前提:已安装配置好了Hadoop环境,因为hive的底层是Hadoop
1 Mysql安装
搜索Centos7自带的mariadb
rpm -qa|grep mariadb
卸载mariadb
rpm -e mariadb-libs-5.5.64-1.el7.x86_64 --nodeps
再搜索一次看看是否还存在
rpm -qa|grep mariadb
安装mysql
创建安装目录
mkdir /export/software/mysql
上传mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar 到上述文件夹下 解压(压缩包已附在文章开头)
tar xvf mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
执行安装
yum -y install libaio
安装mysql-server的两个依赖安装包:
yum install -y net-tools
yum install -y perl
rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm mysql-community-libs-5.7.29-1.el7.x86_64.rpm mysql-community-client-5.7.29-1.el7.x86_64.rpm mysql-community-server-5.7.29-1.el7.x86_64.rpm
mysql初始化设置
#初始化
mysqld --initialize
#更改所属组
chown mysql:mysql /var/lib/mysql -R
#启动mysql
systemctl start mysqld.service
#查看生成的临时root密码
cat /var/log/mysqld.log | grep password
修改root密码 授权远程访问 设置开机自启动
mysql -u root -p
更新root密码 设置为hadoop
alter user user() identified by "hadoop";
授权
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'hadoop' WITH GRANT OPTION;
FLUSH PRIVILEGES;
设置为开机自启动服务
systemctl enable mysqld;
查看是否已经设置自启动成功
systemctl list-unit-files | grep mysqld
退出
exit
其他命令清单一览
#mysql的启动和关闭 状态查看
systemctl start mysqld
systemctl stop mysqld
systemctl status mysqld
2 Hive的安装
上传安装包apache-hive-3.1.2-bin.tar.gz到目录/export/server解压
cd /export/server
tar zxvf apache-hive-3.1.2-bin.tar.gz
解决Hive与Hadoop之间guava版本差异
cd /export/server/apache-hive-3.1.2-bin/
rm -rf lib/guava-19.0.jar
cp /export/server/hadoop-3.3.0/share/hadoop/common/lib/guava-27.0-jre.jar ./lib/
修改环境变量
vi /etc/profile
加入以下内容
export HIVE_HOME=/export/server/apache-hive-3.1.2-bin
export PATH=$PATH:$HIVE_HOME/bin
修改配置文件
- hive-env.sh
cd /export/server/apache-hive-3.1.2-bin/conf
mv hive-env.sh.template hive-env.sh
vi hive-env.sh
在文件最后加上
export HADOOP_HOME=/export/server/hadoop-3.3.0
export HIVE_CONF_DIR=/export/server/apache-hive-3.1.2-bin/conf
export HIVE_AUX_JARS_PATH=/export/server/apache-hive-3.1.2-bin/lib
- hive-site.xml
vi hive-site.xm
<configuration>
<!-- 存储元数据mysql相关配置 -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://node1:3306/hive3?createDatabaseIfNotExist=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hadoop</value>
</property>
<!-- H2S运行绑定host -->
<property>
<name>hive.server2.thrift.bind.host</name>
<value>node1</value>
</property>
<!-- 远程模式部署metastore metastore地址 -->
<property>
<name>hive.metastore.uris</name>
<value>thrift://node1:9083</value>
</property>
<!-- 关闭元数据存储授权 -->
<property>
<name>hive.metastore.event.db.notification.api.auth</name>
<value>false</value>
</property>
</configuration>
node1为安装hive虚拟机的主机名
上传mysql jdbc驱动mysql-connector-java-5.1.32.jar到hive安装包lib下
初始化元数据
cd /export/server/apache-hive-3.1.2-bin/
bin/schematool -initSchema -dbType mysql -verbos
初始化成功会在mysql中创建74张表
在hdfs创建hive存储目录(如存在则不用操作)
hadoop fs -mkdir /tmp
hadoop fs -mkdir -p /user/hive/warehouse
hadoop fs -chmod g+w /tmp
hadoop fs -chmod g+w /user/hive/warehouse
3 启动hive
启动metastore服务
如果使用第一代客户端hive只启动metastore服务即可
#前台启动 关闭ctrl+c
/export/server/apache-hive-3.1.2-bin/bin/hive --service metastore
#前台启动开启debug日志
/export/server/apache-hive-3.1.2-bin/bin/hive --service metastore --hiveconf hive.root.logger=DEBUG,console
#后台启动 进程挂起 关闭使用jps+ kill -9
nohup /export/server/apache-hive-3.1.2-bin/bin/hive --service metastore &
启动hiveserver2服务
想要使用最新版客户端beeline客户端还需要启动hiveserver2服务
nohup /export/server/apache-hive-3.1.2-bin/bin/hive --service hiveserver2 &
这里为了看到远程连接的效果,在node3虚拟机上启动客户端连接node1的hive
拷贝node1上的hive安装包到beeline客户端机器上(node3)
scp -r /export/server/apache-hive-3.1.2-bin/ node3:/export/server/
报错:
Error: Could not open client transport with JDBC Uri: jdbc:hive2://node1:10000: Failed to open new session: java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): User: root is not allowed to impersonate root (state=08S01,code=0)
修改
在hadoop的配置文件core-site.xml中添加如下属性:
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>
连接访问
启动客户端
/export/server/apache-hive-3.1.2-bin/bin/beeline
连接hive(node1修改为自己的安装hive的虚拟机的主机名或ip)
! connect jdbc:hive2://node1:10000
连接成功!