hive2.1.1部署记录
参考了网上很多的文档,终于部署成功,记录下来方便大家
本文衔接《hadoop2.7.3部署记录》http://www.jianshu.com/p/07d6d93c0009
上文有过的部署将不再赘述。
hive部署
1.下载hive安装包apache-hive-2.1.1-bin.tar.gz
[root@master src]# wget http://apache.mirror.gtcomm.net/hive/hive-2.1.1/apache-hive-2.1.1-bin.tar.gz
2.解压并重命名为hive-2.1.1
[root@master src]# tar -zxvf apache-hive-2.1.1-bin.tar.gz -C /opt
[root@master opt]# mv apache-hive-2.1.1-bin/ hive-2.1.1
3.修改环境变量并使配置生效
[root@master opt]# vi /etc/profile
export HIVE_HOME=/opt/hive-2.1.1
export PATH=$PATH:$HIVE_HOME/bin
[root@master opt]# source /etc/profile
4.设置hive配置文件
[root@master opt]# cd hive-2.1.1/
[root@master hive-2.1.1]# cd conf/
[root@master conf]# cp hive-log4j2.properties.template hive-log4j2.properties
[root@master conf]# vi hive-log4j2.properties.template
property.hive.log.dir = /opt/hive-2.1.1/logs/
5.启动hive
[root@master hive-2.1.1]# schematool -dbType derby -initSchema
[root@master hive-2.1.1]# hive
此时Hive安装成功
默认情况下,Hive的元数据保存在了内嵌的derby数据库里,但一般情况下生产环境使用MySQL来存放Hive元数据。
6.安装MySQL(需要给root用户远程登录的权限,SQL语句为grant all on . to root@'%' identified by 'passwd';)
下载MySQL驱动
[root@master opt]# wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.42.tar.gz
MySQL安装可参照http://www.jianshu.com/p/4699bcb04633(仅需要参考MYSQL部分即可)
[root@master opt]# tar zxvf mysql-connector-java-5.1.42.tar.gz
[root@master opt]# mv mysql-connector-java-5.1.42/mysql-connector-java-5.1.42-bin.jar hive-2.1.1/lib/
7.修改Hive配置文件
[root@master opt]# cd hive-2.1.1/conf/
[root@master conf]# cp hive-default.xml.template hive-site.xml
[root@master conf]# vi hive-site.xml
将hive-site.xml文件中的全部${system:java.io.tmpdir}替换为hive的临时目录,例如我替换为/opt/hive/tmp,该目录如果不存在则要自己手工创建,并且赋予读写权限。
将hive-site.xml文件中的全部${system:user.name}都替换为root
修改数据库相关配置,搜索javax.jdo.option.ConnectionURL
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://10.22.4.31:3306/hive?createDatabaseIfNotExist=true</value>
修改MYSQL用户名,搜索javax.jdo.option.ConnectionUserName
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>```
修改MYSQL密码,搜索javax.jdo.option.ConnectionPassword
<name>javax.jdo.option.ConnectionPassword</name>
<value>passwd</value>```
搜索hive.metastore.schema.verification,将对应的value修改为false:
<name>hive.metastore.schema.verification</name>
<value>false</value>```
[root@master hive-2.1.1]# cp /opt/hive-2.1.1/conf/hive-env.sh.template /opt/hive-2.1.1/conf/hive-env.sh
[root@master hive-2.1.1]# vi /opt/hive-2.1.1/conf/hive-env.sh
export HADOOP_HOME=/opt/hadoop-2.7.3
export HIVE_CONF_DIR=/opt/hive-2.1.1/conf
export HIVE_AUX_JARS_PATH=/opt/hive-2.1.1/lib
初始化数据库,执行成功后,mysql内会增加hive库和诸多表。
[root@master bin]# schematool -dbType mysql -initSchema
hive> show functions;
OK
Time taken: 0.664 seconds, Fetched: 237 row(s)
hive> desc function sum;
OK
sum(x) - Returns the sum of a set of numbers
Time taken: 0.005 seconds, Fetched: 1 row(s)
hive> use db_hive_edu;
OK
Time taken: 0.011 seconds
hive> create table student(id int,name string) row format delimited fields terminated by '\t';
OK
Time taken: 0.184 seconds
hive>
开启另一个终端
[root@master conf]# vim /opt/hive/student.txt
001 zhangsan
002 lisi
003 wangwu
004 zhaoliu
005 chengqi
回到之前的终端
hive> load data local inpath '/opt/hive/student.txt' into table db_hive_edu.student;
Loading data to table db_hive_edu.student
OK
hive> select * from student;
OK
1 zhangsan
2 lisi
3 wangwu
4 zhaoliu
5 chengqi
Time taken: 0.671 seconds, Fetched: 5 row(s)
######浏览器访问http://10.22.4.31:50070/explorer.html#/user/hive/warehouse/db_hive_edu.db/student
![hive1.png](https://img.haomeiwen.com/i5314324/afd115c9e574b146.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![hive2.png](https://img.haomeiwen.com/i5314324/e8b6fc6555223267.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)