1、启动hadoop
2、开启 metastore 在开启 hiveserver2服务
nohup hive --service metastore >> log.out 2>&1 &
nohup hive --service hiveserver2 >> log.out 2>&1 &
查看进程是否起起来:
tandemac:bin tanzhengqiang$ jps -ml | grep Hive
27154 org.apache.hadoop.util.RunJar /Users/tanzhengqiang/myapp/hive/lib/hive-service-2.1.1.jar org.apache.hive.service.server.HiveServer2
26675 org.apache.hadoop.util.RunJar /Users/tanzhengqiang/myapp/hive/lib/hive-metastore-2.1.1.jar org.apache.hadoop.hive.metastore.HiveMetaStore
查看10000端口是否启动:
tandemac:bin tanzhengqiang$ lsof -i:10000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 27154 tanzhengqiang 403u IPv4 0x20931996ccd5c3d 0t0 TCP *:ndmp (LISTEN)
本地测试beeline连接,发现AuthorizationException,一猜便是没有权限呐
18/08/08 19:50:37 [main]: WARN jdbc.HiveConnection: Failed to connect to 127.0.0.1:10000
Error: Could not open client transport with JDBC Uri: jdbc:hive2://127.0.0.1:10000/test: Failed to open new session: java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): User: tanzhengqiang is not allowed to impersonate hive (state=08S01,code=0)
原因是我没有配置代理用户:
hadoop引入了一个安全伪装机制,使得hadoop 不允许上层系统直接将实际用户传递到hadoop层,而是将实际用户传递给一个超级代理,由此代理在hadoop上执行操作,避免任意客户端随意操作hadoop
在etc/hadoop/core-site.xml文件中修改为如下方式即可解决:
<property>
<name>hadoop.proxyuser.tanzhengqiang.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.tanzhengqiang.groups</name>
<value>*</value>
</property>
如果当前用户是tanzhengqiang,可直接登录,否则指定 -n选项
beeline> !connect jdbc:hive2://127.0.0.1:10000/test
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/tanzhengqiang/myapp/apache-hive-2.1.1-bin/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/tanzhengqiang/myapp/hadoop-2.7.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]
Connecting to jdbc:hive2://127.0.0.1:10000/test
Enter username for jdbc:hive2://127.0.0.1:10000/test:
Enter password for jdbc:hive2://127.0.0.1:10000/test:
Connected to: Apache Hive (version 2.1.1)
Driver: Hive JDBC (version 2.1.1)
18/08/08 20:28:44 [main]: WARN jdbc.HiveConnection: Request to set autoCommit to false; Hive does not support autoCommit=false.
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://127.0.0.1:10000/test> show databases;
+----------------+--+
| database_name |
+----------------+--+
| default |
| test |
+----------------+--+
2 rows selected (0.232 seconds)