1、创建docker-compose文件
version: '3.4'
services:
zookeeper:
image: harbor-test.aitdcoin.com/sgpexchange/zookeeper:v3.4.13
restart: always
hostname: zookeeper3
container_name: zookeeper
ports:
- 2181:2181
- 2888:2888
- 3888:3888
volumes:
- "./data:/opt/zookeeper-3.4.13/data"
- "./conf/zoo.cfg:/opt/zookeeper-3.4.13/conf/zoo.cfg"
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=192.168.8.51:2888:3888 server.2=192.168.8.61:2888:3888 server.3=192.168.8.62:2888:3888
networks:
- zookeeper-net
networks:
zookeeper-net:
driver: bridge
三台主机都要配置,其中hostname自己定义,注意IP地址和myid更改
[root@sgpexchangeintermediate-192-168-8-62 zookeeper]# vim conf/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=/opt/zookeeper-3.4.13/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
3、启动zookeeper各个节点
[root@sgpexchangeMysqL-192-168-8-61 zookeeper]# docker-compose up -d
Creating network "zookeeper_zookeeper-net" with driver "bridge"
Creating zookeeper ... done
4、测试集群连通性
#随意进入一台主机添加一个根节点目录
[root@sgpexchangeintermediate-192-168-8-62 zookeeper]# docker exec -it zookeeper /bin/bash
root@zookeeper3:/opt/zookeeper-3.4.13# cd bin/
root@zookeeper3:/opt/zookeeper-3.4.13/bin# ./zkCli.sh -server 192.168.8.51:2181
Connecting to 192.168.8.51:2181
WatchedEvent state:SyncConnected type:None path:null
[zk: 192.168.8.51:2181(CONNECTED) 0] create /project zookeeper
Node already exists: /project
[zk: 192.168.8.51:2181(CONNECTED) 1] get /project
zookeeper_project
cZxid = 0x9
ctime = Thu May 13 11:24:46 UTC 2021
mZxid = 0x9
mtime = Thu May 13 11:24:46 UTC 2021
pZxid = 0x9
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 17
numChildren = 0
# 在第二个根节点查询节点目录情况
[zk: 192.168.8.51:2181(CONNECTED) 2] root@zookeeper3:/opt/zookeeper-3.4.13/bin# ./zkCli.sh -server 192.168.8.61:2181
Connecting to 192.168.8.61:2181
[zk: 192.168.8.61:2181(CONNECTED) 1] get /project
zookeeper_project
cZxid = 0x2
ctime = Thu May 13 11:14:34 UTC 2021
mZxid = 0x2
mtime = Thu May 13 11:14:34 UTC 2021
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 17
numChildren = 0
[zk: 192.168.8.61:2181(CONNECTED) 2] root@zookeeper3:/opt/zookeeper-3.4.13/bin# ./zkCli.sh -server 192.168.8.62:2181
Connecting to 192.168.8.62:2181
# 在第三个根节点查询新增节点目录
[zk: 192.168.8.62:2181(CONNECTED) 0] get /project
zookeeper_project
cZxid = 0xb
ctime = Thu May 13 11:26:47 UTC 2021
mZxid = 0xb
mtime = Thu May 13 11:26:47 UTC 2021
pZxid = 0xb
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 17
numChildren = 0
[zk: 192.168.8.62:2181(CONNECTED) 1]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。