docker 安装consul集群
consul架构
image.png拉取镜像
https://hub.docker.com/_/consul/
拉取latest版本镜像
docker pull consul
consul 暴露端口
- DNS: The DNS server (TCP and UDP) : 8600
- HTTP: The HTTP API (TCP Only) :8500
- LAN Serf: The Serf LAN port (TCP and UDP) : 8301
- Wan Serf: The Serf WAN port (TCP and UDP) : 8302
- server: Server RPC address (TCP Only) : 8300
docker 启动consul并加入集群
-join 的ip 为第一个docker实例启动后的ip地址
docker run -d -p 8500:8500 -p 8600:8600/tcp -p 8600:8600/udp consul agent -server -ui -node=Server-A -bootstrap-expect=3 -client=0.0.0.0
docker run -d -p 8501:8500 -p 8601:8600/tcp -p 8601:8600/udp consul agent -server -ui -node=Server-B -bootstrap-expect=3 -client=0.0.0.0 -join=172.12.0.2
docker run -d -p 8502:8500 -p 8602:8600/tcp -p 8602:8600/udp consul agent -server -ui -node=Server-C -bootstrap-expect=3 -client=0.0.0.0 -join=172.12.0.2
docker 启动consul client节点
docker run -d -p 8503:8500 -p 8603:8600/tcp -p 8603:8600/udp consul agent -ui -node=client -bootstrap-expect=3 -client=0.0.0.0 -join=172.17.0.2
页面查看consul集群
打开页面即可查看consul集群情况:http://localhost:8503/ui/dc1/nodes
dig查看路由信息
dig @127.0.0.1 -p 8603 consul.service.consul
内容如下:
dig @127.0.0.1 -p 8603 consul.service.consul
; <<>> DiG 9.10.6 <<>> @127.0.0.1 -p 8603 consul.service.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44580
;; flags: qr aa rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;consul.service.consul. IN A
;; ANSWER SECTION:
consul.service.consul. 0 IN A 172.17.0.3
consul.service.consul. 0 IN A 172.17.0.2
consul.service.consul. 0 IN A 172.17.0.4
;; Query time: 7 msec
;; SERVER: 127.0.0.1#8603(127.0.0.1)
;; WHEN: Sat Jan 09 20:53:12 CST 2021
;; MSG SIZE rcvd: 98
网友评论