将 apache-hive-3.1.2-bin.tar.gz 安装包上传到 node-01 的 /root 目录下并将其解压
[root@node-01 ~]# tar -zxf apache-hive-3.1.2-bin.tar.gz -C apps/
[root@node-01 ~]# rm -rf apache-hive-3.1.2-bin.tar.gz
[root@node-01 apps]# mv apache-hive-3.1.2-bin/ hive-3.1.2
[root@node-01 apps]# vi /etc/profile
export HIVE_HOME=/root/apps/hive-3.1.2
export PATH=$PATH:$HIVE_HOME/bin
[root@node-01 apps]# source /etc/profile
上传 mysql-connector-java-8.0.21.jar 包到 node-01 的 /root 目录下
[root@node ~]# mv /root/mysql-connector-java-8.0.21.jar /root/apps/hive-3.1.2/lib/
[root@node-01 ~]# cd /root/apps/hadoop-3.2.1/etc/hadoop/
[root@node-01 hadoop]# vim core-site.xml
<configuration>
<!--设置 hdfs 命名空间-->
<property>
<name>fs.defaultFS</name>
<value>hdfs://hadoop/</value>
</property>
<!-- zookeeper 集群-->
<property>
<name>ha.zookeeper.quorum</name>
<value>node-01:2181,node-02:2181,node-03:2181</value>
</property>
<!--关闭 HDFS 的权限检查 -->
<property>
<name>dfs.permissions.enabled</name>
<value>false</value>
</property>
<!-- 配置 root 用户可以访问 hdfs -->
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
</property>
<!-- 配置 root 用户所在组可以访问 hdfs -->
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>
</configuration>
[root@node-01 ~]# cd /root/apps/hive-3.1.2/conf
[root@node-01 conf]# mv hive-env.sh.template hive-env.sh
[root@node-01 conf]# vim hive-env.sh
# Set HADOOP_HOME to point to a specific hadoop install directory
HADOOP_HOME=/root/apps/hadoop-3.2.1
# Hive Configuration Directory can be controlled by:
export HIVE_CONF_DIR=/root/apps/hive-3.1.2/conf
[root@node-01 ~]# hadoop fs -mkdir /tmp
[root@node-01 ~]# hadoop fs -mkdir -p /user/hive/warehouse
[root@node-01 ~]# hadoop fs -chmod 777 /tmp
[root@node-01 ~]# hadoop fs -chmod 777 /user/hive/warehouse
[root@node-01 ~]# cd /root/apps/hive-3.1.2/conf
[root@node-01 conf]# vim hive-site.xml
<configuration>
<!-- 关闭版本验证-->
<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
</property>
<!-- Hive 数据库数据存储到 HDFS 路径-->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
<!--关闭本地运行模式-->
<property>
<name>hive.exec.mode.local.auto</name>
<value>false</value>
</property>
<!--Hive元数据不存放本地-->
<property>
<name>hive.metastore.local</name>
<value>false</value>
</property>
<!-- metastore服务器URI -->
<property>
<name>hive.metastore.uris</name>
<value>thrift://192.168.229.21:9083</value>
</property>
<!-- 远程 mysql 数据库本地 url 地址-->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://192.168.2.125:3306/hive_remote?serverTimezone=UTC
</value>
</property>
<!-- 连接 msyql8 驱动-->
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.cj.jdbc.Driver</value>
</property>
<!-- 连接 mysql 用户名-->
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
</property>
<!-- 连接 mysql 密码-->
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
</property>
<!--开启mapreduce任务-->
<property>
<name>hive.compute.query.using.stats</name>
<value>false</value>
</property>
<!-- 显示表的列名 -->
<property>
<name>hive.cli.print.header</name>
<value>true</value>
</property>
<!-- 显示数据库名称 -->
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
</configuration>
[root@node-01 ~]# cd /root/apps/hive-3.1.2
[root@node-01 hive-3.1.2]# mkdir logs
[root@node-01 hive-3.1.2]# cd conf/
[root@node-01 conf]# mv hive-log4j2.properties.template hive-log4j2.properties
[root@node-01 conf]# vim hive-log4j2.properties
#修改24行
property.hive.log.dir = /root/apps/hive-3.1.2/logs
#查看 Hive 的 guava 版本
[root@node-01 ~]# cd /root/apps/hive-3.1.2/lib
[root@node-01 lib]# ll | grep guava
-rw-r--r--. 1 root root 2308517 9月 27 2018 guava-19.0.jar
#查看 Hadoop 的 guava 版本
[root@node-01 ~]# cd /root/apps/hadoop-3.2.1/share/hadoop/common/lib
[root@node-01 lib]# ll | grep guava
-rw-r--r--. 1 1001 1001 2747878 9月 10 2019 guava-27.0-jre.jar
-rw-r--r--. 1 1001 1001 2199 9月 10 2019 listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
#删除 Hive 的低版本 guava
[root@node-01 ~]# cd /root/apps/hive-3.1.2/lib
[root@node-01 lib]# rm -rf guava-19.0.jar
#复制 Hadoop 的高版本 guava
[root@node-01 lib]# cp /root/apps/hadoop-3.2.1/share/hadoop/common/lib/guava-27.0-jre.jar /root/apps/hive-3.1.2/lib/
[root@node-01 ~]# cd /root/apps/
[root@node-01 apps]# scp -r hive-3.1.2/ node-02:$PWD
[root@node-01 apps]# scp -r hive-3.1.2/ node-03:$PWD
[root@node-01 ~]# cd /root/apps/hadoop-3.2.1/etc/hadoop
[root@node-01 hadoop]# scp core-site.xml node-02:$PWD
[root@node-01 hadoop]# scp core-site.xml node-03:$PWD
[root@node-01 apps]# cd /etc
[root@node-01 etc]# scp profile node-02:$PWD
[root@node-01 etc]# scp profile node-03:$PWD
[root@node-02 ~]# source /etc/profile
[root@node-03 ~]# source /etc/profile
[root@node-01 ~]# schematool -dbType mysql -initSchema
Initialization script completed #表示初始化完成
schemaTool completed
如果初始化失败,请检查连接 MySQL 配置的 URL 地址是否正确
Hive 的表数据存储于 HDFS 中,所以需要开启 HDFS 集群,Hive 的查询依赖于 MapReduce 任务,所以需要开启 Yarn 集群
[root@node-01 ~]# dfsCluster.sh start
# shell 批处理脚本如下:
#!/bin/bash
#启动zk集群
for host in node-01 node-02 node-03
do
echo "${host}: zk ${1}ing....."
ssh $host "source /etc/profile;/root/apps/zookeeper-3.4.6/bin/zkServer.sh $1"
done
sleep 2
for host in node-01 node-02 node-03
do
ssh $host "source /etc/profile; /root/apps/zookeeper-3.4.6/bin/zkServer.sh status"
done
#启动hdsf(HA)集群
echo "hdfs cluster ${1}ing....."
${1}-dfs.sh
sleep 2
for host in node-01 node-02
do
echo "${host}:hdfs zkfc ${1}ing....."
ssh $host "/root/apps/hadoop-3.2.1/bin/hdfs --daemon ${1} zkfc"
done
sleep 2
for host in node-02 node-03
do
echo "${host}:datanode cluster ${1}ing....."
ssh $host "/root/apps/hadoop-3.2.1/bin/hdfs --daemon ${1} datanode"
done
sleep 2
#启动 yarn(HA)集群
echo "yarn cluster ${1}ing ....."
${1}-yarn.sh
sleep 2
for host in node-02 node-03
do
echo "${host}:nodemanager cluster ${1}ing....."
ssh $host "/root/apps/hadoop-3.2.1/bin/yarn --daemon ${1} nodemanager"
done
[root@node-01 ~]# jps
10161 NodeManager
8804 QuorumPeerMain
10005 ResourceManager
9592 DFSZKFailoverController
9450 JournalNode
9068 NameNode
9212 DataNode
[root@node-02 ~]# jps
9570 QuorumPeerMain
9795 JournalNode
10261 NodeManager
9868 DFSZKFailoverController
9965 DataNode
10111 ResourceManager
10671 NameNode
[root@node-03 ~]# jps
3632 JournalNode
3718 DataNode
3853 NodeManager
3502 QuorumPeerMain
Hive 元数据存储于 windows 系统下的 mysql 8 中,所以需要启动 mysql 服务,并允许 Hive 远程连接 mysql
[root@node-01 ~]# hive --service metastore 1>/dev/null 2>&1 &
[root@node-01 ~]# jps
10161 NodeManager
8804 QuorumPeerMain
10005 ResourceManager
9592 DFSZKFailoverController
9450 JournalNode
9068 NameNode
9212 DataNode
24030 RunJar # metastore 服务进程
[root@node-01 ~]# hive
Logging initialized using configuration in jar:file:/root/apps/hive-3.1.2/lib/hive-common-3.1.2.jar!/hive-log4j2.properties Async: true
Hive Session ID = 46631073-610a-4242-8d60-3800099daf94
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 (default)> show databases;
手机扫一扫
移动阅读更方便
你可能感兴趣的文章