Consul服务域名访问时好时坏

如题,配置完Consul后,注册了一个MaxScale服务,然后想通过域名的方式访问MaxScale,但是通过ping的方式访问域名的时候,偶尔能ping通,大部分时间都是ping不通的,各个机器之前已经配置了IP访问信任,应该不是防火墙的问题(试过关闭防火墙一样不行)。另外还有一台测试用的应用服务器,/etc/resolv.conf配置是一样,ping maxscale.service.consul一直是没有问题的。
 
相关配置如下
Consul server配置:[db@mysql3 ~]$ cat /etc/consul.d/server.json
{
  "data_dir": "/tmp/consul",
  "datacenter": "dc1",
  "node_name": "server1",
  "log_level": "INFO",
  "server": true,
  "bootstrap": true,
  "bind_addr": "123.123.123.123",
  "client_addr": "123.123.123.123",
  "enable_syslog": true,
  "performance": {
      "raft_multiplier": 1
    },
  "dns_config": {
        "allow_stale": true,
        "max_stale": "15s"
    },
  "ports": {
        "dns": 53,
        "http": 80
    },
  "rejoin_after_leave": true,
  "addresses": {
        "http": "0.0.0.0",
        "dns": "0.0.0.0"
    },
  "ui":true
}
Consul client配置:
[db@iZ25ff0xryjZ ~]$ cat /etc/consul.d/client.json
{
  "data_dir": "/tmp/consul",
  "enable_script_checks": true,
  "node_name": "client11",
  "bind_addr": "124.124.124.124",
  "retry_join": ["123.123.123.123"],
  "retry_interval": "30s",
  "ports": {
        "dns": 53,
        "http": 80
    },
  "addresses": {
        "http": "0.0.0.0",
        "dns": "0.0.0.0"
    },
  "rejoin_after_leave": true,
  "start_join": ["123.123.123.123"]
}
 
Consul client MaxScale相关配置:
[db@iZ25ff0xryjZ ~]$ cat /etc/consul.d/maxscale.json
{"services": [
  {
   "id": "maxscale2",
   "name": "maxscale",
   "address": "124.124.124.124",
   "tags": ["max2"],
   "port": 4006,
   "check": {
    "script": "/usr/local/mysql57/bin/mysqladmin ping --host=124.124.124.124 --port=4006 --user=root --password=xxxx | grep alive || exit 2",
    "interval": "3s"}
   }
 ]
}
 
应用服务器1配置:
[db@mysql4 ~]$ cat /etc/resolv.conf 
options timeout:1 attempts:1 rotate single-request-reopen
nameserver 124.124.124.124
 
应用服务器1 ping 结果:
结果1:经常ping不通
[db@mysql4 ~]$  ping maxscale.service.consul
ping: unknown host maxscale.service.consul
结果2:小概率ping通
[db@web1 ~]$ ping maxscale.service.consul
PING maxscale.service.consul (124.124.124.124) 56(84) bytes of data.
64 bytes from 124.124.124.124: icmp_seq=1 ttl=56 time=1.42 ms
64 bytes from 124.124.124.124: icmp_seq=2 ttl=56 time=1.38 ms
64 bytes from 124.124.124.124: icmp_seq=3 ttl=56 time=1.35 ms
 
 
应用服务器1 ding 结果:这个动作一直没问题
[db@web1 ~]$ dig @123.123.123.123 maxscale.service.consul
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> @123.123.123.123 maxscale.service.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41632
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;maxscale.service.consul. IN A
;; ANSWER SECTION:
maxscale.service.consul. 0 IN A 124.124.124.124
;; Query time: 1 msec
;; SERVER: 123.123.123.123#53(123.123.123.123)
;; WHEN: Sat Jun 02 18:04:42 CST 2018
;; MSG SIZE  rcvd: 68
 
 
 
已邀请:

pytoday

赞同来自:


应用服务器1配置:
[db@mysql4 ~]$ cat /etc/resolv.conf 
options timeout:1 attempts:1 rotate single-request-reopen
nameserver 123.57.5.189


你mysql4这台服务器配置的dns是个公网IP看下这个IP是不是属于你的是否提供了dns服务吧?
web1这台机器你配置的dns看不出来是不是123.123.123.123但是你dig时是用的123.123.123.123正常解析了说明123.123.123.123这个dns才是你真正要解析域名用的dns。你在mysql4这台机器上也dig xxxx @123.123.123.123看下是否正常,正常的话把mysql4这台的dns更换成123.123.123.123(就是/etc/resolv.conf这个配置文件)。
 
还有mysql4这台/etc/resolv.conf这个配置不知道是你少复制东西了还是怎样,正常情况除了nameserver这行,其他行都应该注释的。一般dns的问题你/etc/resolv.conf配置的nameserver指定的哪个IP你测试解析本身时应该dig xxx @ip用你nameserver指定的IP。mysql4你配置的是一个dns,web1你dig的是另一个dns所以你web1这台机器dig的结果对mysql4这台没任何意义其实。

要回复问题请先登录注册