Mac版本:10.13.6
Hadoop版本:3.1.1
Mac下面配置hadoop 3.1.1
在MAC上安装MySQL和Workbench
在安装hive之前需要安装hadoop,因为hive本身并没有提供数据存储功能。它的数据是存储在hadoop的HDFS上面的。安装hadoop的方法见上面的链接。
其次,hive的元数据是存储在数据库上面的,一般是MySql。数据库的安装方法见上面的链接。
brew install hive
在命令行中输入上面的代码就可以直接安装hive了。前提是要先安装了homebrew。
接着配置环境变量,在命令行中打开bash_profile文件
vim ~/.bash_profile
在里面添加下面几行:
export HIVE_HOME=/usr/local/Cellar/hive/3.1.1
export PATH=$HIVE_HOME/bin:$PATH
保存退出以后输入source ~/.bash_profile, 更新环境变量。然后在命令行中输入hive,就可以看到下面的信息了。
Logging initialized using configuration in jar:file:/usr/local/Cellar/hive/3.1.1/libexec/lib/hive-common-3.1.1.jar!/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive>
接下来就要配置MySQL作为hive的元数据存储数据库。
在数据库里面新建一个database
mysql> create database metastore;
然后进入/usr/local/Cellar/hive/3.1.1/libexec/conf 目录下,键入vim hive-site.xml, 将下面的代码粘贴进去。
hive.metastore.local
true
javax.jdo.option.ConnectionURL
jdbc:mysql://localhost/metastore
javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
javax.jdo.option.ConnectionUserName
root
javax.jdo.option.ConnectionPassword
18883171984
hive.exec.local.scratchdir
/tmp/hive
hive.downloaded.resources.dir
/tmp/hive
hive.metastore.warehouse.dir
/user/hive/warehouse
hive.server2.logging.operation.log.location
/tmp/hive
可以先在这里运行一下hive,看看粘贴的文件有没有问题。如果没有问题就可以进行下一步了。
在mysql的官网下载mysql-connector,选下面的操作系统。解压以后,再把jar文件复制到/usr/local/Cellar/hive/3.1.1/libexec/lib目录下面。
如果没有下载mysql-connector,就会出现FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient问题。
最后执行schematool -initSchema -dbType mysql,出现下面的结果,就说明执行成功了。
Initialization script completed
schemaTool completed
运行hive,需要注意的是,在运行hive的情况下不能连接外网,否则不能成功运行!!!
输入下面的命令,如果成功了应该就是没有问题了 。
hive> show databases
> ;
OK
default
Time taken: 0.675 seconds, Fetched: 1 row(s)
hive>