步骤一:启动为前台:bin/hiveserver2
步骤二:启动为后台:nohup bin/hiveserver2 1>/var/log/hiveserver.log 2>/var/log/hiveserver.err &
1:启动成功后,可以在别的节点上用beeline去连接
方式一:
hive/bin/beeline 回车,进入beeline的命令界面
输入命令连接hiveserver2
beeline> !connect jdbc:hive2//master:10000
(master机器是hiveserver2所启动的那台主机名,端口默认是10000)
方式二:
或者启动就连接:
bin/beeline -u jdbc:hive2://master:10000 -n hadoop
接下来就可以做正常sql查询了
1:将Hive作为一个服务器,其他机器可以作为客户端进行访问:
2:然后寻找符合thrift的这种协议的客户端来连这个服务,然而hive自带这种客户端(我这里复制本台机器,弄了两个窗口):
然后呢,就是开启了命令行客户端了,然后了连接你的hive即可。我这里遇到一个错误,顺手贴一下吧。
造成这个错误的原因是!connect jdbc:hive2//master:10000写成!connect jdbc:hive2//localhost:10000即可。
1 [root@master apache-hive-1.2.1-bin]# cd bin/ 2 [root@master bin]# ls 3 beeline ext hive hive-config.sh hiveserver2 metatool schematool 4 [root@master bin]# ./beeline 5 Beeline version 1.2.1 by Apache Hive 6 beeline> !connect jdbc:hive2//master:10000 7 scan complete in 1ms 8 17/12/12 04:42:53 [main]: ERROR beeline.ClassNameCompleter: Fail to parse the class name from the Jar file due to the exception:java.io.FileNotFoundException: minlog-1.2.jar (No such file or directory) 9 17/12/12 04:42:53 [main]: ERROR beeline.ClassNameCompleter: Fail to parse the class name from the Jar file due to the exception:java.io.FileNotFoundException: objenesis-1.2.jar (No such file or directory) 10 17/12/12 04:42:53 [main]: ERROR beeline.ClassNameCompleter: Fail to parse the class name from the Jar file due to the exception:java.io.FileNotFoundException: reflectasm-1.07-shaded.jar (No such file or directory) 11 scan complete in 5708ms 12 No known driver to handle "jdbc:hive2//master:10000"
然后呢我写成beeline> !connect jdbc:hive2://localhost:10000回车。会让你输入账号和密码,这里直接输入你的登陆linux的账号和密码即可,我习惯使用root和其密码操作,虽然不好,但是这里直接输入root账号,123456密码即可登陆。
1 beeline> !connect jdbc:hive2://localhost:10000 2 Connecting to jdbc:hive2://localhost:10000 3 Enter username for jdbc:hive2://localhost:10000: hadoop 4 Enter password for jdbc:hive2://localhost:10000: 5 Error: Failed to open new session: java.lang.RuntimeException: java.lang.RuntimeException: org.apache.hadoop.security.AccessControlException: Permission denied: user=hadoop, access=EXECUTE, inode="/tmp":root:supergroup:drwx------ 6 at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkFsPermission(FSPermissionChecker.java:271) 7 at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.check(FSPermissionChecker.java:257) 8 at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkTraverse(FSPermissionChecker.java:208) 9 at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:171) 10 at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.checkPermission(FSNamesystem.java:6545) 11 at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getFileInfo(FSNamesystem.java:4182) 12 at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.getFileInfo(NameNodeRpcServer.java:881) 13 at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.getFileInfo(ClientNamenodeProtocolServerSideTranslatorPB.java:821) 14 at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java) 15 at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:619) 16 at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:975) 17 at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2040) 18 at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2036) 19 at java.security.AccessController.doPrivileged(Native Method) 20 at javax.security.auth.Subject.doAs(Subject.java:415) 21 at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1656) 22 at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2034) (state=,code=0) 23 0: jdbc:hive2://localhost:10000 (closed)> !connect jdbc:hive2://localhost:10000 24 Connecting to jdbc:hive2://localhost:10000 25 Enter username for jdbc:hive2://localhost:10000: root 26 Enter password for jdbc:hive2://localhost:10000: ****** 27 Connected to: Apache Hive (version 1.2.1) 28 Driver: Hive JDBC (version 1.2.1) 29 Transaction isolation: TRANSACTION_REPEATABLE_READ 30 1: jdbc:hive2://localhost:10000>
登陆以后即可以进行操作,演示如下所示:
停更......
2017-12-12 20:50:44