1)、集群目录zkcluster
cd /usr/local/
mkdir zkcluster
2)、zkcluster目录复制三份zookeeper01~03
cp -r zookeeper-3.4.6/ zookeeper01
cp -r zookeeper-3.4.6/ zookeeper02
cp -r zookeeper-3.4.6/ zookeeper03
3)、zkclusterzk目录zookeeper01~03生成data
mkdir data
/usr/local/zookeeper01/data
/usr/local/zookeeper02/data
/usr/local/zookeeper03/data
4)、zkcluster目录zookeeper01~03 生在服务器myid
##server.1,server.2,server.3
cd /usr/local/zookeeper01/data
touch myid
vi 输入1
cd /usr/local/zookeeper01/data
touch myid
vi 输入2
cd /usr/local/zookeeper01/data
touch myid
vi 输入3
4)、配置zkcluster目录zookeeper01~03 zoo.cfg
#####clientPort
#####Server.myid=IP:port1:port2
#####同一docker配置同一IP不同端号
#####localhost:29001:31001
vi /usr/local/zookeeper01/conf/zoo.cfg
加如下:
dataDir=/usr/local/zookeeper01/data
clientPort=28001
server.1=localhost:29001:31001
server.2=localhost:29002:31002
server.3=localhost:29003:31003
vi /usr/local/zookeeper02/conf/zoo.cfg
加如下:
dataDir=/usr/local/zookeeper02/data
clientPort=28002
server.1=localhost:29001:31001
server.2=localhost:29002:31002
server.3=localhost:29003:31003
vi /usr/local/zookeeper03/conf/zoo.cfg
加如下:
dataDir=/usr/local/zookeeper03/data
clientPort=28003
server.1=localhost:29001:31001
server.2=localhost:29002:31002
server.3=localhost:29003:31003
##server.myid=IP:Port1:Port2
##myid服务器编号 /usr/local/zookeeper01/myid
##port1服务器与集群中的Leader服务器交换信息的端口,一般用2288,
##Port2万一集群中的Leader服务器宕机,需要一个端口重新宣讲,选新Leader,一般3388
5)、zk目录zookeeper01~03 启动
cd /usr/local/zookeeper01/bin
./zkServer.sh start
./zkServer.sh status
#####Mode:follower#####
cd /usr/local/zookeeper02/bin
./zkServer.sh start
./zkServer.sh status
#####Mode:leader#####
cd /usr/local/zookeeper03/bin
./zkServer.sh start
./zkServer.sh status
#####Mode:follower#####
6)、客户端zkCli.sh
cd /usr/local/zookeeper02/bin
./zkCli.sh -server localhost:28002
6-7 zk容器生成镜像
#docker commit 容器ID zk:1.0
docker commit zk zk:1.0
6-8 新容器zk2
##端口映射 宿主机端口:容器端口
######### 2181:28002
docker run -it --name zk2 -p 2181:28002 zk:1.0
docker exec -ti -u root zk2 bash