一、推consul的鏡像到生產應用所有服務器。
每一個consul的server模式的容器,都須要單獨的物理服務器。node
主節點:
docker run -d --net=host --name=consul_pre1 consul:0.9.0 agent -server -bind=10.0.0.20 -node=consul_pre1 -bootstrap-expect 2 -client 0.0.0.0 -ui
#docker run -d --net=host --name=consul_node_1 consul:0.9.0 agent -server -bootstrap-expect=2 -ui -client=0.0.0.0 -node=consul_node1 -advertise=10.0.0.8nginx
從節點:
docker run -d --net=host --name=consul_pre2 consul:0.9.0 agent -bind=10.0.0.12 -node=consul_pre2 -retry-join=10.0.0.20
#docker run -d --net=host --name=consul_node_2 consul:0.9.0 agent -server -ui -client=0.0.0.0 -node=consul_node2 -retry-join=10.0.0.8 -advertise=10.0.0.9docker
#docker run -d --net=host --name=consul_node_3 consul:0.9.0 agent -server -ui -client=0.0.0.0 -node=consul_node3 -retry-join=10.0.0.8 -advertise=10.0.0.10bootstrap
nginx反向代理consul:vim
vim /usr/local/nginx/conf/nginx.conf服務器
server {
listen 8500;
server_name consul.server.com;
location / {
include proxy.conf;
proxy_pass http://consul;
}
}ui
vim /usr/local/nginx/conf/upstream.conf代理
upstream consul {
server 10.0.0.8:8500;
server 10.0.0.9:8500;
server 10.0.0.10:8500;server
dns解析添加A記錄:dns
vim /var/named/chroot/var/named/server.com.zone
consul.server.com. IN A 192.168.1.30
參考:
https://hub.docker.com/_/consul/