Hive的安装部署
注意:hive是一个数据仓库的构建工具,只需要在一台机器上安装即可,不需要在多台服务器上进行安装。
1.提前安装好mysql和hadoop 详见:https://www.cnblogs.com/brianzhu/p/8575243.html
2.下载hive的安装包 http://archive.cloudera.com/cdh5/cdh/5/hive-1.1.0-cdh5.14.2.tar.gz
- 选择要安装的目录 /test/soft
- 上传安装包到在指定的目录下
- 解压安装包到指定的目录
cd/test/soft/
tar -zxf hive-1.1.0-cdh5.14.2.tar.gz -C /test/install/
6.修改配置文件
- 进入到Hive的安装目录下的conf文件夹中
- cd /test/install/hive-1.1.0-cdh5.14.2/conf/
- mv hive-env.sh.template hive-env.sh
- vim hive-env.sh
#配置HADOOP_HOME路径
export HADOOP_HOME=/test/install/hadoop-2.6.0-cdh5.14.2/
#配置HIVE_CONF_DIR路径
export HIVE_CONF_DIR=/test/install/hive-1.1.0-cdh5.14.2/conf
- vim hive-site.xml
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://node03:3306/hive?createDatabaseIfNotExist=true&characterEncoding=latin1&useSSL=false</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>
</property>
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
<property>
<name>hive.cli.print.header</name>
<value>true</value>
</property>
<property>
<name>hive.server2.thrift.bind.host</name>
<value>node03</value>
</property>
</configuration>
- 修改hive的日志配置文件路径,便于我们排查hive出现的错误问题
node03执行以下命令,定义hive的日志文件存放路径
mkdir -p /test/install/hive-1.1.0-cdh5.14.2/logs/
cd /test/install/hive-1.1.0-cdh5.14.2/conf/
mv hive-log4j.properties.template hive-log4j.properties
vim hive-log4j.properties
#更改以下内容,设置我们的日志文件存放的路径
hive.log.dir=/test/install/hive-1.1.0-cdh5.14.2/logs/
-
需要将mysql的驱动包上传到hive的lib目录下
- 例如 mysql-connector-java-5.1.38.jar
Hive的交互方式
- 首先启动mysql和Hadoop的集群
1.Hive交互shell (此种方式已过时)
cd /test/install/hive-1.1.0-cdh5.14.2
bin/hive
会显示以下信息 ,其中有句Hive CLI is deprecated and migration to Beeline is recommended.表示已过时,不推荐这种方式
76566393967b8405a384faf1d4b4c20.png
- Hive的JDBC连接
- 启动HiveServer2服务
- 前台启动
cd /test/install/hive-1.1.0-cdh5.14.2 bin/hive --service hiveserver2
- 后台启动
cd /test/install/hive-1.1.0-cdh5.14.2 nohup bin/hive --service hiveserver2 & beeline客户端连接hiveserver2 重新开启一个会话窗口,然后使用beeline连接hive cd /test/install/hive-1.1.0-cdh5.14.2 bin/beeline beeline> !connect jdbc:hive2://node03:10000
- 前台启动
- 启动HiveServer2服务
3.Hive命令
- Hive -e sql 语句
- 使用-e 参数来直接执行hql语句
cd /test/install/hive-1.1.0-cdh5.14.2/
bin/hive -e "show databases"
- Hive -f sql文件
-
使用-f参数来执行sql文件
- node03执行以下命令准备hive执行脚本
cd /test/install/ vim hive.sql 文件内容如下 create database if not exists myhive; 通过以下命令来执行我们的hive脚本 cd /test/install/hive-1.1.0-cdh5.14.2/ bin/hive -f /kkb/install/hive.sql
-