- 以CentOS7为例
1.检查pip是否已安装
pip -V
如果显示版本python xxx
则已安装跳过第2步
执行第3步
, 否则显示pip: command not found
2.安装pip
#
yum -y install epel-release
yum -y install python-pip
#升级
pip install --upgrade pip
3.安装docker-compose
pip install docker-compose
# 检查docker-compose
docker-compose -version
4.Zookeeper集群
4.1. pull zookeeper
docker pull zookeeper
4.2. 创建docker-compose.yml文件
touch docker-compose.yml
# or
vim docker-compose.yml
4.3. 在docker-compose.yml中添加对应的集群信息
version: '3'
services:
zoo1:
image: zookeeper
restart: always
hostname: zoo1
ports:
- 2181:2181
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
zoo2:
image: zookeeper
restart: always
hostname: zoo2
ports:
- 2182:2181
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
zoo3:
image: zookeeper
restart: always
hostname: zoo3
ports:
- 2183:2181
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
4.4. 执行启动命令
docker-compose up -d
显示
Creating network "root_default" with the default driver
Creating root_zoo1_1 ... done
Creating root_zoo2_1 ... done
Creating root_zoo3_1 ... done
执行docker ps
此时3个容器出现
4cf5ab0f7b2c zookeeper:latest "/docker-entrypoint.…" 26 minutes ago Up 26 minutes 2888/tcp, 3888/tcp, 8080/tcp, 0.0.0.0:2183->2181/tcp root_zoo3_1
12638806d642 zookeeper:latest "/docker-entrypoint.…" 26 minutes ago Up 26 minutes 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp root_zoo1_1
d218b4ded21f zookeeper:latest "/docker-entrypoint.…" 26 minutes ago Up 26 minutes 2888/tcp, 3888/tcp, 8080/tcp, 0.0.0.0:2182->2181/tcp root_zoo2_1
好了恭喜你集群成功!