在最近的一个项目中,遇到一个问题,就是一边是连接Zookeeper做服务发现、一边是连接Zookeeper做Kafka的消费者。因为设计的时候,客户端会监听N多的Topic,在最初测试的时候,没有发现什么异常,但是一导入线上数据就初出问题。总是会发现无法连接到Zookeeper,导致不能正常启动Kafka consumer 的情况。经过排查各种配置之后,发现了 maxClientCnxns 这一项配置。

注意,这里是指单IP的限制!

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.