问题报错
否则报错如下:2011-10-28 09:39:44,856 – WARN [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:5858:NIOServerCnxn$Factory@253] – Too many connections from /172...* – max is 10
一直报这个错误
解决办法
设置同一个ip最大的连接数为300
vim zoo.cfg
# set max client connects
maxClientCnxns=300
默认zookeeper给每个客户端IP使用的连接数为10个,经常会出现连接不够用的情况。修改连接数目前好像只支持zoo.cfg配置文件修改,所以需要zookeeper重启才能生效。
3.4.3版本为60个连接
配置文件参数
http://zookeeper.apache.org/doc/r3.4.3/zookeeperAdmin.html 官方网站
Configuration Parameters
ZooKeeper's behavior is governed by the ZooKeeper configuration file. This file is designed so that the exact same file can be used by all the servers that make up a ZooKeeper server assuming the disk layouts are the same. If servers use different configuration files, care must be taken to ensure that the list of servers in all of the different configuration files match.
Minimum Configuration
Here are the minimum configuration keywords that must be defined in the configuration file:
clientPort
the port to listen for client connections; that is, the port that clients attempt to connect to.
dataDir
the location where ZooKeeper will store the in-memory database snapshots and, unless specified otherwise, the transaction log of updates to the database.
Note
Be careful where you put the transaction log. A dedicated transaction log device is key to consistent good performance. Putting the log on a busy device will adversely effect performance.
tickTime
the length of a single tick, which is the basic time unit used by ZooKeeper, as measured in milliseconds. It is used to regulate heartbeats, and timeouts. For example, the minimum session timeout will be two ticks.
Advanced Configuration
The configuration settings in the section are optional. You can use them to further fine tune the behaviour of your ZooKeeper servers. Some can also be set using Java system properties, generally of the form zookeeper.keyword. The exact system property, when available, is noted below.
dataLogDir
(No Java system property)
This option will direct the machine to write the transaction log to the dataLogDir rather than the dataDir. This allows a dedicated log device to be used, and helps avoid competition between logging and snaphots.
Note
Having a dedicated log device has a large impact on throughput and stable latencies. It is highly recommened to dedicate a log device and set dataLogDir to point to a directory on that device, and then make sure to point dataDir to a directory not residing on that device.
globalOutstandingLimit
(Java system property: zookeeper.globalOutstandingLimit.)
Clients can submit requests faster than ZooKeeper can process them, especially if there are a lot of clients. To prevent ZooKeeper from running out of memory due to queued requests, ZooKeeper will throttle clients so that there is no more than globalOutstandingLimit outstanding requests in the system. The default limit is 1,000.
preAllocSize
(Java system property: zookeeper.preAllocSize)
To avoid seeks ZooKeeper allocates space in the transaction log file in blocks of preAllocSize kilobytes. The default block size is 64M. One reason for changing the size of the blocks is to reduce the block size if snapshots are taken more often. (Also, see snapCount).
snapCount
(Java system property: zookeeper.snapCount)
ZooKeeper logs transactions to a transaction log. After snapCount transactions are written to a log file a snapshot is started and a new transaction log file is created. The default snapCount is 100,000.
traceFile
(Java system property: requestTraceFile)
If this option is defined, requests will be will logged to a trace file named traceFile.year.month.day. Use of this option provides useful debugging information, but will impact performance. (Note: The system property has no zookeeper prefix, and the configuration variable name is different from the system property. Yes - it's not consistent, and it's annoying.)
maxClientCnxns
(No Java system property)
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.
clientPortAddress
New in 3.3.0: the address (ipv4, ipv6 or hostname) to listen for client connections; that is, the address that clients attempt to connect to. This is optional, by default we bind in such a way that any connection to the clientPort for any address/interface/nic on the server will be accepted.
minSessionTimeout
(No Java system property)
New in 3.3.0: the minimum session timeout in milliseconds that the server will allow the client to negotiate. Defaults to 2 times the tickTime.
maxSessionTimeout
(No Java system property)
New in 3.3.0: the maximum session timeout in milliseconds that the server will allow the client to negotiate. Defaults to 20 times the tickTime.
fsync.warningthresholdms
(Java system property: fsync.warningthresholdms)
New in 3.3.4: A warning message will be output to the log whenever an fsync in the Transactional Log (WAL) takes longer than this value. The values is specified in milliseconds and defaults to 1000. This value can only be set as a system property.
autopurge.snapRetainCount
(No Java system property)
New in 3.4.0: When enabled, ZooKeeper auto purge feature retains the autopurge.snapRetainCount most recent snapshots and the corresponding transaction logs in the dataDir and dataLogDir respectively and deletes the rest. Defaults to 3. Minimum value is 3.
autopurge.purgeInterval
(No Java system property)
New in 3.4.0: The time interval in hours for which the purge task has to be triggered. Set to a positive integer (1 and above) to enable the auto purging. Defaults to 0.
中文参考
dataDir = 数据存放路径
dataLogDir = 日志存放路径
clientPort = 客户端连接端口
clientPortAddress
tickTime= 整形 不能为0
maxClientCnxns= 整形 最大客户端连接数
minSessionTimeout= 整形
maxSessionTimeout= 整形
initLimit = 整形
syncLimit = 整形
electionAlg = 整形
peerType = observer | participant
server. sid= host:port | host:port:port | host:port:port:type (type值 observer | participant)
group.gid = sid:sid (一个ID, 值是多个sid, 中间以:分割, 一个sid只能属于一个gid)
weight.sid=整形
本文转自 yanconggod 51CTO博客,原文链接:http://blog.51cto.com/yanconggod/2050787