Hive(八)安装部署

安装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
posted @   一年都在冬眠  阅读(24)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示