zookeeper使用
一、docker-compose方式安装3个节点集群
version: '3.1'
services:
zoo1:
container_name: zoo1
image: zookeeper
hostname: zoo1
ports:
- 2181:2181
networks:
- zookeeper-network
volumes:
- /opt/zookeeper/zoo1/data:/data
- /opt/zookeeper/zoo1/conf/zoo.cfg:/conf/zoo.cfg
- /opt/zookeeper/zoo1/logs:/datalog
restart: always
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo2:
container_name: zoo2
image: zookeeper
hostname: zoo2
ports:
- 2182:2181
networks:
- zookeeper-network
volumes:
- /opt/zookeeper/zoo2/data:/data
- /opt/zookeeper/zoo2/conf/zoo.cfg:/conf/zoo.cfg
- /opt/zookeeper/zoo2/logs:/datalog
restart: always
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo3:
container_name: zoo3
image: zookeeper
hostname: zoo3
ports:
- 2183:2181
networks:
- zookeeper-network
volumes:
- /opt/zookeeper/zoo3/data:/data
- /opt/zookeeper/zoo3/conf/zoo.cfg:/conf/zoo.cfg
- /opt/zookeeper/zoo3/logs:/datalog
restart: always
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
networks:
zookeeper-network:
driver: bridge
注意:
compose文件中目录和文件需要提前建好
mkdir -p /opt/zookeeper/zoo1/data
mkdir -p /opt/zookeeper/zoo1/conf
mkdir -p /opt/zookeeper/zoo1/logs
touch /opt/zookeeper/zoo1/conf/zoo.cfg
mkdir -p /opt/zookeeper/zoo2/data
mkdir -p /opt/zookeeper/zoo2/conf
mkdir -p /opt/zookeeper/zoo2/logs
touch /opt/zookeeper/zoo2/conf/zoo.cfg
mkdir -p /opt/zookeeper/zoo3/data
mkdir -p /opt/zookeeper/zoo3/conf
mkdir -p /opt/zookeeper/zoo3/logs
touch /opt/zookeeper/zoo3/conf/zoo.cfg
分别修改zookeeper的/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=/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.
#
# https://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
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpHost=0.0.0.0
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
启动
docker-compose up -d
标签:opt,zookeeper,zoo2,zoo1,2181,zoo3 From: https://www.cnblogs.com/chuanghongmeng/p/17127772.html