1.官网下载zk安装包?https://zookeeper.apache.org/
2.登录服务器创建三个zk目录,之后在每个文件夹中创建zk dataDir与dataLogDir
mkdir zookeeper2181
mkdir zookeeper2182
mkdir zookeeper2183
cd data/zookeeper2181
mkdir data
mkdir logs
3.分别进入dataDir创建myid文件
cd /data/zookeeper2181/data/
touch myid
vim myid
对应myid 设置为1 2 3与后续zoo.cfg文件对应
4.?分别在每个文件夹中上传安装包后解压
5.进入zk conf文件夹,将zoo_sample.cfg改为zoo.cfg
cd /data/zookeeper2181/apache-zookeeper-3.5.9-bin/conf
mv zoo_sample.cfg zoo.cfg
6.依次修改修改zoo.cfg配置文件中dataDir,dataLogDir,clientPort增加server.NUM=IP:port1:port2配置
# 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
# 存放内存数据快照文件及myid
dataDir=/data/zookeeper2181/data
# 存放事务日志
dataLogDir=/data/zookeeper2181/logs
# 每个实例用一个端口
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.NUM=IP:port1:port2 NUM表示第几号服务器与myid对应;IP为每台机器ip地址;
#port1为leader与follower通信端口;port2为参与竞选leader的通信端口
server.1=127.0.0.1:6789:6790
server.2=127.0.0.1:6791:6792
server.3=127.0.0.1:6793:6794
7.依次进入每个zk bin目录启动
cd /data/zookeeper2182/apache-zookeeper-3.5.9-bin/bin
./zkServer.sh start
8.验证集群是否成功通信
可以在bin目录下直接执行./zkServer.sh status 查看同步状态
也可在bin目录下 执行./zkCli.sh 进入zk
创建节点 create /test
其他客户端进入zk查看是否创建成功 ls /
????????如果开始没配置dataLogDir目录,zk会在dataDir下创建version-2文件夹保存事务日志,下次配置dataLogDir后会导致重启失败,自己搭的话可以直接删除改文件重新启动
? ? ? ? 多机器集群搭建与此步骤一致,确保网络畅通,更改zoo.cfg中ip与端口即可
|