hadoop hive 2.1.1 将Hive启动为服务

来源:互联网 发布:中文安卓编程开创者 编辑:程序博客网 时间:2024/06/05 07:52

我们之前使用的Shell方式与Hive交互只是Hive交互方式中的一种,还有一种就是将Hive启动为服务,然后运行在一个节点上,那么剩下的节点就可以使用客户端来连接它,从而也可以使用Hive的数据分析服务。

前台模式

可以使用下面的命令来将Hive启动为服务。

/root/apps/hive-1.2.1/bin/hiveserver2

后台模式

也可以用下面的命令在后台启动Hive服务。

nohup bin/hiveserver2 1>/var/log/hiveserver.log 2>/var/log/hiveserver.err &

使用beeline连接Hive

用 lsof -i:10000 查看一下 服务是否已经启动起来

我们就在amaster上使用Hive自带的beeline来连接Hive。

/root/apps/hive-1.2.1/bin/beenline

命令提示行变成如下的样子:

Beeline version 1.2.1 by Apache Hivebeeline> 

使用下面的命令连接服务端:

!connect jdbc:hive2://localhost:10000

默认使用启动Hive的用户名我这里是root,密码为空,连上了。

0: jdbc:hive2://localhost:10000> 

尝试执行几个命令:

show databases;

0: jdbc:hive2://localhost:10000> show databases;+----------------+--+| database_name  |+----------------+--+| default        || test_db        |+----------------+--+2 rows selected (1.651 seconds)

select * from t_test;

0: jdbc:hive2://localhost:10000> select * from t_test;+------------+--------------+--+| t_test.id  | t_test.name  |+------------+--------------+--+| 1          | 张三           || 2          | 李四           || 3          | 风凌           || 4          | 三少           || 5          | 月关           || 6          | abc          |+------------+--------------+--+
LF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Connecting to jdbc:hive2://localhost:10000/default
Enter username for jdbc:hive2://localhost:10000/default: root
Enter password for jdbc:hive2://localhost:10000/default: ******

Error: Failed to open new session: java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): User: root is not allowed to impersonate root (state=,code=0)

解决方案:在hadoop>etc>hadoop>core-site.xml 中添加如下部分,重启服务即可:

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

 

HIVE2 :beeline连接设置用户名和密码注意问题

eeline connect有几种方式,见hive-site.xml,缺省为NONE。

 <property>    <name>hive.server2.authentication</name>    <value>NONE</value>    <description>      Expects one of [nosasl, none, ldap, kerberos, pam, custom].      Client authentication types.        NONE: no authentication check        LDAP: LDAP/AD based authentication        KERBEROS: Kerberos/GSSAPI authentication        CUSTOM: Custom authentication provider                (Use with property hive.server2.custom.authentication.class)        PAM: Pluggable authentication module        NOSASL:  Raw transport    </description>  </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>123456</value>
    <description>Password to use against thrift client</description>

  </property>

注意这里设置的用户要求对inode="/tmp/hive" 有执行权限,否则会出现下列问题:

Connecting to jdbc:hive2://localhost:10000/defaultEnter username for jdbc:hive2://localhost:10000/default: hiveEnter password for jdbc:hive2://localhost:10000/default: **Error: Failed to open new session: java.lang.RuntimeException: org.apache.hadoop.security.AccessControlException: Permission denied: user=hive, access=EXECUTE, inode="/tmp/hive":root:supergroup:drwxrwx---    at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.check(FSPermissionChecker.java:319)    at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkTraverse(FSPermissionChecker.java:259)    at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:205)    at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:190)    at org.apache.hadoop.hdfs.server.namenode.FSDirectory.checkPermission(FSDirectory.java:1698)    at org.apache.hadoop.hdfs.server.namenode.FSDirStatAndListingOp.getFileInfo(FSDirStatAndListingOp.java:108)    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getFileInfo(FSNamesystem.java:3817)    at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.getFileInfo(NameNodeRpcServer.java:1005)    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.getFileInfo(ClientNamenodeProtocolServerSideTranslatorPB.java:843)

0 0
原创粉丝点击