最近开始学习hive,在安装的时候遇到一些问题,发出来供大家参考一下。
在安装过程中保证Hadoop集群的搭建和集群已开启。
此处说明hive结合MySQL搭建。
首先安装mysql。Ubuntu20.04.3安装的mysql是MySQL8.0。
sudo apt-get update
sudo apt-get install mysql-server
安装完之后进行初始化,这样好修改密码,待会配置xml文件会用到。
sudo mysql_secure_installation
#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (选择N ,不会进行密码的强校验)
#2
Please set the password for root here...
New password: (输入密码)
Re-enter new password: (重复输入)
#3
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (选择N,不删除匿名用户)
#4
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N (选择N,允许root远程连接)
#5
By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (选择N,不删除test数据库)
#6
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (选择Y,修改权限立即生效)
检查服务状态
systemctl status mysql.service
接着,配置远程访问。(这一步能配还是配一下吧,说不定MySQL连不上就是因为这个。)
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf #找到 bind-address 修改值为 0.0.0.0(如果需要远程访问)
sudo /etc/init.d/mysql restart #重启mysql
然后登录mysql:sudo mysql -uroot -p (输入之前初始化那会设置的密码)
#切换数据库
mysql>use mysql;
#查询用户表命令:
mysql>select User,authentication_string,Host from user;
#查看状态
select host,user,plugin from user;
#设置权限与密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码'; #使用mysql_native_password修改加密规则
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '密码' PASSWORD EXPIRE NEVER; #更新一下用户的密码
mysql> UPDATE user SET host = '%' WHERE user = 'root'; #允许远程访问
(其中root@localhost,localhost就是本地访问,配置成 % 就是所有主机都可连接;)
#刷新cache中配置 刷新权限
mysql>flush privileges;
mysql>quit;
(到这一步,mysql算是装完了)
先别退出,在mysql里创建数据库hive
create database hive;
然后给予权限
grant all privileges on hive.* to root@'%' ;
刷新:flush privileges;
退出数据库,安装hive。把下载好的hive安装包复制到hdfs主节点(一定是主节点),解压压缩包(以apache-hive-2.3.5为例)
sudo tar -xvf apache-hive-2.3.5-bin.tar -C /opt
给包建立软链接,方便后续操作
sudo ln -s apache-hive-2.3.5-bin hive
编辑环境变量
vi ~/.bashrc
配置:export HIVE_HOME=/opt/hive
export PATH=$HIVE_HOME/bin:$JAVA_HOME/bin:$PATH
保存并生效 source ~/.bashrc
在/opt/hive/conf目录下,创建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://localhost:3306/hive?createDatabaseIfNotExist=true&useSSL=false&serverTimezone=UTC</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.cj.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name> <value>你的密码</value>
</property>
</configuration>
注意1:
这个地方文字编辑有误,在配置过程中hive?之后紧接着create……不然会报错。
注意2:
新版本8.0版本的驱动为com.mysql.cj.jdbc.Driver
旧版本5.x版本的驱动为com.mysql.jdbc.Driver
上传jar包。此处用的是mysql-connector-java-8.0.15.jar 直接去maven仓库下载
sudo cp mysql-connector-java-8.0.15.jar /opt/hive/lib/
在 /opt/hive/lib/目录下初始化元数据库
schematool -dbType mysql -initSchema
出现schemaTool completed 就算初始化成功了。