我有2个数据中心[dc1
,dc2
],两者都是使用加入加入的 -
wan(consul join -wan server1 server2 serverN)
使用Fabio
进行负载平衡。
Consul Federation(Basic)
用于远程数据中心查询转发。
My Infra:每个数据中心有3个Consul服务器。后端中的2个Web服务器,在每个数据中心的consul服务器上注册了他们的服务和运行状况检查。在每个数据中心注册同名的服务中。不同的ServiceID
Server Version: Consul v1.0.2
Client Version: Consul v1.0.2
客户服务和健康检查:httpserver.json
{ "service": {
"id": "SERVICE-HTTP-WEB1",
"name": "httpserver",
"tags": ["urlprefix-/"],
"port": 8000,
"check": {
"id": "server_check",
"name": "CHeck_Nginx",
"http": "http://localhost:8000",
"interval": "5s",
"timeout": "1s"
}
}
}
在每个数据中心,传入的网络流量通过fabio load balancer
路由到后端nginx服务器。
问题是当所有客户端Nginx Web服务器都出现故障或所有客户端节点都在任何数据中心中出现故障时。应将流量转发到远程数据中心。相反,我在日志中看到了:
日志:[WARN] localhost的路由:9999 /
我错过了什么吗?
查询领事成员时-wan
## Consul start:
/consul agent \
-advertise=10.139.80.88 \
-bind=0.0.0.0 \
-advertise-wan=139.59.68.32 \
-bootstrap-expect=3 \
-client=0.0.0.0 \
-data-dir=/var/lib/consul \
-config-dir=/etc/consul.d/server \
-server \
-ui
配置文件:config.json
{
"server": true,
"datacenter": "dc2",
"data_dir": "/var/lib/consul",
"log_level": "INFO",
"enable_syslog": true,
"translate_wan_addrs": true, # It doesn't affect whether apply or not
"retry_join": ["10.139.80.89", "10.139.80.87"] # registered proper using private/public as well
}
领事成员-wan
[正确信息]
Node Address Status Type Build
Protocol DC Segment dc1-server-0.dc1 10.139.80.88:8302 alive
server 1.0.2 2 dc1 <all> dc1-server-1.dc1
10.139.80.89:8302 alive server 1.0.2 2 dc1 <all> dc1-server-2.dc1 10.139.80.87:8302 alive server 1.0.2 2
dc1 <all> dc2-server-0.dc2 10.130.71.114:8302 alive server
1.0.2 2 dc2 <all> dc2-server-1.dc2 10.130.71.113:8302 alive server 1.0.2 2 dc2 <all> dc2-server-2.dc2
10.130.71.115:8302 alive server 1.0.2 2 dc2 <all>
[同时注册私人和公共IP。在wan]
中,服务器注册没有问题当我查询远程数据中心时,反之亦然,结果是正确的。
dig @localhost -p 8600 httpserver.service.dc2.consul
; <<>> DiG 9.10.3-P4-Ubuntu <<>> @localhost -p 8600
httpserver.service.dc2.consul ; (1 server found) ;; global options:
+cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47869 ;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0,
ADDITIONAL: 1 ;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;;
QUESTION SECTION: ;httpserver.service.dc2.consul. IN A
;; ANSWER SECTION: httpserver.service.dc2.consul. 0
IN A 10.139.240.239 **[NGINX RUNNING ]**
httpserver.service.dc2.consul. 0 IN A 10.139.48.49 **[NGINX
RUNNING ]**
;; Query time: 43 msec ;; SERVER: 127.0.0.1#8600(127.0.0.1) ;; WHEN:
Sun Jan 14 14:10:31 UTC 2018 ;; MSG SIZE rcvd: 90