1. 程式人生 > 其它 >Hive 元件安裝配置

Hive 元件安裝配置

下載和解壓安裝檔案 基礎環境和安裝準備

  • Hive元件的部署規劃和軟體包路徑如下:
    (1)當前環境中已安裝 Hadoop全分佈系統
    (2)本地安裝 MySQL資料庫(賬號 root,密碼 Password123$),軟體包在/opt/software/mysql-5.7.18路徑下
    (3)MySQL埠號(3306)
    (4)MySQL的 JDBC驅動包/opt/software/mysql-connector-java-5.1.47.jar,在此基礎上更新 Hive元資料儲存
    (5)Hive軟體包/opt/software/apache-hive-2.0.0-bin.tar.gz
  • 解壓安裝檔案
    (1)使用 root使用者,將 Hive安裝包
/opt/software/apache-hive-2.0.0-bin.tar.gz路解壓到/usr/local/src路徑下
[root@master ~]# tar -zxvf /opt/software/apache-hive-2.0.0-bin.tar.gz -C /usr/local/src

(2)將解壓後的 apache-hive-2.0.0-bin資料夾更名為 hive

[root@master ~]# mv /usr/local/src/apache-hive-2.0.0-bin usr/local/src/hive

(3)修改 hive目錄歸屬使用者和使用者組為 hadoop

[root@master ~]# chown -R hadoop:hadoop /usr/local/src/hive

設定 Hive 環境

  • 解除安裝 MariaDB 資料庫
    Hive元資料儲存在 MySQL資料庫中,因此在部署 Hive元件前需要首先在 Linux系統下安裝 MySQL資料庫,並進行 MySQL字符集、安全初始化、遠端訪問許可權等相關配置。
    需要使用 root使用者登入,執行如下操作步驟:
    (1)關閉 Linux系統防火牆,並將防火牆設定為系統開機並不自動啟動。
    關閉防火牆服務
[root@master ~]# systemctl stop firewalld

(2)設定防火牆服務開機不啟動

[root@master ~]# systemctl disable firewalld

(3)解除安裝 Linux系統自帶的 MariaDB。
首先檢視 Linux系統中 MariaDB的安裝情況
查詢已安裝的 mariadb軟體包

[root@ master ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.52-2.el7.x86_64

以上結果顯示 Linux系統中已經按照了 mariadb-libs-5.5.52-2.el7.x86_64軟體包,
需要將其解除安裝。
(4)解除安裝 MariaDB軟體包

[root@master ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64

安裝 MySQL 資料庫

按如下順序依次按照 MySQL資料庫的 mysql common、mysql libs、mysql client
軟體包。
(1)MySQL軟體包路徑

[root@master ~]# cd /opt/software/mysql-5.7.18/
[root@master ~]# rpm -ivh mysql-community-common-5.7.18-1.el7.x86_64.rpm
[root@master ~]# rpm -ivh mysql-community-libs-5.7.18-1.el7.x86_64.rpm
[root@master ~]# rpm -ivh mysql-community-client-5.7.18-1.el7.x86_64.rpm

(2)安裝 mysql server軟體包

[root@master ~]# rpm -ivh mysql-community-server-5.7.18-1.el7.x86_64.rpm

(3)修改 MySQL資料庫配置,在/etc/my.cnf檔案中新增如表 6-1所示的 MySQL資料庫配置項

將以下配置資訊新增到/etc/my.cnf檔案 symbolic-links=0配置資訊的下方
default-storage-engine=innodb
innodb_file_per_table
collation-server=utf8_general_ci
init-connect='SET NAMES utf8'
character-set-server=utf8

(4)啟動 MySQL資料庫
[root@master ~]# systemctl start mysqld
(5)查詢 MySQL資料庫狀態。mysqld程序狀態為 active (running),則表示 MySQL資料庫正常執行

如果 mysqld 程序狀態為 failed,則表示 MySQL 資料庫啟動異常。此時需要排查/etc/my.cnf檔案
[root@master ~]# systemctl status mysqld

(6)查詢 MySQL資料庫預設密碼

MySQL 資料庫安裝後的預設密碼儲存在/var/log/mysqld.log 檔案中,在該檔案中以password關鍵字搜尋預設密碼
[root@master ~]# cat /var/log/mysqld.log | grep password
2020-05-07T02:34:03.336724Z 1 [Note] A temporary password is generated for root@localhost: MPg5lhk4?>Ui 
# 默 認 密 碼 為:MPg5lhk4?>Ui

MySQL資料庫是安裝後隨機生成的,所以每次安裝後生成的預設密碼不相同
(7)MySQL資料庫初始化
執行mysql_secure_installation命令初始化 MySQL資料庫,初始化過程中需要設定
資料庫 root 使用者登入密碼,密碼需符合安全規則,包括大小寫字元、數字和特殊符號,
可設定密碼為 Password123$

在進行 MySQL資料庫初始化過程中會出現以下互動確認資訊:
1)Change the password for root ? ((Press y|Y for Yes, any other key for No)
表示是否更改 root使用者密碼
2)Do you wish to continue with the password provided?(Press y|Y for Yes,any other key for No)
表示是否使用設定的密碼繼續,在鍵盤輸入 y和回車。
3)Remove anonymous users? (Press y|Y for Yes, any other key for No)
表示是否刪除匿名使用者
4)Disallow root login remotely? (Press y|Y for Yes, any other key for No)
表示是否拒絕 root 使用者遠端登入,在鍵盤輸入 n 和回車
5)Remove test database and access to it? (Press y|Y for Yes, any other key for No)
表示是否刪除測試資料庫
6)Reload privilege tables now? (Press y|Y for Yes, any other key for No)
表示是否重新載入授權表

#mysql_secure_installation命令執行過程如下:
[root@master ~]# mysql_secure_installation

Securing the MySQL server deployment.
Enter password for user root: # 輸入/var/log/mysqld.log 檔案中查詢
到的預設 root使用者登入密碼
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
 Estimated strength of the password: 100
 Change the password for root ? ((Press y|Y for Yes, any other
key for No) : y
New password: # 輸入新密碼 Password123$
Re-enter new password: # 再次輸入新密碼 Password123$
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y # 輸入 y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y # 輸入 y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n # 輸入 n
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y # 輸入 y
 - Dropping test database...
Success.
 - Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y # 輸入 y
Success.
All done!

(8)新增 root使用者從本地和遠端訪問 MySQL資料庫表單的授權

[root@master ~]# mysql -uroot -p

Enter password: # 輸入新設定的密碼 Password123$
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 5.7.18 MySQL Community Server (GPL)
 Copyright (c) 2000, 2017, 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.

#進入之後
mysql> grant all privileges on *.* to root@'localhost'
identified by 'Password123$'; # 新增 root使用者本地訪問授權
 Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> grant all privileges on *.* to root@'%' identified by 'Password123$'; # 新增 root使用者遠端訪問授權
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges; # 重新整理授權 Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from mysql.user where user='root'; # 查詢 root使用者授權情況
+------+-----------+
| user | host 	   |
+------+-----------+
| root | % 		   |
| root | localhost |
+------+-----------+
2 rows in set (0.00 sec)
mysql> exit; # 退出 MySQL資料庫
Bye

配置 Hive 元件

(1)設定 Hive環境變數並使其生效。
在檔案末尾追加以下配置內容

[root@master ~]# vi /etc/profile
# set hive environment
export HIVE_HOME=/usr/local/src/hive
export PATH=$PATH:$HIVE_HOME/bin

使環境變數配置生效
[root@master ~]# source /etc/profile
(2)修改 Hive元件配置檔案
切換到 hadoop使用者執行以下對 Hive元件的配置操作
將/usr/local/src/hive/conf 資料夾下 hive-default.xml.template 檔案,更名為hive-site.xml

[root@master ~]# su - hadoop
[hadoop@master ~]$ cp /usr/local/src/hive/conf/hive-default.xml.template
/usr/local/src/hive/conf/hive-site.xml

(3)通過 vi 編輯器修改 hive-site.xml 檔案實現 Hive 連線 MySQL 資料庫,並設定Hive臨時檔案儲存路徑

[hadoop@master ~]$ vi /usr/local/src/hive/conf/hive-site.xml
#設定 MySQL資料庫連線。
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://master:3306/hive?createDatabaseIfNotExist=true&amp;us
eSSL=false</value>
<description>JDBC connect string for a JDBC metastore</description>
#配置 MySQL資料庫 root的密碼。
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>Password123$</value>
<description>password to use against s database</description>
</property>
#驗證元資料儲存版本一致性。若預設 false,則不用修改。
<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
<description>
Enforce metastore schema version consistency.
True: Verify that version information stored in is compatible with one from
Hive jars. Also disable automatic
False: Warn if the version information stored in metastore doesn't match
with one from in Hive jars.
</description>
</property>
#配置資料庫驅動
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
#配置資料庫使用者名稱 javax.jdo.option.ConnectionUserName為 root。
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
<description>Username to use against metastore database</description>
</property>
#將 以 下 位 置 的 ${system:java.io.tmpdir}/${system:user.name} 替 換 為“/usr/local/src/hive/tmp”目錄及其子目錄
#需要替換以下 4處配置內容:
<name>hive.querylog.location</name>
<value>/usr/local/src/hive/tmp</value>
<description>Location of Hive run time structured log
file</description>

<name>hive.exec.local.scratchdir</name>
<value>/usr/local/src/hive/tmp</value>

<name>hive.downloaded.resources.dir</name>
<value>/usr/local/src/hive/tmp/resources</value>

<name>hive.server2.logging.operation.log.location</name>
<value>/usr/local/src/hive/tmp/operation_logs</value>

(4)在 Hive安裝目錄中建立臨時資料夾 tmp

[hadoop@master ~]$ mkdir /usr/local/src/hive/tmp
至此,Hive元件安裝和配置完成

初始化 hive 元資料

#將 MySQL資料庫驅動(/opt/software/mysql-connector-java-5.1.46.jar)拷貝到Hive安裝目錄的 lib下
[hadoop@master ~]$ cp /opt/software/mysql-connector-java-5.1.46.jar
/usr/local/src/hive/lib/
#重新啟動 hadooop即可
[hadoop@master lib]$ stop-all.sh
[hadoop@master lib]$ start-all.sh 3)初始化資料庫
[hadoop@master ~]$schematool -initSchema -dbType mysql
#啟動 hive
[hadoop@master ~]$ hive