美文网首页
consul节点治理:查看、删除无用节点

consul节点治理:查看、删除无用节点

作者: 做量化的程序员 | 来源:发表于2021-08-18 20:23 被阅读0次

    springcloud微服务架构,使用Consul作为服务注册中心,有时某个服务已经不可用了但是依旧存在于Consul中,导致调用服务时,出现调用失败的情况,这时可以手动删除该服务。

    基础知识不在这里赘述,直接来管理节点

    1. 查询集群节点状态
    
    [root@localhost ~]# consul members
    Node      Address                   Status  Type    Build  Protocol  DC   Segment
    server-1  192.168.9.17:8301  alive   server  1.7.0  2              dc1  <all>
    server-2  192.168.9.18:8301  alive   server  1.7.0  2              dc1  <all>
    server-3  192.168.9.19:8301  alive   server  1.7.0  2              dc1  <all>
    

    命令输出显示了集群节点名称、IP端口、健康状态、启动模式、所在数据中心和版本信息。

    1. 查询本地的数据中心
    [root@dig-192-168-9-19 data]# curl http://192.168.9.19:8500/v1/catalog/datacenters
    [
        "dc1"
    ]
    

    返回的时数据中心名称,或者可以通过members中的DC直接看到

    1. 查询在该数据中心注册的服务
    http://ip:端口/v1/internal/ui/services?dc=数据中心id
    [root@dig-192-168-9-19 data]# curl http://192.168.9.19:8500/v1/internal/ui/services?dc=dc1
    [
        {
            "Name": "ai-server",
            "Tags": [
                "secure=false"
            ],
            "Nodes": [
                "dig-192-168-9-19"
            ],
            "ChecksPassing": 2,
            "ChecksWarning": 0,
            "ChecksCritical": 0
        },
        {
            "Name": "auth-server",
            "Tags": [
                "secure=false"
            ],
            "Nodes": [
                "dig-192-168-9-19"
            ],
            "ChecksPassing": 2,
            "ChecksWarning": 0,
            "ChecksCritical": 0
        }
    ]
    
    

    查询到注册的服务
    ChecksPassing 注册的节点数
    ChecksCritical 失败的节点数

    1. 查询服务节点
    [root@dig-192-168-9-19 ~]# curl http://192.168.9.19:8500/v1/health/service/auth-server?dc=dc1
    [
        {
            "Node": {
                "ID": "547ddd0a-bf1b-14ff-241d-4648b7aeaf2e",
                "Node": "dig-192-168-9-19",
                "Address": "127.0.0.1",
                "Datacenter": "dc1",
                "TaggedAddresses": {
                    "lan": "127.0.0.1",
                    "wan": "127.0.0.1"
                },
                "Meta": {
                    "consul-network-segment": ""
                },
                "CreateIndex": 7,
                "ModifyIndex": 7
            },
            "Service": {
                "ID": "auth-server-8085",
                "Service": "auth-server",
                "Tags": [
                    "secure=false"
                ],
                "Address": "dig-192-168-9-19",
                "Meta": null,
                "Port": 8085,
                "EnableTagOverride": false,
                "ProxyDestination": "",
                "Connect": {
                    "Native": false,
                    "Proxy": null
                },
                "CreateIndex": 21182,
                "ModifyIndex": 21182
            },
            "Checks": [
                {
                    "Node": "dig-192-168-9-19",
                    "CheckID": "serfHealth",
                    "Name": "Serf Health Status",
                    "Status": "passing",
                    "Notes": "",
                    "Output": "Agent alive and reachable",
                    "ServiceID": "",
                    "ServiceName": "",
                    "ServiceTags": [],
                    "Definition": {},
                    "CreateIndex": 10,
                    "ModifyIndex": 10
                },
                {
                    "Node": "dig-192-168-9-19",
                    "CheckID": "service:auth-server-8085",
                    "Name": "Service 'auth-server' check",
                    "Status": "passing",
                    "Notes": "",
                    "Output": "HTTP GET http://dig-192-168-9-19:8085/actuator/health: 200  Output: {\"status\":\"UP\"}",
                    "ServiceID": "auth-server-8085",
                    "ServiceName": "auth-server",
                    "ServiceTags": [
                        "secure=false"
                    ],
                    "Definition": {},
                    "CreateIndex": 21182,
                    "ModifyIndex": 21183
                }
            ]
        }
    ]
    
    
    1. 注销
    # 注销旧服务
    curl -s -X PUT "http://$CONSUL_NODE/v1/agent/service/deregister/$SERVER_ID"
    

    相关文章

      网友评论

          本文标题:consul节点治理:查看、删除无用节点

          本文链接:https://www.haomeiwen.com/subject/degibltx.html