springcloud consul 搭建docker 集羣(1)
1、 建3個server節點 和1個client節點
-
配置docker 網絡
sudo docker network create --subnet=172.18.0.0/24 consulnet
-
創建配置文件
- 創建文件夾 consul_client_config , consul_server_config)
- 創建文件 consul_client_config/basic_config_1.json
{ "datacenter": "dc1", "log_level": "INFO", "node_name": "c1", "server": false, "bind_addr": "0.0.0.0", "client_addr": "0.0.0.0", "ui": false, "ports": { "dns": 8600, "http": 8500, "https": -1, "server": 8300, "serf_lan": 8301, "serf_wan": 8302 }, "rejoin_after_leave": true, "retry_join": [ "172.18.0.2", "172.18.0.3", "172.18.0.4" ], "retry_interval": "30s", "reconnect_timeout": "72h" }
- 創建文件 consul_server_config/basic_config_1.json
{ "datacenter": "dc1", "log_level": "INFO", "node_name": "s_1", "server": true, "bootstrap_expect": 2, "bind_addr": "0.0.0.0", "client_addr": "0.0.0.0", "ui": true, "ports": { "dns": 8600, "http": 8500, "https": -1, "server": 8300, "serf_lan": 8301, "serf_wan": 8302 }, "rejoin_after_leave": true, "retry_join": [ "172.18.0.2", "172.18.0.3", "172.18.0.4" ], "retry_interval": "30s", "reconnect_timeout": "72h" }
- 創建文件 consul_server_config/basic_config_2.json
{ "datacenter": "dc1", "log_level": "INFO", "node_name": "s_2", "server": true, "bootstrap_expect": 2, "bind_addr": "0.0.0.0", "client_addr": "0.0.0.0", "ui": true, "ports": { "dns": 8600, "http": 8500, "https": -1, "server": 8300, "serf_lan": 8301, "serf_wan": 8302 }, "rejoin_after_leave": true, "retry_join": [ "172.18.0.2", "172.18.0.3", "172.18.0.4" ], "retry_interval": "30s", "reconnect_timeout": "72h" }
- 創建文件 consul_server_config/basic_config_3.json
{ "datacenter": "dc1", "log_level": "INFO", "node_name": "s_3", "server": true, "bootstrap_expect": 2, "bind_addr": "0.0.0.0", "client_addr": "0.0.0.0", "ui": true, "ports": { "dns": 8600, "http": 8500, "https": -1, "server": 8300, "serf_lan": 8301, "serf_wan": 8302 }, "rejoin_after_leave": true, "retry_join": [ "172.18.0.2", "172.18.0.3", "172.18.0.4" ], "retry_interval": "30s", "reconnect_timeout": "72h" }
- 文件如下
- 複製文件到 /opt/config/consul/
cp -rf ./consul_server_config /opt/config/consul/ cp -rf ./consul_client_config /opt/config/consul/
-
docker 命令
-- server sudo docker run -d --name consul_s1 --net consulnet --ip 172.18.0.2 --restart always -v /etc/localtime:/etc/timezone:rw -v /etc/localtime:/etc/localtime:rw -v /opt/config/consul/consul_server_config/basic_config_1.json:/consul/config/basic_config_1.json consul agent -config-dir /consul/config sudo docker run -d --name consul_s2 --net consulnet --ip 172.18.0.3 --restart always -v /etc/localtime:/etc/timezone:rw -v /etc/localtime:/etc/localtime:rw -v /opt/config/consul/consul_server_config/basic_config_2.json:/consul/config/basic_config_1.json consul agent -config-dir /consul/config sudo docker run -d --name consul_s3 --net consulnet --ip 172.18.0.4 --restart always -v /etc/localtime:/etc/timezone:rw -v /etc/localtime:/etc/localtime:rw -v /opt/config/consul/consul_server_config/basic_config_3.json:/consul/config/basic_config_1.json consul agent -config-dir /consul/config -- client agent sudo docker run -d -p 8500:8500 -p 8600:8600 -p 8300:8300 -p 8301:8301 -p 8302:8303 --name consul_c1 --net consulnet --ip 172.18.0.5 --restart always -v /etc/localtime:/etc/timezone:rw -v /etc/localtime:/etc/localtime:rw -v /opt/config/consul/consul_client_config/basic_config_1.json:/consul/config/basic_config.json consul agent -config-dir /consul/config
-
打開 http://172.18.0.2:8500
沒有 api-gateway 和 testwebapp 項目