前题

hive跑起来了,再继续下面步骤~

文件修改
1.配置hive-site.xml
切换到hive的conf目录下,打开hive-site.xml文件

cd /Users/zhaohaichao/programming/hive-1.1.0-cdh5.15.1/conf
vi hive-site.xml

添加以下配置

<property>
        <name>hive.server2.authentication</name>
        <value>NONE</value>
</property>
<property>
        <name>hive.server2.thrift.bind.host</name>
        <value>hadoop1</value>
</property>
<property>
         <name>hive.server2.thrift.port</name>
         <value>10000</value>
         <description>TCP port number to listen on, default 10000</description>
 </property>

<property>
        <name>hive.server2.thrift.http.port</name>
        <value>10001</value>
</property>

<property>
        <name>hive.server2.thrift.client.user</name>
        <value>root</value>
        <description>Username to use against thrift client</description>
</property>
<property>
        <name>hive.server2.thrift.client.password</name>
        <value>root</value>
        <description>Password to use against thrift client</description>
</property>

hive文件配置说明
hive.server2.authentication 配置hive用户认证,设置为NONE则跳过认证

hive.server2.thrift.bind.host 配置thrift服务绑定的ip,需要在hadoop1启动hive服务,thrift服务才能与hadoop1建立连接,thrift主要用来实现hiveserver2的瘦客户端

hive.server2.thrift.port 配置thrift服务绑定的端口,主要用来建立与thrift服务连接

hive.server2.thrift.http.port 配置thrift服务绑定的http端口,可以通过http执行hive操作

hive.server2.thrift.client.user 配置thrift服务的验证账户

hive.server2.thrift.client.password 配置thrift服务的验证密码

  1. 修改core-site.xml
    添加以下配置
<property>
        <name>hadoop.proxyuser.root.hosts</name>
        <value>*</value>
</property>
<property>
        <name>hadoop.proxyuser.root.groups</name>
        <value>*</value>
</property>

hadoop的文件配置说明
hadoop.proxyuser.root.hosts 配置hadoop的代理用户,主要是用于让hiveserver2客户端访问及操作hadoop文件具备权限
hadoop.proxyuser.root.groups 配置hadoop的代理用户组,主要是用于让hiveserver2客户端访问及操作hadoop文件具备权限
文件说明
如果不清楚文件的具体位置,请浏览hadoop集群安装与搭建

我是单机版的,你们集群版记得把hive-site.xml和core-site.xml都分发到其他机器上

单机版的就不用搞分发了
3.启动服务

hadoop集群要重新启动

瘦客户端服务的启动,这里有两种启动方式,一种是前台启动,即控制台一直打印日志,且不能关掉控制台,关掉即服务挂掉

cd /Users/zhaohaichao/programming/hive-1.1.0-cdh5.15.1/bin
./hiveserver2

另一种是后台启动的方式,后台启动控制台可以关闭,且在进程中运行,执行 jps,可以看到hive的进程

cd /Users/zhaohaichao/programming/hive-1.1.0-cdh5.15.1/bin
nohup hive --service hiveserver2 &

等2分钟左右,我们再去启动客户端,这样避免做多次连接操作而连接不上,原因是服务端的程序还没执行完成

4.启动瘦客户端beeline:

cd /Users/zhaohaichao/programming/hive-1.1.0-cdh5.15.1/bin
beeline
!connect jdbc:hive2://hadoop1:10000

命令说明:

执行beeline,启动了thirft服务,通过thirft的jdbc命令连接hive。
hadoop1是启动hive服务的主机名,10000则是hive-site.xml文件配置的端口。
执行上面命令之后,需要执行hive-site.xml文件上配置的验证账户和密码,即root,回车之后,就登陆进hive了

注:
启动后问题:
1、要求输入用户名和密码
这个时候由于hive.server2.authentication设置的值是NONE,所以不输入也能进入,直接回车就行
2、连接不上问题
可能会报错:

Error: Could not establish connection to jdbc:hive2://localhost:10000: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{use:database=default}) (state=08S01,code=0)

这个时候查看是不是执行beeline命令后出现

Beeline version 1.2.1.spark2 by Apache Hive

类似这样的spark的东西,因为spark的bin目录下也是有beeline的,网上有解决方案是进入hive的bin目录下执行beeline,但是我这么执行也会报错,并没有什么用

正确的启动应该是你hive的版本,如下

Beeline version 1.1.0-cdh5.15.1 by Apache Hive

解决方案,将spark的环境变量注释掉就好了,或者将spark的bin目录下的beeline改个名字,如果是集群版,建议spark和hive不要装一台机器上,可以避免这个问题

2、mr查询报错问题

报错如下:

hue 设置hiveserver2 hiveserver2配置_hadoop


Caused by: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.AccessControlException): Permission denied: user=root, access=EXECUTE, inode="/tmp/hadoop-yarn/staging":zhaohaichao:supergroup:drwx------

解决方式,执行:

hadoop fs -chmod -R 777 /tmp/hadoop-yarn