Consul 基础8

2021-12-01 17:10:42 浏览数 (1)

查看服务

使用DNS API查看

可以使用 DNS API的方式查看服务对应的IP

代码语言:javascript复制
[root@h104 ~]# dig @127.0.0.1 -p 8600  web.service.consul

; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7_2.1 <<>> @127.0.0.1 -p 8600 web.service.consul
; (1 server found)
;; global options:  cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59452
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;web.service.consul.		IN	A

;; ANSWER SECTION:
web.service.consul.	0	IN	A	192.168.100.104

;; Query time: 1 msec
;; SERVER: 127.0.0.1#8600(127.0.0.1)
;; WHEN: Fri Mar 18 17:38:04 CST 2016
;; MSG SIZE  rcvd: 70

[root@h104 ~]# 

也可以使用 DNS API 获取整个 address/port 信息,只要加上 SRV

代码语言:javascript复制
[root@h104 ~]# dig @127.0.0.1 -p 8600  web.service.consul SRV

; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7_2.1 <<>> @127.0.0.1 -p 8600 web.service.consul SRV
; (1 server found)
;; global options:  cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32826
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;web.service.consul.		IN	SRV

;; ANSWER SECTION:
web.service.consul.	0	IN	SRV	1 1 80 h104.node.dc1.consul.

;; ADDITIONAL SECTION:
h104.node.dc1.consul.	0	IN	A	192.168.100.104

;; Query time: 1 msec
;; SERVER: 127.0.0.1#8600(127.0.0.1)
;; WHEN: Fri Mar 18 17:40:00 CST 2016
;; MSG SIZE  rcvd: 130

[root@h104 ~]#

0 人点赞