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.

相關文章
相關標籤/搜索