多台服务器Docker-compose 安装zookeeper集群
多台服务器Docker-compose 安装zookeeper集群
安装docker-compose
• 安装docker:sudo apt-get install docker.io
• 开机启动docker sudo systemctl enable docker.service
• 安装docker-compose
-
sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
-
sudo chmod +x /usr/local/bin/docker-compose
zookeeper安装与配置
假定zookeeper安装在三台机器:10.1.2.101、10.1.2.102、10.1.2.103
设置固定格式的docker-compose 目录方便查找
mkdir -p ~/docker-compose-file/zookeeper
vim docker-compose.yml
#以10.1.2.101为例
version: '2'
services:
zookeeper:
image: 'zookeeper:latest'
restart: always
environment:
ZOO_MY_ID: 1
volumes:
- /data/docker-container-configs/zookeeper/zoo.cfg:/conf/zoo.cfg
#也可以挂载到主机,新建myid文件- /data/zookeeper:/data
#也可以挂载到主机- /data/docker-container-logs/zookeeper:/datalog
ports:
- 2181:2181
container_name: 'zookeeper101'
network_mode: "host"
保存docker-compose.yml
设置固定格式的config目录,方便查找
mkdir -p /data/docker-container-configs/zookeeper
vim zoo.cfg
写配置文件
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data
dataLogDir=/data
clientPort=2181
server.1=0.0.0.0:2888:3888
server.2=10.1.2.102:2888:3888
server.3=10.1.2.103:2888:3888
保存 zoo.cfg
#启动 一定要到docker-compose.yml文件所在目录执行
cd ~/docker-compose-file/zookeeper
sudo docker-compose up -d
依次配置启动三台服务器的zookeeper
检查集群
docker exec -ti [你的zookeeper container id] zkServer.sh status
- 1
显示Mode:follower或者leader 就说明集群配置成功了
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
Mode: follower