1、解压
从software目录下解压至module目录。
[root@slave4 software]# lsapache-hive-3.1.2-bin.tar.gz hadoop-3.2.1.tar.gz nacos-server-1.1.4.tar.gz spark-3.0.0-bin-hadoop3.2.tgz[root@slave4 software]# tar -xzvf apache-hive-3.1.2-bin.tar.gz -C ../module/
-C 参数表示解压到指定目录。
2、环境变量
因为hive只配置单节点,所以给当前节点配置hive环境变量即可。
# set hive environmentexport HIVE_HOME=/opt/module/apache-hive-3.1.2-binexport HIVE_CONF_DIR=/opt/module/apache-hive-3.1.2-bin/confexport PATH=$PATH:$HIVE_HOME/bin
记得source一下生效。
3、配置
3.1 MySQL中创建数据库
新建数据库,名称为
hive_3(字符集:utf8;排序规则:utf8_general_ci)3.2 HDFS中创建目录
root用户终端执行以下命令创建目录并赋予
rwxrwxrwx权限。[root@slave4 conf]# hdfs dfs -mkdir -p /user/hive/tmp[root@slave4 conf]# hdfs dfs -mkdir -p /user/hive/warehouse[root@slave4 conf]# hdfs dfs -chmod 777 /user/hive/tmp[root@slave4 conf]# hdfs dfs -chmod 777 /user/hive/warehouse
检查

3.3 修改配置文件
1、在apache-hive-3.1.2-bin/conf目录下进行以下操作。
[root@slave4 conf]# touch hive-site.xml[root@slave4 conf]# cp hive-log4j2.properties.template hive-log4j2.properties[root@slave4 conf]# cp beeline-log4j2.properties.template beeline-log4j2.properties[root@slave4 conf]# cp hive-env.sh.template hive-env.sh
2、在/opt/module/apache-hive-3.1.2-bin目录下新建logs文件夹,用来存放运行日志。
3、修改配置文件
hive-log4j2.properties
....# 指定为第2步中的logs路径property.hive.log.dir = /opt/module/apache-hive-3.1.2-bin/logs....
hive-env.sh
# Set HADOOP_HOME to point to a specific hadoop install directoryHADOOP_HOME=/opt/module/hadoop-3.2.1# Hive Configuration Directory can be controlled by:export HIVE_CONF_DIR=/opt/module/apache-hive-3.1.2-bin/conf# Folder containing extra libraries required for hive compilation/execution can be controlled by:export HIVE_AUX_JARS_PATH=/opt/module/apache-hive-3.1.2-bin/lib
hive-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?><?xml-stylesheet type="text/xsl" href="configuration.xsl"?><configuration><property><name>hive.exec.scratchdir</name><value>/user/hive/tmp</value></property><property><name>hive.metastore.warehouse.dir</name><value>/user/hive/warehouse</value></property><property><name>hive.metastore.uris</name><value>thrift://填入当前节点的hostname:9083</value></property><property><name>javax.jdo.option.ConnectionDriverName</name><value>com.mysql.jdbc.Driver</value></property><property><name>javax.jdo.option.ConnectionURL</name><value>jdbc:mysql://填入安装MySQL节点的hostname:填入MySQL端口/hive_3?createDatabaseIfNotExist=true&useSSL=false</value></property><property><name>javax.jdo.option.ConnectionUserName</name><value>填入MySQL用户</value></property><property><name>javax.jdo.option.ConnectionPassword</name><value>填入MySQL密码</value></property><property><name>hive.server2.thrift.bind.host</name><value>填入当前节点的hostname</value></property><property><name>hive.server2.thrift.port</name><value>10000</value></property><property><name>hive.metastore.event.db.notification.api.auth</name><value>false</value></property><property><name>hive.server2.active.passive.ha.enable</name><value>true</value></property></configuration>
3.4 补充jar
- 添加MySQL驱动
将升级包中的MySQL驱动拷贝到/opt/module/apache-hive-3.1.2-bin/lib目录中。(不需要修改jar名称)
- 升级Guava
lib中自带Guava版本为guava-19.0.jar,需要升级。
将升级包中的guava-27.0-jre.jar拷贝到/opt/module/apache-hive-3.1.2-bin/lib目录中。同时删除/opt/module/apache-hive-3.1.2-bin/lib目录下的guava-19.0.jar包。(不需要修改jar名称)
4、启动
1、启动Metastore
进入/opt/module/apache-hive-3.1.2-bin/bin目录,执行以下命令
schematool -dbType mysql -initSchema -verbose
2、启动metastore和hiveserver2
进入/opt/module/apache-hive-3.1.2-bin/bin目录,执行以下命令启动metastore和hiveserver2。
[root@slave4 bin]# nohup ./hive --service metastore --hiveconf hive.log.file=metastore.log &>> metastore.log &[root@slave4 bin]# nohup ./hive --service hiveserver2 --hiveconf hive.log.file=hiveserver2.log &>> hiveserver2.log &
3、检查
执行jps -m查看本机JVM中是否有(名称为RunJar)metastore和(名称为RunJar)hiveserver2的Java进程。
5、附录
无
