Hive的部署

MySQL安装

安装

首先上传mysql数据库的rpm压缩包到主机/opt/software

image-20230327163403445

//解压缩包到当前目录中
[root@master-tz software]# unzip mysql-5.7.18.zip
//进入到rpm软件目录中,首先检查mariadb,如果有就要卸载

image-20230327163858423

//安装数据库
[root@master-tz mysql-5.7.18]# rpm -ivh mysql-community-common-5.7.18-1.el7.x86_64.rpm
[root@master-tz mysql-5.7.18]# rpm -ivh mysql-community-libs-5.7.18-1.el7.x86_64.rpm
[root@master-tz mysql-5.7.18]# rpm -ivh mysql-community-client-5.7.18-1.el7.x86_64.rpm
//安装下面的rpm需要首先安装perl软件
[root@master-tz mysql-5.7.18]# yum install -y net-tools perl
[root@master-tz mysql-5.7.18]# rpm -ivh mysql-community-server-5.7.18-1.el7.x86_64.rpm

配置

修改配置文件/etc/my.cnf

vim /etc/my.cnf
//最后添加五行
default-storage-engine=innodb
innodb_file_per_table
collation-server=utf8_general_ci
init-connect='SET NAMES utf8'
character-set-server=utf8
//最后保存退出

image-20230327164618444

启动

[root@master-tz mysql-5.7.18]# systemctl start mysqld
[root@master-tz mysql-5.7.18]# systemctl status mysqld

image-20230327164839744

查看MySQL初始密码

[root@master-tz mysql-5.7.18]# cat /var/log/mysqld.log | grep password
2023-03-27T08:52:43.074230Z 1 [Note] A temporary password is generated for root@localhost: KbVXiHlul3:> //查看初始密码,下方需要填写
[root@master-tz mysql-5.7.18]# mysql_secure_installation //重新设定密码,并把密码设置为Password123$
//注:允许远程连接设定为n,表示允许远程连接,其它设定为y

除了以下是n其他都是y

image-20230327165755870

登录数据库客户端

[root@master-tz mysql-5.7.18]# mysql -uroot -pPassword123$

image-20230327165944986

新建hive用户与元数据

mysql>create database hive_db;
mysql>create user hive identified by 'Password123$';
mysql>grant all privileges on *.* to hive@'%' identified by 'Password123$' with grant
option ;
mysql>grant all privileges on *.* to 'root'@'%'identified by 'Password123$' with grant
option;
mysql>flush privileges;

Hive安装

安装

首先将hive的压缩包上传到虚拟机,并解压,重命名hive,设置hive权限

[root@master-tz ~]# tar -zxf apache-hive-2.0.0-bin.tar.gz -C /usr/local/src/
[root@master-tz ~]# cd /usr/local/src/
[root@master-tz src]# mv apache-hive-2.0.0-bin/ hive
[root@master-tz src]# chown -R hadoop:hadoop hive/

修改环境变量

[root@master-tz src]# vim /etc/profile
# set Hive environment
export HIVE_HOME=/usr/local/src/hive # Hive安装目录
export PATH=$HIVE_HOME/bin:$PATH # 添加将Hive的bin目录
export HIVE_CONF_DIR=$HIVE_HOME/conf #Hive的环境变量
[root@master-tz src]# source /etc/profile

修改配置文件

hive-site.xml文件

首先切换到hadoop用户

[hadoop@master-tz conf]$ cd /usr/local/src/hive/conf
[hadoop@master-tz conf]$ vim hive-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!--元数据库地址-->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://master-tz:3306/hive_db?createDatabaseIfNotExist=true</value>
</property>
<!--mysql用户名-->
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
</property>
<!--mysql中hive用户密码-->
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>Password123$</value>
</property>
<!--mysql驱动-->
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>hive.downloaded.resources.dir</name>
<value>/usr/local/src/hive/tmp</value>
</property>
<property>
<name>hive.exec.local.scratchdir</name>
<value>/usr/local/src/hive/tmp/${hive.session.id}_resources</value>
</property>
<property>
<name>hive.querylog.location</name>
<value>/usr/local/src/hive/tmp</value>
</property>
<property>
<name>hive.server2.logging.operation.log.location</name>
<value>/usr/local/src/hive/tmp/operation_logs</value>
</property>
<property>
<name>hive.server2.webui.host</name>
<value>master-tz</value>
</property>
<property>
<name>hive.server2.webui.port</name>
<value>10002</value>
</property>
</configuration>

hive-env.sh

[hadoop@master-tz conf]$ cp hive-env.sh.template hive-env.sh
[hadoop@master-tz conf]$ vim hive-env.sh
//增加如下配置项
# Set JAVA
export JAVA_HOME=/usr/local/src/java
# Set HADOOP_HOME to point to a specific hadoop install directory
export HADOOP_HOME=/usr/local/src/hadoop
# Hive Configuration Directory can be controlled by:
export HIVE_CONF_DIR=/usr/local/src/hive/conf
# Folder containing extra ibraries required for hive compilation/execution can be
controlled by:
export HIVE_AUX_JARS_PATH=/usr/local/src/hive/lib

MySQL的驱动jar包上传至虚拟机,然后将该jar包复制到hive安装路径下的lib文件夹中

[root@master-tz software]# cp mysql-connector-java-5.1.46.jar /usr/local/src/hive/lib/

确保hadoop集群正常,然后初始化hive元数据库

[hadoop@master-tz conf]$ schematool -initSchema -dbType mysql

image-20230327174225761

进入hive shell界面

[hadoop@master-tz ~]$ hive
hive>

如果出现以下情况

image-20230327174414446

则需要去hive-site.xml配置文件修改为

<value>jdbc:mysql://master-tz:3306/hive_db?createDatabaseIfNotExist=true&useSSL=false</value>

image-20230327174701459

最后修改:2023 年 03 月 27 日
如果觉得我的文章对你有用,请随意赞赏