官方建议 : 集群最少3台服务器,且强烈建议使用奇数台服务器;如果搭建2台,不如只搭建单节点,可不阅读
For replicated mode, a minimum of three servers are required, and it is strongly recommended that you have an odd number of servers. 对于集群模式,至少需要三台服务器,并且我们强烈建议您使用奇数台服务器。 If you only have two servers, then you are in a situation where if one of them fails, there are not enough machines to form a majority quorum. 如果您只有两台服务器,那么您所处的情况是,如果其中一台出现故障,则没有足够的机器来形成多数仲裁 Two servers are inherently less stable than a single server, because there are two single points of failure. 两台服务器本质上不如一台服务器稳定,因为会存在两个单点故障
停止之前160服务的ZooKeeper,安装参照 ZooKeeper-单节点
第 12 行 修改数据存储位置
dataDir=/usr/local/src/apache-zookeeper-3.7.0-bin/data
在文件末尾追加内容(2888是通信端口,3888是选举接口)
# server.Y=IP:port1:port2 server.1=192.168.109.160:2888:3888 server.2=192.168.109.161:2888:3888 server.3=192.168.109.162:2888:3888
cd .. cd data/ echo 1 > myid cat myid
firewall-cmd --query-port=2181/tcp firewall-cmd --zone=public --add-port=2181/tcp --permanent firewall-cmd --reload
进入bin目录,分别在三台机器上执行启动命令
./zkServer.sh start
之后在三台机器上查看当前机器的角色,161是leader,其他是follower
./zkServer.sh status