Consul 註冊服務和健康檢查

Consul 註冊服務和健康檢查

標籤(空格分隔): go

註冊服務文檔:https://developer.hashicorp.com/consul/api-docs/agent/service#register-service
健康檢查文檔:https://developer.hashicorp.com/consul/docs/services/usage/checks

註冊服務[API方式]

URL:http://127.0.0.1:8500/v1/agent/service/register
Body: 
{
  "ID": "user-service",
  "Name": "user-service",
  "Tags": ["user", "service", ""],
  "Address": "127.0.0.1",
  "Port": 9991
}

註冊服務 check:http

URL:http://127.0.0.1:8500/v1/agent/service/register?replace-existing-checks=true
Header:Content-type:application/json
Body:`{
       "ID": "user-web",
       "Name": "user-web",
       "Tags": ["user", "web", "gin"],
       "Address": "127.0.0.1",
       "Port": 9999,
       // 健康檢查
       "Check": {
         "http":"http://127.0.0.1:9999/health", // 健康檢查的路徑
         "Interval": "5s", // 間隔5秒
         "Timeout": "5s"
       },
       }`

註冊服務:check:grpc

grpc健康檢查文檔:https://github.com/grpc/grpc/blob/master/doc/health-checking.md
consul-grpc健康檢查文檔:https://developer.hashicorp.com/consul/docs/services/usage/checks#grpc-checks

1. GRPC服務註冊健康檢查:
// 註冊服務健康檢查
// "google.golang.org/grpc/health"
// "google.golang.org/grpc/health/grpc_health_v1"
grpc_health_v1.RegisterHealthServer(s, health.NewServer())

2. Consul註冊服務
URL:http://127.0.0.1:8500/v1/agent/service/register?replace-existing-checks=true
Body:{
        "ID": "user-service",
        "Name": "user-service",
        "Tags": ["user", "service", "grpc"],
        "Address": "127.0.0.1",
        "Port": 9991,
        "Check": {
           "GRPC":"127.0.0.1:9991",
           "GRPCUseTLS":false,
           "Interval": "5s",
           "Timeout": "5s"
        }
    }

驗證

訪問:http://127.0.0.1:8500/ui/dc1/services

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章