您的位置:首页 > 运维架构

Mac下hadoop,hive, hbase,spark单机环境搭建

2017-05-22 23:37 666 查看
最近在用mac笔记本搭建hadoop+hive+spark的测试环境,中间遇到不少问题,所以,记录一下,希望以后不会再犯。也可供参考。

之前在linux虚机下从wget软件包开始搭建过一次环境,mac下则是使用brew来进行快速安装的。不得不说,用brew后方便很多。

一 hadoop安装

大家可以参考https://www.cnblogs.com/davidgu/p/6179191.html这篇文章,使用brew install hadoop后,brew会自动安装hadoop的最新版本,当前时间的版本为:

/usr/local/Cellar/hadoop/2.8.0
配置文件没有什么问题,按照文章中所说进行编辑即可,唯一需要注意的就是自己实际的jdk目录,和hadoop目录,这里注意检查一下。

关于hadoop安装后容易出现的一些问题,可参考文档: http://blog.csdn.net/xiaolang85/article/details/7975618?t=1489924870208

其中有一个问题,按照网上的一些教程配置后,发现8088和50070端口不能正常访问,一般50070端口不能访问的可能性会大一些。有说需要重新格式化hdfs的,也有说要手动添加50070端口到配置文件的,可能解决了部分场景的问题,但我在mac下进行上述方法的尝试之后均没有效果。环境中hdfs和yarn都启动之后,却发现50070端口根本没有开启[使用命令:lsof -i:50070]。后来返回上面的参考文章后,重新修改了

core-site.xml
内容为:

<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:8020</value>
</property>
</configuration>

添加了下面fs.default.name一段的配置,然后使用sbin/stop-all.sh,再sbin/start-all.sh启动后,问题解决。

二 hive安装命令

brew install hive

执行后,brew会自动完成从.tar.gz文件下载,解压缩包的过程。如果没有特别设定过brew的路径配置,那么文件会在目录

/usr/local/Cellar/hive
下。当前时间(2017.05.22)安装的版本是hive2.1.0.

hive安装完成后,需要设置一系列的配置文件和环境变量,配置文件在路径:

/usr/local/Cellar/hive/2.1.0/libexec/conf

这里面已经提供了一些.template模板,拷贝文件并去掉.template后缀即可。环境变量需要设置HIVE_HOME,vim /etc/profile,加入

export HIVE_HOME=/usr/local/Cellar/hive/2.1.0
export $PATH:$HIVE_HOME/bin

两行内容。
其中,比较重要的一个是hive-site.xml,这里涉及到hive元数据(metastore)的处理方式,hive支持三种方式,使用hive内嵌derby,local方式(如本地mysql)以及remote方式(远程mysql)。说明和配置方式可以参考文章:http://www.cnblogs.com/zhengrunjian/p/4546032.html,http://blog.csdn.net/reesun/article/details/8556078,http://f.dataguru.cn/thread-63133-1-1.html。注:【建议重点看第三篇】

方法一,derby

其中最为简洁的一种就是使用内嵌的derby,这是hive的默认启动方式,一般用于单元测试。这种方式最大的缺点是,在同一时间只能有一个进程连接使用数据库,否则会报错。

对应的hive-site.xml配置内容如下:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<configuration>

<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:derby:;databaseName=metastore_db;create=true</value>
</property>

<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>org.apache.derby.jdbc.EmbeddedDriver</value>
</property>

<property>
<name>hive.metastore.local</name>
<value>true</value>
</property>

<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>

</configuration>


其中,目录/user/hive/warehouse 需要root权限进行创建,可以使用sudo mkdir -p /user/hive/warehouse 命令实现。

然后,还需要执行初始化命令:

schematool -dbType derby -initSchema

这个schematool工具在目录:

/usr/local/Cellar/hive/2.1.0/bin
问题1:

但上述命令在执行时可能会报错:

Starting metastore schema initialization to 2.0.0

Initialization script hive-schema-2.0.0.derby.sql
Error: FUNCTION 'NUCLEUS_ASCII' already exists. (state=X0Y68,code=30000)
org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
*** schemaTool failed ***


如果出现这种情况,需要我们检查目录下是否已经有,metastore_db这个目录,如果有,那么就删掉后重新执行初始化命令。我的问题就是这个原因导致的。

执行成功后,我们就可以使用命令  schematool -dbType derby -info
来查看初始化信息了。

这里又遇到一个奇葩问题:

问题2:

NestedThrowablesStackTrace:
Required table missing : "VERSION" in Catalog "" Schema "". DataNucleus requires this table to perform its persistence operations. Either your MetaData is incorrect, or you need to enable "datanucleus.schema.autoCreateTables"
org.datanucleus.store.rdbms.exceptions.MissingTableException: Required table missing : "VERSION" in Catalog "" Schema "". DataNucleus requires this table to perform its persistence operations. Either your MetaData is incorrect, or you need to enable "datanucleus.schema.autoCreateTables"
at org.datanucleus.store.rdbms.table.AbstractTable.exists(AbstractTable.java:606)
at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.performTablesValidation(RDBMSStoreManager.java:3365)

很显然,是没有找到对应的VERSON信息,这是由于没有derby导致。。这里吐槽下网上的大多数教程,hive安装步骤中,只提到说使用内嵌的derby方式,却很少有提及derby安装的,可能有两个原因,一是之前已经安装过,或安装hive时自带(?表示怀疑),二就是,都是抄来抄去的,已经忘了这个基本步骤。

那么继续,要解决这个问题就是再用brew install derby 执行derby安装,删除metastore_db目录后,再重新执行初始化命令,然后,再执行hive命令,成功进入期待已久的命令行模式。

然而,问题并没有结束。。。

在hive命令行模式下,show databases;命令执行没有问题,但执行create database first_hive;的时候报错:

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:Unable to create database path file:/user/hive/warehouse/first_hive.db, failed to create database first_hive)


由于创建语句涉及到写操作,而默认登录的一般都不是root用户,所以自然想到是不是前面创建数据目录的时候,没有设置访问权限的问题,于是进入

/user/hive
,下面的目录都设置 sudo chmod 777 * 后,再次进入hive命令行,执行创建语句成功。

三 hive使用

初学者可以先看下这个系列:http://blog.csdn.net/qq_29622761/article/details/51570137

其他hive常见问题汇总:http://blog.csdn.net/freedomboy319/article/details/44828337

四 Hbase安装

参考文档:http://blog.csdn.net/gaoqiao1988/article/details/52972224

五 Spark安装
参考文档:http://blog.csdn.net/u012373815/article/details/53231580
spark-shell命令行下的一些简单操作,可以参考:http://blog.csdn.net/u012373815/article/details/53231580
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息