consul通用命令

consul通用命令

1.查看consul已注册服务

- http API方式:
curl -s http://127.0.0.1:8500/v1/agent/services |  jq -r '.[] | [.Service, .Address, .Port] |@csv'

- consul catalog:
consul catalog services

2.注册consul

- 注册接口:
  http://127.0.0.1:8500/v1/agent/service/register 
- 服务查询接口:
  http://127.0.0.1:8500/v1/agent/services
- 注册服务请求接口:
  curl --request PUT --data "$(jq -r .service <<<"$req")" http://127.0.0.1:8500/v1/agent/service/register
  $reg={
  {
  "service": {
    "id": "$ID" ,
    "name": "$NAME" ,
    "address": "$ADDRESS",
    "port": $PORT,
    "check": {
      "tcp": "$ADDRESS:$PORT",
      "interval": "10s",
      "timeout": "3s"
      }
    }
   }
- 变量值说明:
    id: 服务名+uid 
    name:服务名
    address:服务所对应的ip
    port:服务监听的端口
- consul注册的脚本:
  /data/install/bin/reg_consul_svc