Hive(八)安裝部署

一年都在冬眠發表於2024-10-14

安裝Hive

  • 把apache-hive-3.1.2-bin.tar.gz上傳到linux的/opt/software目錄下
  • 解壓apache-hive-3.1.2-bin.tar.gz到/opt/module/目錄下面
[user@hadoop102 software]$ tar -zxvf /opt/software/apache-hive-3.1.2-
bin.tar.gz -C /opt/module/
  • 修改apache-hive-3.1.2-bin.tar.gz的名稱為hive
[user@hadoop102 software]$ mv /opt/module/apache-hive-3.1.2-bin/ 
/opt/module/hive
  • 修改/etc/profile.d/my_env.sh,新增環境變數
[user@hadoop102 software]$ sudo vim /etc/profile.d/my_env.sh
  • 新增內容
#HIVE_HOME
export HIVE_HOME=/opt/module/hive
export PATH=$PATH:$HIVE_HOME/bin
  • 解決日誌Jar包衝突
[user@hadoop102 software]$ mv $HIVE_HOME/lib/log4j-slf4j-impl-2.10.0.jar $HIVE_HOME/lib/log4j-slf4j-impl-2.10.0.bak
  • 初始化後設資料庫
[user@hadoop102 hive]$ bin/schematool -dbType derby -initSchema

安裝MySQL

  • 檢查當前系統是否安裝過MySQL
[user@hadoop102 ~]$ rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64 
//如果存在透過如下命令解除安裝
[user@hadoop102 ~]$ sudo rpm -e --nodeps mariadb-libs
  • 將MySQL安裝包複製到/opt/software目錄下,並解壓到/opt/module/
[user@hadoop102 software]$ tar -xf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar -C /opt/module/
  • 在/opt/module/目錄下執行rpm安裝,按照順序依次執行!
[user@hadoop102 module]$ sudo rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm 
warning: mysql-community-common-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.28-1.e################################# [100%]
[user@hadoop102 module]$ sudo rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm 
warning: mysql-community-libs-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.28-1.el7################################# [100%]
[user@hadoop102 module]$ sudo rpm -ivh mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm 
warning: mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-compat-5.7.2################################# [100%]
[user@hadoop102 module]$ sudo rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm 
warning: mysql-community-client-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.28-1.e################################# [100%]
[user@hadoop102 module]$ sudo rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm 
warning: mysql-community-server-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.28-1.e################################# [100%]
  • 刪除/etc/my.cnf檔案中datadir指向的目錄下的所有內容,如果有內容的情況下

檢視datadir的值:

[mysqld]
datadir=/var/lib/mysql

刪除/var/lib/mysql 目錄下的所有內容:

[user@hadoop102 mysql]# cd /var/lib/mysql
[user@hadoop102 mysql]# sudo rm -rf ./* //注意執行命令的位置
  • 初始化資料庫
[user@hadoop102 opt]$ sudo mysqld --initialize --user=mysql
  • 檢視臨時生成的root使用者的密碼,root@localhost:密碼
[user@hadoop102 opt]$ sudo cat /var/log/mysqld.log 
  • 啟動MySQL服務
[user@hadoop102 opt]$ sudo systemctl start mysqld
  • 登入MySQL資料庫
[user@hadoop102 opt]$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  • 修改root使用者的密碼
mysql> set password = password("新密碼");
  • 修改mysql庫下的user表中的root使用者允許任意ip連線
mysql> update mysql.user set host='%' where user='root';
mysql> flush privileges;

複製驅動

將MySQL的JDBC驅動複製到Hive的lib目錄下

[user@hadoop102 software]$ cp /opt/software/mysql-connector-java-5.1.37-bin.jar  $HIVE_HOME/lib

配置Metastore到MySQL

  • 在$HIVE_HOME/conf目錄下新建hive-site.xml檔案
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
 <!-- jdbc 連線的 URL -->
 <property>
 <name>javax.jdo.option.ConnectionURL</name>
 <value>jdbc:mysql://hadoop102:3306/metastore?useSSL=false</value>
</property>
 <!-- jdbc 連線的 Driver-->
 <property>
 <name>javax.jdo.option.ConnectionDriverName</name>
 <value>com.mysql.jdbc.Driver</value>
</property>
<!-- jdbc 連線的 username-->
 <property>
 <name>javax.jdo.option.ConnectionUserName</name>
 <value>root</value>
 </property>
 <!-- jdbc 連線的 password -->
 <property>
 <name>javax.jdo.option.ConnectionPassword</name>
 <value>000000</value>
</property>
 <!-- Hive 後設資料儲存版本的驗證 -->
 <property>
 <name>hive.metastore.schema.verification</name>
 <value>false</value>
</property>
 <!--後設資料儲存授權-->
 <property>
 <name>hive.metastore.event.db.notification.api.auth</name>
 <value>false</value>
 </property>
 <!-- Hive 預設在 HDFS 的工作目錄 -->
 <property>
<name>hive.metastore.warehouse.dir</name>
 <value>/user/hive/warehouse</value>
 </property>
</configuration>
  • 登陸MySQL
[user@hadoop102 software]$ mysql -uroot -p
  • 新建Hive後設資料庫
mysql> create database metastore;
mysql> quit;
  • 初始化Hive後設資料庫
[user@hadoop102 software]$ schematool -initSchema -dbType mysql -verbose

使用後設資料服務的方式訪問Hive

  • 在hive-site.xml檔案中新增如下配置資訊
 <!-- 指定儲存後設資料要連線的地址 -->
 <property>
 <name>hive.metastore.uris</name>
 <value>thrift://hadoop102:9083</value>
 </property>
  • 啟動metastore
[user@hadoop202 hive]$ hive --service metastore

注意: 啟動後視窗不能再操作,需開啟一個新的shell視窗做別的操作

  • 啟動hive
[user@hadoop202 hive]$ bin/hive

使用JDBC方式訪問Hive

  • 在hive-site.xml檔案中新增如下配置資訊
 <!-- 指定 hiveserver2 連線的 host -->
 <property>
  <name>hive.server2.thrift.bind.host</name>
  <value>hadoop102</value>
 </property>
 <!-- 指定 hiveserver2 連線的埠號 -->
 <property>
  <name>hive.server2.thrift.port</name>
  <value>10000</value>
 </property>
  • 啟動hiveserver2
[user@hadoop102 hive]$ bin/hive --service hiveserver2
  • 啟動beeline客戶端(需要多等待一會)
[user@hadoop102 hive]$ bin/beeline -u jdbc:hive2://hadoop102:10000 -n user