docker 部署 zookeeper 集群

安装环境:

  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

猜你喜欢

转载自www.cnblogs.com/wh-blog/p/11283236.html