ZooKeeper客户端链接数过多

ZooKeeper限制客户端链接数服务器

问题:并发

最近发现ZooKeeper服务器上的链接数过多,都是链接zookeeper的。socket


解决方案:ide

经过查询分析,发现zookeeper的一个客户端使用有问题,建立的链接过多致使的。this

zookeeper有没有相应的功能能作下限制呢?spa

查看zookeeper的配置参数,能够发现zookeeper的能够经过相应的配置来限制某ip的链接数。ip


maxClientCnxnsrem

这个配置参数将限制链接到ZooKeeper的客户端的数量,限制并发链接的数量,它经过IP来区分不一样的客户端。此配置选项能够用来阻止某些类别的Dos***。该参数默认是60,将它设置为0将会取消对并发链接的限制。it

例如,将maxClientCnxns的值设置为1,以下所示:io

#set maxClientCnxns

maxClientCnxns=1

启动ZooKeeper以后,首先用一个客户端链接到ZooKeeper服务器之上。而后,当第二个客户端尝试对ZooKeeper进行链接,或者某些隐式的对客户端的链接操做,将会触发ZooKeeper的上述配置。系统会提示相关信息,以下图1所示:


ZooKeeper关于maxClientCnxns参数的官方解释:

单个客户端与单台服务器之间的链接数的限制,是ip级别的,默认是60,若是设置为0,那么代表不做任何限制。请注意这个限制的使用范围,仅仅是单台客户端机器与单台ZK服务器之间的链接数限制,不是针对指定客户端IP,也不是ZK集群的链接数限制,也不是单台ZK对全部客户端的链接数限制。

maxClientCnxns

Limits the number of concurrent connections (at the socket level) that a single client, identified by IP address, may make to a single member of the ZooKeeper ensemble. This is used to prevent certain classes of DoS attacks, including file descriptor exhaustion. The default is 60. Setting this to 0 entirely removes the limit on concurrent connections.

相关文章
相关标签/搜索