这里的内容是按照我之前发布的Hadoop单节点集群搭建的文章往下继续操作的。
Hadoop单节点集群搭建
一、系统环境
os : Ubuntu 22.04 LTS 64bit
jdk : 1.8.0
hadoop : 3.3.6
mysql : 5.7.21
hive : 3.1.2
二、安装步骤
1、hive的安装与配置
(1)hive的安装:hive-3.1.2下载地址
下载hive 3.1.2,使用以下命令安装到/usr/local
cd /home/hduser/Downloads
tar -zxvf apache-hive-3.1.2-bin.tar.gz
sudo mv apache-hive-3.1.2-bin /usr/local/hive
cd /usr/local
sudo chown -R hduser hive
(2)配置环境变量
sudo nano ~/.bashrc
添加以下代码:
export HIVE_HOME=/usr/local/hive
export HCAT_HOME=$HIVE_HOME/hcatalog
export HIVE_CONF=$HIVE_HOME/conf
export PATH=$PATH:$HIVE_HOME/bin
应用新的环境变量
source ~/.bashrc
(3) 配置hive-site.xml
cd /usr/local/hive
cp conf/hive-default.xml.template conf/hive-site.xml
cd /usr/local/hive/conf
sudo nano hive-site.xml
将对应的name修改成下面的value:(在nano编译器中使用Ctrl+w搜索)
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?characterEncoding=UTF-8&createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore.To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
<description>Username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
<description>password to use against metastore database</description>
</property>
在hive-site.xml中的
将 ${system:java.io.tmpdir}全部替换为/usr/local/hive/tmp,
将 ${system:user.name}全部替换为 ${user.name}
配置文件3215行有代码错误需要修改,将该行出现红色的三个字母删除,“;”保留;(这里使用Ctrl+/ 搜索)
2、安装并配置MySQL
2.1 安装MySQL
sudo apt-get install mysql-server
sudo apt-get install mysql-client
2.2 重启MySQL
service mysql restart
sudo mysql -u root -p
2.3 设置登录密码(密码为123456,已经填好了,不用自己另外再填)
mysql>use mysql;
mysql>update user set authentication_string='123456' where user = 'root';
mysql>flush privileges;
mysql>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
mysql>quit;
2.4 重新打开MySQL
mysql -u root -p
quit;
2.5 MySQL JDBC驱动程序安装
(1) 官网下载:mysql-connector-j-8.0.31.jar
(2) 将安装的驱动程序文件夹中的JAR文件“mysql-connector-j-8.0.31.jar”复制到Hive安装目录的lib文件夹中
cd /home/hduser/Downloads
tar -zxvf mysql-connector-j-8.0.31.tar.gz
cp mysql-connector-j-8.0.31/mysql-connector-j-8.0.31.jar /usr/local/hive/lib/
2.6 配置mysql允许hive接入:
mysql -u root -p
mysql>CREATE USER 'hive'@'localhost';
mysql>ALTER USER 'hive'@'localhost' IDENTIFIED BY 'hive';
mysql>GRANT ALL PRIVILEGES ON *.* TO 'hive'@'localhost';
mysql>FLUSH PRIVILEGES;
2.7 新建hive数据库
mysql>create database hive;
mysql>quit;
2.8 初始化数据库
schematool -dbType mysql -initSchema
3、启动hive
start-all.sh #先启动Hadoop
hive
4、测试hive
hive>show databases;
hive>show tables;