- 3台Linux,这里使用虚拟机搭建能够互连的3个centos系统
- 分别在3台Linux上安装jdk1.8
- 分别在3台Linux上创建zookeeper目录,用于存放zookeeper的安装目录和数据,目录下创建以下目录:
- 下载zookeeper-3.4.14.tar.gz,分别放到3台Linux并解压,效果如上图
- 3台Linux分别操作:把
/opt/zookeeper/zookeeper-3.4.14/conf
下的zoo_sample.cfg
复制成zoo.cfg
,修改内容为:
# 每次心跳间隔,毫秒
tickTime=2000
# 初始化时在多少次心跳内必须完成
# synchronization phase can take
initLimit=10
# 多少次心跳无响应就判断为宕机
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/opt/zookeeper/zkdata
dataLogDir=/opt/zookeeper/zkdataLog
# the port at which the clients will connect
clientPort=12181
# 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
#改为3台Linux的ip
server.1=192.168.1.103:12888:13888
server.2=192.168.1.113:12888:13888
server.3=192.168.1.114:12888:13888
- 对应上面的zoo.cfg配置文件,在
/zkdata
目录下echo "1" > myid
生成一个包含对应server标识的myid文件(比如192.168.1.113的myid的内容是2,192.168.1.114的myid的内容是3) - 确认防火墙没有拦截
- 进入
/opt/zookeeper/zookeeper-3.4.14/bin
,运行./zkServer.sh start
,3台Linux都启动后,通过./zkServer.sh status
查看是否有leader和follower节点
9.注意: zookeeper不会自动清理日志和快照,可以通过crontab定时任务调用./bin/zkCleanup.sh
命令来清理(写个脚本)
关闭zookeeper:cd /opt/zookeeper/zookeeper-3.4.14/ && bin/zkServer.sh stop