http://apache.fayea.com/zookeeper
打开 conf 目录下 zoo_sample.cfg 将其名字改为 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. # do not use /tmp for storage, /tmp here is just # example sakes. # 修改的地方 dataDir=D:/JAVA/zookeeper-3.4.10/data dataLogDir=D:/JAVA/zookeeper-3.4.10/logs # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1
在bin目录下,双击zkServer.cmd即可启动Zookeeper。
如果启动闪退,可能是配置文件有问题,可以使用默认配置文件看是否可以启动。
所谓伪集群, 是指在单台机器中启动多个zookeeper进程, 并组成一个集群. 以启动3个zookeeper进程为例.
将zookeeper的目录拷贝2份:
|–zookeeper-3.4.10-0
|–zookeeper-3.4.10-1
|–zookeeper-3.4.10-2
与单机配置类似,只是3个zookeeper不能配置同一个目录下,配置如下
zookeeper0
# 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. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=D:/JAVA/zookeeper-3.4.10-0/data dataLogDir=D:/JAVA/zookeeper-3.4.10-0/logs # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 server.0=127.0.0.1:2888:3888 server.1=127.0.0.1:2889:3889 server.2=127.0.0.1:2890:3890
zookeeper-3.4.10-1 、zookeeper-3.4.10-2与zookeeper-3.4.10-0类似,只有dataDir和dataLogDir配置到不同的目录,clientPort在zookeeper-3.4.10-0中是2181,在zookeeper-3.4.10-1中是 2182,在 zookeeper-3.4.10-2中为 2183
在之前设置的dataDir中新建myid文件, 写入一个数字, 该数字表示这是第几号server. 该数字必须和zoo.cfg文件中的server.X中的X一一对应.
D:/JAVA/zookeeper-3.4.10-0/data/myid文件中写入0,zookeeper-3.4.10-1为1,zookeeper-3.4.10-2为2
server.A=B:C:D:其中
A 是一个数字,表示这个是第几号服务器;
B 是这个服务器的 ip 地址;
C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;
D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。
如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同的端口号。
集群模式的配置和伪集群基本一致.
由于集群模式下, 各server部署在不同的机器上, 因此各server的conf/zoo.cfg文件可以完全一样.基于Linux配置。
tickTime=2000 initLimit=5 syncLimit=2 dataDir=/home/zookeeper/data dataLogDir=/home/zookeeper/logs clientPort=4180 server.43=10.1.39.43:2888:3888 server.47=10.1.39.47:2888:3888 server.48=10.1.39.48:2888:3888 部署了3台zookeeper server, 分别部署在10.1.39.43, 10.1.39.47, 10.1.39.48上. 需要注意的是, 各server的dataDir目录下的myid文件中的数字必须不同. 10.1.39.43 server的myid为43, 10.1.39.47 server的myid为47, 10.1.39.48 server的myid为48.
10.1.39.43 server的myid为43, 10.1.39.47 server的myid为47, 10.1.39.48 server的myid为48.
部署完成后即可分别启动。
启动后要检查 Zookeeper 是否已经在服务,可以通过 netstat -at|grep 2181 命令查看是否有 clientPort 端口号在监听服务。
https://blog.csdn.net/cainiao_ACCP/article/details/73850904
原文:https://www.cnblogs.com/ryelqy/p/14192167.html