转载:https://blog.csdn.net/liu_zhaoming/article/details/79332232
准备环境
服务器1:192.168.241.101 paascloud-zk-01 端口:2181、2881、3881
服务器2:192.168.241.102 paascloud-zk-02 端口:2182、2882、3882
服务器3:192.168.241.103 paascloud-zk-03 端口:2183、2883、3883
jdk version jdk8.144
zk version 3.4.11
1.安装
wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.11/
tar -zxvf zookeeper-3.4.11.tar.gz /usr/local/tar -zxvf zookeeper-3.4.11.tar.gz /usr/local
mv zookeeper-3.4.11 zk
mkdir /usr/local/zk/data
mkdir /usr/local/zk/logs
- 1
- 2
- 3
- 4
- 5
配置
mkdir /usr/local/zk/data
mkdir /usr/local/zk/logs
mv /usr/local/zk/conf/zoo_sample.cfg zoo.cfg
vi zoo.cfg
dataDir=/usr/local/zk/data
dataLogDir=/usr/local/zk/logs
server.1=paascloud-zk-01:2881:3881
server.2=paascloud-zk-02:2882:3882
server.3=paascloud-zk-03:2883:3883
autopurge.snapRetainCount=3
touch /usr/local/zk/data/myid
三台服务顺序 按顺序 一次写入1 2 3
echo 1 > /var/data/zk/myid
echo 1 > /var/data/zk/myid
echo 1 > /var/data/zk/myid
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
启动服务
/usr/local/zk/bin/zkServer.sh start
- 1
查看三台服务器的状态
/usr/local/zk/bin/zkServer.sh status
- 1
服务器1
ZooKeeper JMX enabled by default
Using config: /usr/local/zk/bin/../conf/zoo.cfg
Mode: follower
- 1
- 2
- 3
- 4
服务器2
ZooKeeper JMX enabled by default
Using config: /usr/local/zk/bin/../conf/zoo.cfg
Mode: leader
- 1
- 2
- 3
服务器3
ZooKeeper JMX enabled by default
Using config: /usr/local/zk/bin/../conf/zoo.cfg
Mode: follower
- 1
- 2
- 3
- 4
到此集群搭建成功