运行环境:
JDK 1.7 以上版本
最好在单独的机子上部署集群
集群节点为数量最好为 2n +1 ,即为单数,推荐最少为3个节点
因为:当为2个的时候,如果其中一个down了,另一个根据选举协议,无法得到节点中的大多数同意,无法升级为 Leader,就会导致整个服务器不可用
所以可以得出结论:节点数为3,可以容忍1个节点down,节点数为5,可以容忍2个节点down,依次类推。推荐的节点数就为 2n+1,这基本就可以保证高可用
只能保证基本的原因是:还要考虑网络的问题,比如同一个交换机等
官方参考文档:
http://zookeeper.apache.org/doc/r3.4.14/zookeeperAdmin.html#sc_zkMulitServerSetup
Clustered (Multi-Server) Setup
For reliable ZooKeeper service, you should deploy ZooKeeper in a cluster known as an ensemble. As long as a majority of the ensemble are up, the service will be available. Because Zookeeper requires a majority, it is best to use an odd number of machines. For example, with four machines ZooKeeper can only handle the failure of a single machine; if two machines fail, the remaining two machines do not constitute a majority. However, with five machines ZooKeeper can handle the failure of two machines.
Note
As mentioned in the ZooKeeper Getting Started Guide , a minimum of three servers are required for a fault tolerant clustered setup, and it is strongly recommended that you have an odd number of servers.
Usually three servers is more than enough for a production install, but for maximum reliability during maintenance, you may wish to install five servers. With three servers, if you perform maintenance on one of them, you are vulnerable to a failure on one of the other two servers during that maintenance. If you have five of them running, you can take one down for maintenance, and know that you're still OK if one of the other four suddenly fails.
Your redundancy considerations should include all aspects of your environment. If you have three ZooKeeper servers, but their network cables are all plugged into the same network switch, then the failure of that switch will take down your entire ensemble.