# tar -xf zookeeper-3.4.10.tar.gz # cd zookeeper-3.4.10
进入conf目录,将默认的zoo_sample.cfg改成zoo.cfg,执行命令:bin/zkServer.sh start启动即可
zkServer命令相关参数:
Usage: bin/zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}
将解压出来的zookeeper目录拷贝三份,如:zookeeper1,zookeeper2,zookeeper3。 分别创建并修改配置文件zoo0x.cfg,dataDir和clientPort不能相同。 分别在三个dataDir目录中创建文件myid,存放对应服务节点数字,如:server.1存储1。 分别修改完成后,即可运行bin/zkServer.sh启动zookeeper服务节点。集群节点必须是奇数个
配置文件参考:
vim /opt/zookeeper01/conf/zoo01.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=/tmp/zookeeper01 dataDir=/data/product/zookeeper01/datadir # the port at which the clients will connect clientPort=2181 # listen ip address #clientPortAddress=localhost # 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.01=localhost:2887:3887 server.02=localhost:2888:3888 server.03=localhost:2889:3889
server.A=B:C:D
- A 是一个数字,表示这个是第几号服务器;
- B 是这个服务器的IP地址(或者是与IP地址做了映射的主机名);
- C 第一个端口用来集群成员的信息交换,表示这个服务器与集群中的Leader服务器交换信息的端口;
- D 是在leader挂掉时专门用来进行选举leader所用的端口。
默认情况下zookeeper的日志是根据执行bin/zkServer.sh start命令时所在的路径,在当前路径下创建一个文件名为:zookeeper.out的文件并将日志内容写入其中
修改日志保存到固定路径的文件下:
1,修改启动脚本bin/zkServer.sh,增加:
ZOO_LOG_DIR="$ZOOBINDIR/../logs"
2,修改vim bin/zkEnv.sh
42 if [ "x$ZOOCFG" = "x" ] 43 then 44 ZOOCFG="zoo02.cfg"
spring: cloud: zookeeper: connect-string: localhost:2181,localhost:2182,localhost:2183
注意:如果使用 Spring Cloud Zookeeper Config 模块,必须配置在 bootstrap.yml 中
注意:zookeeper集群最好保持奇数个节点,如果集群中的节点只剩下1个,集群将会失效,客户端将无法连接