准备:打开三台虚拟机,并且连接好xshell

1.上传apache-hive-2.3.3-bin.tar.gz压缩包文件到/opt/software目录下,

xshell 连接hive vbs xshell连接hive数据库_xshell 连接hive vbs

可以使用rz命令,选择路径上传,也可以直接把文件从本地拖拽致xshell内,也可以使用xftp来传输。

xshell 连接hive vbs xshell连接hive数据库_大数据_02

  1. 解压apache-hive-2.3.3-bin.tar.gz 到指定文件夹目录下

xshell 连接hive vbs xshell连接hive数据库_大数据_03

xshell 连接hive vbs xshell连接hive数据库_hive_04

修改文件夹名,此步骤可忽略:

xshell 连接hive vbs xshell连接hive数据库_hive_05

3.在/opt/software/hive-2.3.3/lib目录下上传mysql连接包

xshell 连接hive vbs xshell连接hive数据库_mysql_06

xshell 连接hive vbs xshell连接hive数据库_xshell 连接hive vbs_07

4.在Hive的conf目录下下添加以下配置信息:

xshell 连接hive vbs xshell连接hive数据库_hadoop_08

vi 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/myhive?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&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>
         <!--客户端显示当前查询表的头信息 -->
          <property>
           <name>hive.cli.print.header</name>
           <value>true</value>
         </property>
         <!--客户端显示当前数据库名称信息 -->
         <property>
           <name>hive.cli.print.current.db</name>
           <value>true</value>
         </property>
    <property>
         <!--关闭数据库的版本检查-->
               <name>hive.metastore.schema.verification</name>
               <value>false</value>
         </property>
</configuration>

xshell 连接hive vbs xshell连接hive数据库_大数据_09

 

5.查看/etc/profile下Hadoop的安装路径

xshell 连接hive vbs xshell连接hive数据库_xshell 连接hive vbs_10


复制路径

xshell 连接hive vbs xshell连接hive数据库_hadoop_11

6.改名,vi hive-log4j2.properties并且在对应的位置修改,

property.hive.log.dir = /opt/software/hive-2.3.3/logs

xshell 连接hive vbs xshell连接hive数据库_hadoop_12


xshell 连接hive vbs xshell连接hive数据库_hadoop_13

xshell 连接hive vbs xshell连接hive数据库_hive_14

7.vi hive-env.sh

在对应的位置添加。

HADOOP_HOME=/opt/software/hadoop-2.9.2

export HIVE_CONF_DIR=/opt/software/hive-2.3.3-bin/conf

xshell 连接hive vbs xshell连接hive数据库_mysql_15

8.改名(可忽略),vi hive-log4j2.properties并且在对应位置修改自己的hive路径。

mv hive-log4j2.properties.template hive-log4j2.properties

在对应的位置修改:

property.hive.log.dir = /opt/software/hive-2.3.3/logs

xshell 连接hive vbs xshell连接hive数据库_hive_16

xshell 连接hive vbs xshell连接hive数据库_大数据_17

9.给mysql赋予权限:

mysql -uroot -p123456

xshell 连接hive vbs xshell连接hive数据库_mysql_18

10.赋予权限

>grant all privileges on *.* to root@"%" identified by "123456" with grant option;

xshell 连接hive vbs xshell连接hive数据库_大数据_19

若此处报错:

先查看mysql初始密码策略。
SHOW VARIABLES LIKE 'validate_password%';
设置密码的验证强度等级。
set global validate_password_policy=LOW;
设置密码的长度。
set global validate_password_length=6;
然后再进行赋予权限。
>grant all privileges on *.* to root@"localhost" identified by "123456" with grant option;

xshell 连接hive vbs xshell连接hive数据库_hive_20

xshell 连接hive vbs xshell连接hive数据库_xshell 连接hive vbs_21

11.配置HIVE_HOME到系统环境变量中:vi /etc/profile,添加Hadoop和hive的路径。

xshell 连接hive vbs xshell连接hive数据库_hadoop_22

xshell 连接hive vbs xshell连接hive数据库_mysql_23

12.配置完后需要重新加载配置文件:

重新加载:source /etc/profile。

13.初始化Hive,执行以下命令

schematool -dbType mysql -initSchema

xshell 连接hive vbs xshell连接hive数据库_大数据_24

14.执行hive命令进行连接,如图所示即成功,show databases;可查看。

xshell 连接hive vbs xshell连接hive数据库_mysql_25

xshell 连接hive vbs xshell连接hive数据库_mysql_26

15.执行hiveserver2,启动服务端,Hive的bin目录下有hiveserver2,

启动bin/ hiveserver2。

xshell 连接hive vbs xshell连接hive数据库_hive_27

16.新建node01,使用如下命令进行客户端连接:

beeline -u 'jdbc:hive2://192.168.67.110:10000' -n root

xshell 连接hive vbs xshell连接hive数据库_mysql_28

  1. 在浏览器中访问node01地址,如下图所示则集群正常。

xshell 连接hive vbs xshell连接hive数据库_mysql_29

20.客户端连接成功后,若如图所示即成功安装配置好了hive。

 

xshell 连接hive vbs xshell连接hive数据库_hive_30

 

常见问题1

在给mysql赋予权限时报错

xshell 连接hive vbs xshell连接hive数据库_hadoop_31

解决方法:修改mysql的初始密码策略
1.将密码的验证强度设为低级

set global validate_password_policy=LOW;

xshell 连接hive vbs xshell连接hive数据库_mysql_32

2.将密码长度设置为6位

set global validate_password_length=6;

xshell 连接hive vbs xshell连接hive数据库_xshell 连接hive vbs_33

常见问题2

Hive连接过程中失败

xshell 连接hive vbs xshell连接hive数据库_xshell 连接hive vbs_34

使用jps查看hadoop集群是否启动

xshell 连接hive vbs xshell连接hive数据库_mysql_35

重新启动集群start-dfs.sh start-yarn.sh后即可解决

xshell 连接hive vbs xshell连接hive数据库_hadoop_36

常见问题3

若启动异常,则需要在hadoop路径下配置文件core-site.xml中加入:

xshell 连接hive vbs xshell连接hive数据库_大数据_37

<property>
        <name>hadoop.proxyuser.root.hosts</name>
        <value>*</value>
</property>
<property>
        <name>hadoop.proxyuser.root.groups</name>
        <value>*</value>
</property>

xshell 连接hive vbs xshell连接hive数据库_hive_38

并且重新初始化集群即可。

xshell 连接hive vbs xshell连接hive数据库_hadoop_39

若出现上述问题,则需要先删除hive数据库,然后使用命令:

schematool -dbType mysql -initSchema进行初始化。

xshell 连接hive vbs xshell连接hive数据库_mysql_40

xshell 连接hive vbs xshell连接hive数据库_xshell 连接hive vbs_41

xshell 连接hive vbs xshell连接hive数据库_hadoop_42

关闭集群,并且格式化hdfs。

xshell 连接hive vbs xshell连接hive数据库_hive_43

xshell 连接hive vbs xshell连接hive数据库_大数据_44

xshell 连接hive vbs xshell连接hive数据库_hadoop_45

输入Y

xshell 连接hive vbs xshell连接hive数据库_hive_46

在hadoop路径下删除hdfs,再新建(mkdir hsfs目录),再在hdfs目录下新建data,name,tmp目录。

xshell 连接hive vbs xshell连接hive数据库_xshell 连接hive vbs_47

node02,node03同理

xshell 连接hive vbs xshell连接hive数据库_hive_48

xshell 连接hive vbs xshell连接hive数据库_xshell 连接hive vbs_49

重新格式化

xshell 连接hive vbs xshell连接hive数据库_大数据_50