部署集群要求server 数量>=3,client若干 server用于数据持久化与同步 client用于服务发现与转发
环境
服务器1:192.168.4.200
部署内容:consul-server、consul-agent
服务器2:192.168.4.202
部署内容:consul-server、consul-agent
服务器3:192.168.4.203
部署内容:consul-server、consul-agent
集群部署
三台服务器上准备docker及docker-compose,启动时先启动server、再启动client;server的启动需要先启动主节点
1、需要先启动一台server作为leader,以服务器2为例
version: '3.1'networks:consul:services:consul-agent: &consul-agentcontainer_name: consul-agentimage: consul:1.7.14restart: alwaysnetwork_mode: "host"command: "agent -retry-join 192.168.4.202 -client 0.0.0.0"volumes:- ./consul/consul-agent/config/consul-config.json:/consul/config/config.json- ./consul/consul-agent/data:/consul/dataconsul-server:container_name: consul-server<<: *consul-agentnetwork_mode: "host"command: "agent -server -node server-202 -bootstrap-expect 3 -advertise 192.168.4.202 -ui -client 0.0.0.0"#主 "agent -server -bootstrap-expect 3 -advertise 192.168.4.202 -ui -client 0.0.0.0"# 从 "agent -server -retry-join 192.xxx.xxx.xxx(主ip) -advertise 192.xxx.xxx.xxx -ui -client 0.0.0.0"volumes:- ./consul/consul-server/config/consul-config.json:/consul/config/config.json- ./consul/consul-server/data:/consul/data
2、服务器1:
version: '3.1'networks:consul:services:consul-agent: &consul-agentcontainer_name: consul-agentimage: consul:1.7.14restart: alwaysnetwork_mode: "host"command: "agent -retry-join 192.168.4.202 -client 0.0.0.0"volumes:- ./consul/consul-agent/config/consul-config.json:/consul/config/config.json- ./consul/consul-agent/data:/consul/dataconsul-server:container_name: consul-server<<: *consul-agentnetwork_mode: "host"command: "agent -server -node server-200 -join 192.168.4.202 -advertise 192.168.4.200 -ui -client 0.0.0.0"#主 "agent -server -bootstrap-expect 3 -advertise 192.168.4.202 -ui -client 0.0.0.0"# 从 "agent -server -retry-join 192.xxx.xxx.xxx(主ip) -advertise 192.xxx.xxx.xxx -ui -client 0.0.0.0"volumes:- ./consul/consul-server/config/consul-config.json:/consul/config/config.json- ./consul/consul-server/data:/consul/data
3、服务器3:
version: '3.1'networks:consul:services:consul-agent: &consul-agentcontainer_name: consul-agentimage: consul:1.7.14restart: alwaysnetwork_mode: "host"command: "agent -retry-join 192.168.4.202 -client 0.0.0.0"volumes:- ./consul/consul-agent/config/consul-config.json:/consul/config/config.json- ./consul/consul-agent/data:/consul/dataconsul-server:container_name: consul-server<<: *consul-agentnetwork_mode: "host"command: "agent -server -node server-203 -join 192.168.4.202 -advertise 192.168.4.203 -ui -client 0.0.0.0"#主 "agent -server -bootstrap-expect 3 -advertise 192.168.4.202 -ui -client 0.0.0.0"# 从 "agent -server -retry-join 192.xxx.xxx.xxx(主ip) -advertise 192.xxx.xxx.xxx -ui -client 0.0.0.0"volumes:- ./consul/consul-server/config/consul-config.json:/consul/config/config.json- ./consul/consul-server/data:/consul/data
