# 创建 consul 数据目录
mkdir -vp /docker/consul/{node1,node2,node3}
# 给 consul 数据目录设所有者
chown -R 100:1000 /docker/consul/{node1,node2,node3}
# 创建 docker-compose.yml
cat <<'EOF'> /docker/consul/docker-compose.yml
version: "3.7"
services:
consul-server-1: &consul-server
image: consul:latest
restart: always
hostname: node1
command: "agent -server -data-dir /data -retry-join consul-server-bootstrap -client 0.0.0.0"
environment:
- TZ=Asia/Shanghai
volumes:
- /docker/consul/node1:/data
consul-server-2:
<<: *consul-server
hostname: node2
volumes:
- /docker/consul/node2:/data
consul-server-bootstrap:
<<: *consul-server
hostname: node3
volumes:
- /docker/consul/node3:/data
ports:
- "8300:8300"
- "8301:8301"
- "8301:8301/udp"
- "8500:8500"
- "8600:8600"
- "8600:8600/udp"
command: "agent -server -data-dir /data -bootstrap-expect 3 -ui -client 0.0.0.0"
EOF
# 启动 consul 集群服务
docker-compose -f /docker/consul/docker-compose.yml up -d
访问 服务器IP:8500
DONE