-
Hive 官网地址
-
Hive 官网地址
-
下载地址
-
github 地址
ll /opt/software/
总用量 143360 -rw-rw-r--. 1 owenxuan owenxuan 146799982 12月 22 11:16 apache-hive-3.1.2-bin.tar.gz解压 Hive 到/opt/module 目录下
cd /opt/software/ tar -zxvf apache-hive-3.1.2-bin.tar.gz -C ../module/将Hive 更名
cd ../module/ mv apache-hive-3.1.2-src/ hive配置 Hive 环境变量 新建/etc/profile.d/my_env.sh 文件
sudo vim /etc/profile.d/my_env.sh
添加如下内容
#HIVE_HOME export HIVE_HOME=/opt/module/hive export PATH=$PATH:$HIVE_HOME/bin
保存后退出
source 一下/etc/profile 文件,让新的环境变量 PATH 生效
source /etc/profile测试 Hive是否安装成功
hive
如果能看到以下结果,则代表 Hive 安装成功。
hive>解决日志 Jar 包冲突
rm $HIVE_HOME/lib/log4j-slf4j-impl-2.10.0.jar初始化元数据库
bin/schematool -dbType derby -initSchema启动并使用 Hive 启动 Hive
bin/hive使用 Hive
hive> show databases; hive> show tables; hive> create table test(id int); hive> insert into test values(1); hive> select * from test;新建一个终端,监控日志文件
tail -f /tmp/owenxuan/hive.logMySQL 安装 检查当前系统是否安装过 MySQL
rpm -qa|grep mariadb //如果存在通过如下命令卸载 sudo rpm -e --nodeps mariadb-libs将 MySQL 安装包拷贝到 /opt/software 目录下
MySQL 下载地址
使用FinalShell 将 MySQL 导入到 opt 目录下面的 software 文件夹下面 在 Linux 系统下的 opt 目录中查看软件包是否导入成功ll /opt/software
总用量 734364 -rw-rw-r--. 1 owenxuan owenxuan 605187279 12月 24 10:51 mysql-8.0.27-1.el8.x86_64.rpm-bundle.tar解压 MySQL 安装包
tar -xf mysql-8.0.27-1.el8.x86_64.rpm-bundle.tar
-rw-rw-r--. 1 owenxuan owenxuan 797798400 9月 29 15:51 mysql-8.0.27-1.el8.x86_64.rpm-bundle.tar -rw-r--r--. 1 owenxuan owenxuan 14692316 9月 29 15:33 mysql-community-client-8.0.27-1.el8.x86_64.rpm -rw-r--r--. 1 owenxuan owenxuan 35730444 9月 29 15:33 mysql-community-client-debuginfo-8.0.27-1.el8.x86_64.rpm -rw-r--r--. 1 owenxuan owenxuan 2524808 9月 29 15:34 mysql-community-client-plugins-8.0.27-1.el8.x86_64.rpm -rw-r--r--. 1 owenxuan owenxuan 3056028 9月 29 15:34 mysql-community-client-plugins-debuginfo-8.0.27-1.el8.x86_64.rpm -rw-r--r--. 1 owenxuan owenxuan 645452 9月 29 15:34 mysql-community-common-8.0.27-1.el8.x86_64.rpm -rw-r--r--. 1 owenxuan owenxuan 3829756 9月 29 15:34 mysql-community-debuginfo-8.0.27-1.el8.x86_64.rpm -rw-r--r--. 1 owenxuan owenxuan 22083196 9月 29 15:34 mysql-community-debugsource-8.0.27-1.el8.x86_64.rpm -rw-r--r--. 1 owenxuan owenxuan 2276504 9月 29 15:34 mysql-community-devel-8.0.27-1.el8.x86_64.rpm -rw-r--r--. 1 owenxuan owenxuan 1565372 9月 29 15:34 mysql-community-libs-8.0.27-1.el8.x86_64.rpm -rw-r--r--. 1 owenxuan owenxuan 3094780 9月 29 15:34 mysql-community-libs-debuginfo-8.0.27-1.el8.x86_64.rpm -rw-r--r--. 1 owenxuan owenxuan 55964292 9月 29 15:36 mysql-community-server-8.0.27-1.el8.x86_64.rpm -rw-r--r--. 1 owenxuan owenxuan 22725496 9月 29 15:36 mysql-community-server-debug-8.0.27-1.el8.x86_64.rpm -rw-r--r--. 1 owenxuan owenxuan 101981976 9月 29 15:37 mysql-community-server-debug-debuginfo-8.0.27-1.el8.x86_64.rpm -rw-r--r--. 1 owenxuan owenxuan 261643100 9月 29 15:37 mysql-community-server-debuginfo-8.0.27-1.el8.x86_64.rpm -rw-r--r--. 1 owenxuan owenxuan 241719788 9月 29 15:38 mysql-community-test-8.0.27-1.el8.x86_64.rpm -rw-r--r--. 1 owenxuan owenxuan 24246504 9月 29 15:39 mysql-community-test-debuginfo-8.0.27-1.el8.x86_64.rpm在安装目录下执行 rpm 安装 安装缺少环境
yum install -y libaio在安装目录下执行 rpm 安装
sudo rpm -ivh mysql-community-common-8.0.27-1.el8.x86_64.rpm sudo rpm -ivh mysql-community-libs-8.0.27-1.el8.x86_64.rpm sudo rpm -ivh mysql-community-libs-compat-8.0.27-1.el8.x86_64.rpm sudo rpm -ivh mysql-community-client-8.0.27-1.el8.x86_64.rpm sudo rpm -ivh mysql-community-server-8.0.27-1.el8.x86_64.rpm初始化数据库
sudo mysqld --initialize --user=mysql查看临时生成的 root 用户的密码
sudo cat /var/log/mysqld.log启动 MySQL 服务
sudo systemctl start mysqld登录 MySQL 数据库
mysql -uroot -p
Enter password: --输入临时生成的密码必须先修改 root 用户的密码,否则执行其他的操作会报错
mysql> set password = password("新密码");
修改 mysql 库下的 user 表中的 root 用户允许任意 ip 连接
mysql> update mysql.user set host='%' where user='root'; mysql> flush privileges;Hive 元数据配置到 MySQL 下载JDBC驱动
JDBC驱动下载地址
拷贝JDBC驱动cp /opt/software/mysql-connector-java-8.0.27.jar $HIVE_HOME/lib配置 metastore 到 MySQL 在$HIVE_HOME/conf 目录下新建 hive-site.xml 文件
vim $HIVE_HOME/conf/hive-site.xml
添加如下内容
登陆 MySQLjavax.jdo.option.ConnectionURL jdbc:mysql://10.10.10.31:3306/metastore?useSSL=false javax.jdo.option.ConnectionDriverName com.mysql.jdbc.Driver javax.jdo.option.ConnectionUserName root javax.jdo.option.ConnectionPassword OUwen501 hive.metastore.schema.verification false hive.metastore.event.db.notification.api.auth false hive.metastore.warehouse.dir /user/hive/warehouse hive.metastore.uris thrift://10.10.10.31:9083 hive.server2.thrift.bind.host 10.10.10.31 hive.server2.thrift.port 10000
mysql -uroot -pOUwen501新建 Hive 元数据库
mysql> create database metastore; mysql> quit;初始化 Hive 元数据库
schematool -initSchema -dbType mysql -verbose再次启动 Hive 启动 Hive
bin/hive使用 Hive
hive> show databases; hive> show tables; hive> create table test(id int); hive> insert into test values(1); hive> select * from test;使用元数据服务的方式访问 Hive 启动 metastore
hive --service metastore
2021-12-24 16:58:08: Starting Hive metastore Server
- 注意: 启动后窗口不能再操作,需打开一个新的 shell 窗口做别的操作
bin/hive使用 JDBC 方式访问 Hive 使用 JDBC 方式访问 Hive
bin/hive --service hiveserver2启动 beeline 客户端(需要多等待一会)
bin/beeline -u jdbc:hive2://10.10.10.31:10000 -n owenxuan
成功启动信息
Connecting to jdbc:hive2://10.10.10.31:10000 Connected to: Apache Hive (version 3.1.2) Driver: Hive JDBC (version 3.1.2) Transaction isolation: TRANSACTION_REPEATABLE_READ Beeline version 3.1.2 by Apache Hive 0: jdbc:hive2://10.10.10.31:10000>编写 hive 服务启动脚本
vim ~/bin/hiveservices.sh
输入如下内容
#!/bin/bash
HIVE_LOG_DIR=$HIVE_HOME/logs
if [ ! -d $HIVE_LOG_DIR ]
then
mkdir -p $HIVE_LOG_DIR
fi
#检查进程是否运行正常,参数 1 为进程名,参数 2 为进程端口
function check_process()
{
pid=$(ps -ef 2>/dev/null | grep -v grep | grep -i $1 | awk '{print
$2}')
ppid=$(netstat -nltp 2>/dev/null | grep $2 | awk '{print $7}' | cut -
d '/' -f 1)
echo $pid
[[ "$pid" =~ "$ppid" ]] && [ "$ppid" ] && return 0 || return 1
}
function hive_start()
{
metapid=$(check_process Hivemetastore 9083)
cmd="nohup hive --service metastore >$HIVE_LOG_DIR/metastore.log 2>&1 &"
[ -z "$metapid" ] && eval $cmd || echo "metastroe 服务已启动"
server2pid=$(check_process HiveServer2 10000)
cmd="nohup hiveserver2 >$HIVE_LOG_DIR/hiveServer2.log 2>&1 &"
[ -z "$server2pid" ] && eval $cmd || echo "HiveServer2 服务已启动"
}
function hive_stop()
{
metapid=$(check_process Hivemetastore 9083)
[ "$metapid" ] && kill $metapid || echo "metastore 服务未启动"
server2pid=$(check_process HiveServer2 10000)
[ "$server2pid" ] && kill $server2pid || echo "HiveServer2 服务未启动"
}
case $1 in
"start")
hive_start
;;
"stop")
hive_stop
;;
"restart")
hive_stop
sleep 2
hive_start
;;
"status")
check_process Hivemetastore 9083 >/dev/null && echo "metastore 服务运行正常" || echo "metastore 服务运行异常"
check_process HiveServer2 10000 >/dev/null && echo "HiveServer2 服务运行正常" || echo "HiveServer2 服务运行异"
;;
*)
echo Invalid Args!
echo 'Usage: '$(basename $0)' start|stop|restart|status'
;;
esa
保存后退出,然后赋予脚本执行权限
chmod +x hiveservices.sh测试脚本
hiveservices.sh start



