Hive安装
0 准备工作
- 搭建Hadoop完全分布式集群:Hadoop完全分布式集群搭建
- 下载安装MySQL:CentOS7 MySQL安装
1 下载Hive
Hive官网:https://hive.apache.org/general/downloads/
找到适配自己Hadoop版本的Hive
找到后进入下载站下载
Hive下载:https://dlcdn.apache.org/hive/
2 安装Hive
将下载好的包使用xftp或其他工具上传
进入上传的hive包目录,安装Hive
tar -zxvf apache-hive-3.1.3-bin.tar.gz
为了方便,可以对Hive目录重命名
mv apache-hive-3.1.3-bin hive
配置Hive环境变量
vim /etc/profile
# Hive环境变量
export HIVE_HOME=/opt/hive
export PATH=$PATH:$HIVE_HOME/bin
重新加载profile文件
source /etc/profile
查看Hive版本,看是否配置成功
hive --version
3 配置Hive
进入Hive配置文件目录
cd $HIVE_HOME/conf/
拷贝并重命名Hive配置文件
cp hive-default.xml.template hive-site.xml
修改配置文件,除了前两行全删掉
vim hive-site.xml
将配置项黏贴进去
<configuration>
<!-- 使用JDBC连接指定的数据库存储Hive元数据 -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<!-- 不加上useSSL=false可能会出发大量警告 -->
<value>jdbc:mysql://hadoop1:3306/hive?useSSL=false</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>123456</value>
</property>
</configuration>
4 配置Hive元数据存储库。
登录MySQL
mysql -u root -p
创建Hive元数据存储库
create database hive character set "utf8";
给与root用户远程登录权限,设置自己的远程登录密码
set global validate_password_policy=0;
set global validate_password_length=1;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;
退出
exit;
拷贝驱动到$HIVE_HOME/lib目录下
没有mysql驱动的可去mysql官网下载:https://downloads.mysql.com/archives/c-j/
cp mysql-connector-java-5.1.49.jar $HIVE_HOME/lib/
5 初始化Hive
cd $HIVE_HOME/bin
./schematool -dbType mysql -initSchema
这时报错:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hive/lib/log4j-slf4j-impl-2.17.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop/share/hadoop/common/lib/slf4j-reload4j-1.7.35.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V
at org.apache.hadoop.conf.Configuration.set(Configuration.java:1357)
at org.apache.hadoop.conf.Configuration.set(Configuration.java:1338)
at org.apache.hadoop.mapred.JobConf.setJar(JobConf.java:536)
at org.apache.hadoop.mapred.JobConf.setJarByClass(JobConf.java:554)
at org.apache.hadoop.mapred.JobConf.<init>(JobConf.java:448)
at org.apache.hadoop.hive.conf.HiveConf.initialize(HiveConf.java:5144)
at org.apache.hadoop.hive.conf.HiveConf.<init>(HiveConf.java:5107)
at org.apache.hive.beeline.HiveSchemaTool.<init>(HiveSchemaTool.java:96)
at org.apache.hive.beeline.HiveSchemaTool.main(HiveSchemaTool.java:1473)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.hadoop.util.RunJar.run(RunJar.java:323)
at org.apache.hadoop.util.RunJar.main(RunJar.java:236)
解决:https://www.cnblogs.com/syq816/p/12632028.html
再次初始化,成功
./schematool -dbType mysql -initSchema
6 启动Hive。
hive
接下来就可以使用了,尝试一个创建数据库。
create database abc;
若要远程连接Hive,请看:远程连接Hive