由于平台马上要引入zookeeper+dubbo,为了解决zookeeper单个实例运行的风险,需要做个集群。
1,先说配置:zoo.cfg十分简单,分两种情况:
一种是在一台机器采用不同的端口配置多个服务;另一种是在多台机器上每个配一个服务,这样的安全系数会大很多。
单机版:
# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. dataDir=/Users/xxxxxx/zookeeper/zookeeper-3.3.6/server1/data #不同节点不同端口:2081,2182,2183 clientPort=2181 server.1=localhost:2888:3888 server.2=localhost:2889:3889 server.3=localhost:2890:3890
多机版:
clientPort=2181
server.1=10.2.38.5:2888:3888
server.2=10.2.38.6:2888:3888
server.3=10.2.38.7:2888:3888
2,在各自data下面写入myid文件,内容为节点的序号,如1:
echo '1' > myid
3,依次启动服务即可:
sh zkServer.sh start