Hive搭建前提:hadoop已安装配置成功,安装步骤可参考
Hadoop3.1.3完全分布式平台搭建_hadoop-3.1.3-CSDN博客
- Hive搭建涉及的安装包: https://pan.quark.cn/s/af141a7d3ff1
一、上传并解压hive
1、通过MobaXterm工具将hive3.1.3的安装包上传至master主机的/opt/software目次下,并解压至/opt/install目次下,解压命令为:
tar -zxvf apache-hive-3.1.3-bin.tar.gz -C /opt/install
2、将解压后的hive-3.1.3目次重命名为hive,命令为:
mv apache-hive-3.1.3-bin/ hive
二、配置hive的环境变量
1、打开/etc/profile文件
vi /etc/profile
2、在末端添加hive的环境变量,命令为:
export HIVE_HOME=/opt/install/hive
export PATH=$PATHHIVE_HOME/bin
配置完成后按下esc键,输入:wq保存并退出文件
3、见效配置的环境
source /etc/profile
4、验证hive是否配置成功
hive --version
三、安装mysql
1、查抄mysql是否已安装
rpm -qa | grep mysql
若查到内容,说明mysql已安装,此时需要先卸载掉
(卸载命令:rpm -e xxx xxx为文件全名)
2、使用wget下载官方mysql包,命令为:
wget http://repo.mysql.com/mysql80-community-release-el7.rpm
若报错提示wget:command not found,需要先安装wget,命令为:
yum install –y wget
3、安装mysql包,命令为:yum install -y mysql80-community-release-el7.rpm
4、安装mysql服务,命令为:yum install –y mysql-community-server
可能的报错:xxx的公钥尚未安装…
办理办法: rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
5、启动服务并查看服务状态
systemctl start mysqld
systemctl status mysqld
6、获取mysql默认暗码
grep "password" /var/log/mysqld.log
7、登录mysql并修改暗码
mysql –uroot -p
先修改一次暗码,然后才气调整为简朴的暗码规则
set password for root@localhost='Root777!';
set global validate_password.policy = 0;
set global validate_password.length = 4;
将暗码修改为123456
set password for root@localhost=’123456’;
退出当前账户,重新用123456这个暗码登录
登录成功,说明暗码修改成功
8、授权长途用户连接mysql
use mysql;
update user set host = '%' where user = 'root';
flush privileges;
授权完毕后输入exit; 退出mysql
9、将mysql的jar包上传至/opt/install/hive/lib目次下
四、hive的核心文件配置
进入hive的conf目次: cd /opt/install/hive/conf
1、配置hive-env.sh
(1)conf目次中只有hive-env.sh.template,需要拷贝重新生成一个hive-env.sh
命令为: cp hive-env.sh.template hive-env.sh
(2)打开hive-env.sh,在末端添加如下两行内容
export HADOOP_HOME=/opt/install/hadoop
export HIVE_CONF_DIR=/opt/install/hive/conf
添加完成后,按下esc键,输入:wq保存并退出文件
2、配置hive-site.xml
(1)conf目次中没有hive-site.xml文件,输入 vi hive-site.xml创建并编辑文件
按下字母i,进入编辑模式,输入如下内容:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<configuration>
<!--设置Hive通过JDBC模式连接MySQL数据库metastore内容,用来保存hive元数据-->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://master:3306/hive?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT</value>
</property>
<!--设置Hive连接MySQL的驱动名称-->
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.cj.jdbc.Driver</value>
</property>
<!--Hive连接存储metastore内容的数据库的用户名root和暗码123456-->
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>
</property>
<!--执行Hive数据堆栈操纵的数据存储目次-->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>hdfs://master:9820/hive/warehouse</value>
</property>
<property>
<name>hive.exec.mode.local.auto</name>
<value>true</value>
</property>
<property>
<name>hive.server2.thrift.port</name>
<value>10000</value>
</property>
<property>
<name>hive.server2.thrift.bind.host</name>
<value>master</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://master:9083</value>
</property>
<property>
<name>hive.metastore.event.db.notification.api.auth</name>
<value>false</value>
</property>
<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
</property>
<property>
<name>hive.server2.active.passive.ha.enable</name>
<value>true</value>
</property>
<property>
<name>hive.cli.print.header</name>
<value>true</value>
</property>
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
<property>
<name>hive.resultset.use.unique.column.names</name>
<value>false</value>
</property>
</configuration>
编辑完成后,按下esc键,输入:wq,保存并退出文件
五、初始化元数据库
1、mysql配置好,hadoop集群已启动的情况下,进入hive的bin目次
cd /opt/install/hive/bin
2、执行以下指令进行初始化: schematool -dbType mysql -initSchema
(1)此时会报以下错误:
(2)报错缘故原由:hadoop和hive的guava.jar版本不同等,两个jar位置分别位于如下目次:
hadoop: /opt/install/hadoop/share/hadoop/common/lib/guava-27.0-jre.jar
hive: /opt/install/hive/lib/guava-19.0.jar
(3)办理办法:删除低版本的jar,将高版本的复制到低版本目次下。
rm -rf /opt/install/hive/lib/guava-19.0.jar
cp /opt/install/hadoop/share/hadoop/common/lib/guava-27.0-jre.jar /opt/install/hive/lib/
(4)然后再次运行schematool -dbType mysql -initSchema,即可成功初始化元数据
六、启动hive
1、在hive的bin目次下启动元数据服务
hive --service metastore
2、输入hive进入交互模式
常用HQL操纵,比方:
列出全部数据库:show databases;
创建数据库:create database xxx;
删除数据库:drop database xxx;
使用某数据库:use xxx;
退出hive交互模式:输入exit; 即可
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |