Hive安装

本文详细指导如何在Linux上上传并解压Hive,移除旧版MySQL后安装MySQL,配置hive-env.sh和hive-site.xml,连接MySQL驱动,设置环境变量,完成元数据初始化,并解决启动时的安全模式问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

1.上传解压hive

2.安装MySQL

3.文件配置

 4.启动验证


         数据仓库工具hive是基于Hadoop集群运行的,在安装hive之前,确保电脑已经启动Hadoop集群。

1.上传解压hive

        对hive软件包进行上传解压,重命名后,输入命令启动hive。

[root@master ~]# cd /export/software/
[root@master software]# rz -be

[root@master software]# tar -zxvf apache-hive-3.1.2-bin.tar.gz -C /export/servers/
[root@master software]# cd /export/servers/
[root@master servers]# ls
apache-hive-3.1.2-bin  hadoop-3.1.3  jdk
[root@master servers]# mv apache-hive-3.1.2-bin hive
[root@master servers]# ls
hadoop-2.6.4  hive  jdk
[root@master servers]# cd hive/

2.安装MySQL

        查询Linux系统中数据库软件安装情况。

[root@master hive]# rpm -qa|grep mariadb*
mariadb-libs-5.5.56-2.el7.x86_64
[root@master hive]# yum remove mariadb*
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased
--> Finished Dependency Resolution
base/7/x86_64                                        | 3.6 kB     00:00     
extras/7/x86_64                                      | 2.9 kB     00:00     
updates/7/x86_64                                     | 2.9 kB     00:00     

Dependencies Resolved

============================================================================
 Package            Arch         Version              Repository       Size
============================================================================
Removing:
 mariadb-libs       x86_64       1:5.5.56-2.el7       @anaconda       4.4 M
Removing for dependencies:
 postfix            x86_64       2:2.10.1-6.el7       @anaconda        12 M

Transaction Summary
============================================================================
Remove  1 Package (+1 Dependent package)

Installed size: 17 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 2:postfix-2.10.1-6.el7.x86_64                            1/2 
  Erasing    : 1:mariadb-libs-5.5.56-2.el7.x86_64                       2/2 
  Verifying  : 1:mariadb-libs-5.5.56-2.el7.x86_64                       1/2 
  Verifying  : 2:postfix-2.10.1-6.el7.x86_64                            2/2 

Removed:
  mariadb-libs.x86_64 1:5.5.56-2.el7                                        

Dependency Removed:
  postfix.x86_64 2:2.10.1-6.el7                                             

Complete!
[root@master hive]#

        将系统中自带的mariadb软件卸载,卸载过程若出现交互,一律填写"y"。

        以下代码实现安装MySQL数据库,并将数据库登录权限更改为:root用户在任何主机上使用密码可登录MySQL。

[root@master hive]# sudo rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Retrieving http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-release-el7-5    ################################# [100%]
[root@master hive]# yum install mysql mysql-server mysql-devel
[root@master hive]# service mysql start
Redirecting to /bin/systemctl start mysql.service
[root@master hive]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.51 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> select user,host,password from user;
+------+-----------+----------+
| user | host      | password |
+------+-----------+----------+
| root | localhost |          |
| root | master    |          |
| root | 127.0.0.1 |          |
| root | ::1       |          |
|      | localhost |          |
|      | master    |          |
+------+-----------+----------+
6 rows in set (0.00 sec)

mysql> update user set host='%' where host='::1';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> delete from user where host='127.0.0.1';
Query OK, 1 row affected (0.00 sec)

mysql> delete from user where host='master';
Query OK, 2 rows affected (0.00 sec)

mysql> delete from user where host='localhost';
Query OK, 2 rows affected (0.00 sec)

mysql> update user set password=password('123456') where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select user,host,password from user;
+------+------+-------------------------------------------+
| user | host | password                                  |
+------+------+-------------------------------------------+
| root | %    | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+------+-------------------------------------------+
1 row in set (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
Bye
[root@master hive]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@master hive]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.51 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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>

        若出现yum 安装不成功情况,可查看主机是否可上网。访问外网不成功,可查看设置静态IP文件是否出错。

3.文件配置

       hive-env.sh

        设置hadoop环境变量,作用是无论系统是否配置hadoop环境变量,在hive执行时可通过hive-env.sh加载hadoop环境变量。将以下内容添加到hive-env.sh文件末尾。

                export HADOOP_HOME=/export/servers/hadoop-3.1.3
                export HIVE_CONF_DIR=/export/servers/hive/conf

[root@master ~]# cd /export/servers/hive
[root@master hive]# cd conf/
[root@master conf]# cp hive-env.sh.template hive-env.sh
[root@master conf]# vi hive-env.sh

        hive-site.xml

         conf目录下没有该文件,利用vi新建该文件,并将以下内容粘贴到hive-site.xml文件中。(注意: <value>jdbc:mysql://master:3306/metastore?createDatabaseIfNotExist=true</value>这行内容作用是:在master主机上的Mysql数据库中新建数据库Metastore保存元数据,若你的主机名不是master,需要将“master”改成你的主机名)

<configuration>
        <!--mysql连接协议以及mysql地址-->
           <property> 
                <name>javax.jdo.option.ConnectionURL</name>
                <value>jdbc:mysql://master:3306/metastore?createDatabaseIfNotExist=true</value>
        </property>
        <!--JDBC连接驱动-->
        <property>
                <name>javax.jdo.option.ConnectionDriverName</name>
                <value>com.mysql.jdbc.Driver</value>
         </property>
        <!--mysql连接用户名-->
        <property>
                <name>javax.jdo.option.ConnectionUserName</name>
                <value>root</value>
        </property>
        <!--mysql连接密码-->
        <property>
                <name>javax.jdo.option.ConnectionPassword</name>
                <value>123456</value>
        </property>
</configuration>

[root@master conf]# vi hive-site.xml

        上传连接Mysql JDBC驱动jar包。

[root@master conf]# cd ../lib/
[root@master lib]# rz -be

 配置hive环境变量

export HIVE_HOME=/export/servers/hive
export PATH=$PATH:$HIVE_HOME/bin

将以上内容写入/etc/profile文件中,保存退出,并 source /etc/profile。

 4.启动验证

      初始化元数据

[root@master hive]#schematool -initSchema -dbType mysql -verbose

       输入对应启动hive命令,成功进入命令行窗口。show databases;若出现default数据库说明安装成功!

[root@master hive]# hive
hive> show databases;
OK
default
Time taken: 0.717 seconds, Fetched: 1 row(s)
hive> 

  启动hive时,若出现以下错误:

       若启动集群后,NamNode处于安全模式,会造成hive启动不成功,需要关闭安全模式。

 图4-1 NameNode处于安全模式

[root@master hive]# hadoop dfsadmin -safemode leave
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值