Hive 组件安装配置
阅读原文时间:2023年07月08日阅读:1
  • 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
  • 卸载 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 common、mysql libs、mysql client软件包

(1)MySQL软件包路径

yum -y install unzip
unzip mysql-5.7.18/
[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  #输入
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

(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;useSSL=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组件安装和配置完成!

#将 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  #初始化数据库
[hadoop@master ~]$ schematool -initSchema -dbType mysql
看到 schemaTool completed 即为成功!

#启动 hive
[hadoop@master ~]$ hive
进入hive即为成功!