安裝環境:
3台裝有docker的Ubuntu 機器,192.168.120.100、192.168.120.101、192.168.120.102
步驟:
1、分別創建zookeeper的文件夾
mkdir ~/docker/zookeeper
cd ~/docker/zookeeper
2、創建zoo.cfg 文件
vim zoo.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=/data
# the port at which the clients will connect
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.1=192.168.120.100:2888:3888
server.2=192.168.120.101:2888:3888
server.3=192.168.120.102:2888:3888
添加如上配置文件;注:在Linux上每個配置項都要嚴謹,最后又空格,沒區分大小寫都是有問題的
3、創建data文件夾
mkdir data
4、根據配置寫入zookeeper的id
在192.168.120.100上執行 echo 1 > data/myid
在192.168.120.101上執行 echo 2 > data/myid
在192.168.120.102上執行 echo 3 > data/myid
5、運行容器
分別運行命令 sudo docker run -d --restart=always --name zookeeper --network host -v $PWD/zoo.cfg:/conf/zoo.cfg -v $PWD/data:/data zookeeper