如何使用pyhive访问远程配置单元 [英] How to access remote hive using pyhive
问题描述
使用此链接尝试连接到远程配置单元.下面是使用的代码.接收到的错误消息也在下面给出
Used this link to try to connect to a remote hive. Below is the code used. The error msg received is also given below
代码
from pyhive import hive
conn = hive.Connection(host="10.111.22.11", port=10000, username="user1" ,database="default")
错误消息
Could not connect to any of [('10.111.22.11', 10000)]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/anaconda3/lib/python3.6/site-packages/pyhive/hive.py", line 131, in __init__
self._transport.open()
File "/opt/anaconda3/lib/python3.6/site-packages/thrift_sasl/__init__.py", line 61, in open
self._trans.open()
File "/opt/anaconda3/lib/python3.6/site-packages/thrift/transport/TSocket.py",line 113, in open
raise TTransportException(TTransportException.NOT_OPEN, msg)
thrift.transport.TTransport.TTransportException: Could not connect to any of [('10.111.22.11', 10000)]
成功连接还有哪些其他要求?我能够直接连接到服务器(使用腻子)并运行配置单元.但是,当从另一台服务器X尝试时,出现此错误.我也可以从服务器X ping Hive服务器.
What are the other requirements for successful connection? I am able to connect to the server directly (using putty) and run hive. But when tried from another server X i get this error. Also i can ping the hive server from server X.
端口号可能是问题吗?如何检查正确的端口号?
Could the port number be the problem? How do i check the correct port number?
正如下面的答案中所讨论的,我试图启动hiveserver2.但是该命令似乎不起作用.任何帮助都非常感谢.
As discussed in the below answer i tried to start hiveserver2 . But the command doesnt seem to work. Any help is really appreciated.
当我从配置单元外壳执行查询时,我在日志中看到的端口也是 8088 .想知道这是否应该是端口,而不是 10000 (两者均无法正常工作)
Also the port i see in the log when i execute a query from hive shell is 8088. wonder if this should be the port instead of 10000(both did not work anyway)
推荐答案
无法使用pyhive
使其工作.必须使用paramiko
插入
下面是示例代码
Could not make it work using pyhive
. Had to use paramiko
insted
below is the sample code
import os
import paramiko
import time
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh", "known_hosts")))
ssh.connect('1.1.1.1', username='uid', password='pwd')
sshin, sshout, ssherr= ssh.exec_command('hive -e "create table test(key varchar(10),keyval varchar(200))"')
这篇关于如何使用pyhive访问远程配置单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!