Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not connect to hiveserver2 #22

Closed
lixiyu opened this issue Mar 29, 2017 · 4 comments
Closed

can not connect to hiveserver2 #22

lixiyu opened this issue Mar 29, 2017 · 4 comments
Milestone

Comments

@lixiyu
Copy link

lixiyu commented Mar 29, 2017

I can connect to hiveserver2 in beeline whith beeline> !connect jdbc:hive2://192.168.1.110:10010
but cannot conncet to hiveserver2 whith code blow (there are no username and password):
$hive = new \ThriftSQL\Hive( '192.168.1.110',10010); $hiveTables = $hive ->setSasl( false ) /* To turn SASL auth off, on by default */ ->connect() ->queryAndFetchAll( 'SHOW TABLES' ); print_r( $hiveTables );

and I got the error :
PHP Fatal error: Uncaught Thrift\Exception\TException: TSocket: Could not connect to 192.168.1.110:10010 (Connection refused [111]) in phar:///home/lixiyu/code/php-thrift-sql/ThriftSQL.phar/Thrift/Transport/TSocket.php:235 Stack trace: #0 phar:///home/lixiyu/code/php-thrift-sql/ThriftSQL.phar/ThriftSQL/Hive.php(47): Thrift\Transport\TSocket->open() #1 /home/lixiyu/code/php-thrift-sql/example.php(10): ThriftSQL\Hive->connect() #2 {main} thrown in phar:///home/lixiyu/code/php-thrift-sql/ThriftSQL.phar/Thrift/Transport/TSocket.php on line 235

can somebody help me ?

@lixiyu
Copy link
Author

lixiyu commented Mar 29, 2017

may be is hiveserver2 close it self. after I restart hiveserver2, I got error bellow :
PHP Fatal error: Uncaught Thrift\Exception\TTransportException: TSocket read 0 bytes in phar:///home/lixiyu/code/php-thrift-sql/ThriftSQL.phar/Thrift/Transport/TSocket.php:269 Stack trace: #0 phar:///home/lixiyu/code/php-thrift-sql/ThriftSQL.phar/Thrift/Transport/TTransport.php(74): Thrift\Transport\TSocket->read(67108844) #1 phar:///home/lixiyu/code/php-thrift-sql/ThriftSQL.phar/Thrift/Protocol/TBinaryProtocol.php(212): Thrift\Transport\TTransport->readAll(67108864) #2 phar:///home/lixiyu/code/php-thrift-sql/ThriftSQL.phar/Packages/TCLIService/TCLIService.php(162): Thrift\Protocol\TBinaryProtocol->readMessageBegin(NULL, 0, 0) #3 phar:///home/lixiyu/code/php-thrift-sql/ThriftSQL.phar/Packages/TCLIService/TCLIService.php(131): ThriftSQL\TCLIServiceClient->recv_OpenSession() #4 phar:///home/lixiyu/code/php-thrift-sql/ThriftSQL.phar/ThriftSQL/Hive.php(62): ThriftSQL\TCLIServiceClient->OpenSession(Object(ThriftSQL\TOpenSessionReq)) #5 /home/lixiyu/code/php-thrift-sql/example.php(10): ThriftSQL\Hive->connect() #6 {main} thrown in phar:///home/lixiyu/code/php-thrift-sql/ThriftSQL.phar/Thrift/Transport/TSocket.php on line 269

@lixiyu
Copy link
Author

lixiyu commented Mar 30, 2017

问题解决了。算是hive配置的问题吧。有人说 PHP的框架不支持SASL,或者我不会用。
修改 hive-site.xml 的hive.server2.authentication的值,然后重启hiveserver2就 OK 了,但是改了之后 beeline 不能连上来了。
<property><name>hive.server2.authentication</name><value>NOSASL</value></property>
(这个值默认是 NULL ,必须改成 NOSASL 才能用这个框架按照我上面的用法连接成功。而且启动后第一次连接客户端会报错,但服务端日志正常,第二次开始才能拿到数据。而且很容易无端报错,重试几次就好了)

参考答案:
http://stackoverflow.com/questions/15415904/requests-hang-when-using-hiveserver2-thrift-java-client

@DYFeng
Copy link

DYFeng commented Apr 24, 2017

$hive = new \ThriftSQL\Hive('stats-hadoop11', 10000, 'yeyifeng','fake_password');
$hive->setSasl(true);
var_dump($hive->connect()->queryAndFetchAll('show tables;')) ;

Works for me.Just using a fake pasword.

But my hive server does not have this configure.
<property><name>hive.server2.authentication</name><value>NOSASL</value></property>

@mariedavis-abn
Copy link

I was trying to connect with Username Authentication for my Hiveserver2. I was getting an error for "tsocket read 0 bytes". Creating a fake username and password worked for me.

@xyu xyu added this to the v0.3 milestone Jul 24, 2019
xyu added a commit that referenced this issue Jul 24, 2019
Set a default username of `php-thrift-sql` when there is no username given for either Hive or Impala.

Also set a default password for Hive if none given. With SASL Hive just needs something set to not error out which prevents some common problems when using this lib. Closes #22 and #23
@xyu xyu closed this as completed in 25e1476 Jul 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants