前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Consul 基础9

Consul 基础9

作者头像
franket
发布2021-12-01 17:11:12
2500
发布2021-12-01 17:11:12
举报
文章被收录于专栏:技术杂记

我们还可以使用 DNS API 结合 tag 来过滤服务

代码语言:javascript
复制
[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 ~]# 

使用HTTP API查看

代码语言:javascript
复制
[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 ~]# 

查看服务的健康状态

代码语言:javascript
复制
[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 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 使用HTTP API查看
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档