我们还可以使用 DNS API 结合 tag 来过滤服务
[root@h104 ~]# dig @127.0.0.1 -p 8600 rails.web.service.consul
; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7_2.1 <<>> @127.0.0.1 -p 8600 rails.web.service.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15147
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;rails.web.service.consul. IN A
;; ANSWER SECTION:
rails.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:43:27 CST 2016
;; MSG SIZE rcvd: 82
[root@h104 ~]#
[root@h104 ~]# curl http://localhost:8500/v1/catalog/service/web?pretty
[
{
"Node": "h104",
"Address": "192.168.100.104",
"ServiceID": "web",
"ServiceName": "web",
"ServiceTags": [
"rails"
],
"ServiceAddress": "",
"ServicePort": 80,
"ServiceEnableTagOverride": false,
"CreateIndex": 5,
"ModifyIndex": 5
}
][root@h104 ~]#
[root@h104 ~]#
查看服务的健康状态
[root@h104 ~]# curl http://localhost:8500/v1/health/service/web?passing
[{"Node":{"Node":"h104","Address":"192.168.100.104","TaggedAddresses":{"wan":"192.168.100.104"},"CreateIndex":3,"ModifyIndex":5},"Service":{"ID":"web","Service":"web","Tags":["rails"],"Address":"","Port":80,"EnableTagOverride":false,"CreateIndex":5,"ModifyIndex":5},"Checks":[{"Node":"h104","CheckID":"serfHealth","Name":"Serf Health Status","Status":"passing","Notes":"","Output":"Agent alive and reachable","ServiceID":"","ServiceName":"","CreateIndex":3,"ModifyIndex":3}]}][root@h104 ~]#
[root@h104 ~]#
[root@h104 ~]# curl http://localhost:8500/v1/health/service/web?pretty
[
{
"Node": {
"Node": "h104",
"Address": "192.168.100.104",
"TaggedAddresses": {
"wan": "192.168.100.104"
},
"CreateIndex": 3,
"ModifyIndex": 5
},
"Service": {
"ID": "web",
"Service": "web",
"Tags": [
"rails"
],
"Address": "",
"Port": 80,
"EnableTagOverride": false,
"CreateIndex": 5,
"ModifyIndex": 5
},
"Checks": [
{
"Node": "h104",
"CheckID": "serfHealth",
"Name": "Serf Health Status",
"Status": "passing",
"Notes": "",
"Output": "Agent alive and reachable",
"ServiceID": "",
"ServiceName": "",
"CreateIndex": 3,
"ModifyIndex": 3
}
]
}
][root@h104 ~]#
[root@h104 ~]#
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。