作者: 大圆那些事 | 文章可以转载,请以超链接形式标明文章原始出处和作者信息
网址: http://www.cnblogs.com/panfeng412/archive/2013/03/23/hiveserver2-too-many-zookeeper-connections-issues.html
HiveServer2支持多客户端的并发访问,使用ZooKeeper来管理Hive表的读写锁。实际环境中,遇到了HiveServer2连接ZooKeeper出现Too many connections的问题,这里是对这一问题的排查和解决过程。
问题描述
HiveServer2服务无法执行hive命令,日志中提示如下错误:
2013-03-22 12:54:43,946 WARN zookeeper.ClientCnxn (ClientCnxn.java:run(1089)) - Session 0x0 for server hostname/***.***.***.***:2181, unexpected error, closing socket connection and attempting reconnect
java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:21)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:233)
at sun.nio.ch.IOUtil.read(IOUtil.java:200)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:236)
at org.apache.zookeeper.ClientCnxnSocketNIO.doIO(ClientCnxnSocketNIO.java:68)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:355)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1068)
问题排查
1. 首先,根据HiveServer2的错误日志,提示是由于Connection reset by peer,即连接被ZooKeeper拒绝。
2. 进一步查看HiveServer2上所配置的ZooKeeper集群日志(用户Hive表的读写锁管理),发现如下错误信息:
2013-03-22 12:52:48,938 [myid:] - WARN [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@193] - Too many connections from /***.***.***.*** - max is 50
<property>
<name>hive.server2.thrift.min.worker.threads</name>
<value>5</value>
<description>Minimum number of Thrift worker threads</description>
</property>
<property>
<name>hive.server2.thrift.max.worker.threads</name>
<value>100</value>
<description>Maximum number of Thrift worker threads</description>
</property>
<property>
<name>hive.server2.thrift.min.worker.threads</name>
<value>10</value>
<description>Minimum number of Thrift worker threads</description>
</property>
<property>
<name>hive.server2.thrift.max.worker.threads</name>
<value>200</value>
<description>Maximum number of Thrift worker threads</description>
</property>
<property>
<name>hive.zookeeper.session.timeout</name>
<value>60000</value>
<description>Zookeeper client's session timeout. The client is disconnected, and as a result, all locks released, if a heartbeat is not sent in the timeout.</description>
</property>
2)zoo.cfg中:
# Limits the number of concurrent connections (at the socket level) that a single client, identified by IP address
maxClientCnxns=200
# The minimum session timeout in milliseconds that the server will allow the client to negotiate
minSessionTimeout=1000
# The maximum session timeout in milliseconds that the server will allow the client to negotiate
maxSessionTimeout=60000