[root@localhost ~]# wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
[root@localhost ~]# tar -zxvf zookeeper-3.4.14.tar.gz
[root@localhost ~]# cd zookeeper-3.3.6/conf/ [root@localhost conf]# ls configuration.xsl log4j.properties zoo_sample.cfg
[root@localhost conf]# cp zoo_sample.cfg zoo.cfg [root@localhost conf]# ls configuration.xsl log4j.properties zoo.cfg zoo_sample.cfg
[root@localhost conf]# vi zoo.cfg
1、单机模式:不做集群,内容如下(data目录需改成你真实输出目录):
# 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=/usr/local/mycrosoftware/zookeeper/zookeeper-3.4.14/data dataLogDir=/usr/local/mycrosoftware/zookeeper/zookeeper-3.4.14/log # the port at which the clients will connect clientPort=2181
2、集群模式:要做集群,内容如下(dataDir目录和server地址需改成你真实部署机器的信息):目前并未测试
tickTime=2000 initLimit=10 syncLimit=5 dataDir=/root/zookeeper-3.3.6/data clientPort=2181 server.0=192.168.0.109:2555:3555 server.1=192.168.0.110:2555:3555 server.2=192.168.0.111:2555:3555
并在data目录下放置myid文件:(上面zoo.cfg中的dataDir)
mkdir data vi myid
myid指明自己的id,对应上面zoo.cfg中server.后的数字,第一台的内容为1,第二台的内容为2,内容如下
1
[root@localhost bin]# ./zkServer.sh start JMX enabled by default Using config: /root/zookeeper-3.3.6/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
[root@localhost bin]# ./zkCli.sh -server 127.0.0.1:2181
[root@localhost bin]# ps -aux | grep ‘zookeeper‘ #查看进程 netstat -anp|grep 2181 #查看zookeeper的端口号命令 bin/zkServer.sh stop #zookeeper 的停止命令 bin/zkServer.sh status #zookeeper 的状态查看命令
运行配置的作用
initLimit
ZooKeeper集群模式下包含多个zk进程,其中一个进程为leader,余下的进程为follower。
当follower最初与leader建立连接时,它们之间会传输相当多的数据,尤其是follower的数据落后leader很多。initLimit配置follower与leader之间建立连接后进行同步的最长时间。
syncLimit
配置follower和leader之间发送消息,请求和应答的最大时间长度。
tickTime
tickTime则是上述两个超时配置的基本单位,例如对于initLimit,其配置值为5,说明其超时时间为 2000ms * 5 = 10秒。
dataLogDir
dataLogDir指定的路径是事务日志保存路径
dataDir
dataDir指定的路径是快照保存路径,当没有指定dataLogDir路径时,事务日志也会保存在该目录下
server.id=host:port1:port2
其中id为一个数字,表示zk进程的id,这个id也是dataDir目录下myid文件的内容。
host是该zk进程所在的IP地址,port1表示follower和leader交换消息所使用的端口,port2表示选举leader所使用的端口。
其配置的含义跟单机模式下的含义类似,不同的是集群模式下还有一个myid文件。myid文件的内容只有一行,且内容只能为1 - 255之间的数字,这个数字亦即上面介绍server.id中的id,表示zk进程的id。
注意
如果仅为了测试部署集群模式而在同一台机器上部署zk进程,server.id=host:port1:port2配置中的port参数必须不同。但是,为了减少机器宕机的风险,强烈建议在部署集群模式时,将zk进程部署不同的物理机器上面。
博客参考:https://blog.csdn.net/qq_27739989/article/details/78078431
原文:https://www.cnblogs.com/hejj-bk/p/11587640.html