图片-稻子网
图片-稻子网
图片-稻子网
图片-稻子网

consul 1.4.0

单机服务端节点启动配置

vi /etc/systemd/system/consul.service
[Unit]
Description=consul
After=syslog.target network.target
[Service]
Type=simple
RemainAfterExit=no
WorkingDirectory=/usr/local/consul
ExecStart=/usr/local/consul/consul agent -ui -server -bootstrap -bind 127.0.0.1 -client 0.0.0.0 \\
  -data-dir /usr/local/consul/data -config-dir /usr/local/consul/consul.d \\
  -log-level debug -log-file /usr/local/consul/logs/ -log-rotate-duration 24h
[Install]
WantedBy=multi-user.target

consul 1.4.0 服务端ACL启用配置

vi /usr/local/consul/consul.d/acl.json
{
  "primary_datacenter": "dc1",
  "acl" : {
    "enabled": true,
    "default_policy": "deny",
    "down_policy": "extend-cache",
    "tokens" : {
      "master" : "blizzmi"
    }
  }
}

service 操作

vi playload.json
{
    "id": "DEV/test",
    "name": "DEVtest",
    "tags": ["node_exporter","hostname"],
    "address": "192.168.200.111",
    "port": 9090,
    "Meta": {
        "username": "root666",
        "passwd": "123456666"
            },
    "check": {
        "tcp": "192.168.200.111:9090",
        "interval": "10s"
  }
}
注册
curl --request PUT --data @playload.json http://192.168.200.60:8500/v1/agent/service/register
删除
curl --request PUT http://192.168.200.60:8500/v1/agent/service/deregister/DEV/test
curl --request PUT http://192.168.200.111:8500/v1/agent/service/deregister/openshift.232-node02
# deregister/{ServiceID}
查询所有服务详情
curl http://192.168.200.60:8500/v1/agent/services|python -m json.tool
查询单个服务(精简)
curl http://192.168.200.60:8500/v1/agent/service/dev/redis|python -m json.tool
------
查询所有服务列表(精简)
curl http://192.168.200.60:8500/v1/catalog/services|python -m json.tool
查询指定环境的所有服务(详细)
curl http://192.168.200.60:8500/v1/catalog/service/dev|python -m json.tool
查询指定环境的单个服务(详细)
curl http://192.168.200.60:8500/v1/catalog/service/dev?tag=redis|python -m json.tool
md5-9c3ed5cdea71f904d26915000382105e
创建
curl -H "X-Consul-Token: blizzmi" -X PUT -d 'test' http://192.168.200.60:8500/v1/kv/web/key1
删除
curl -H "X-Consul-Token: blizzmi" --request DELETE http://192.168.200.60:8500/v1/kv/web/key1
级联删除
curl -H "X-Consul-Token: blizzmi" --request DELETE  http://192.168.200.60:8500/v1/kv/web/?recurse=ture
查询
curl -H "X-Consul-Token: blizzmi" http://192.168.200.60:8500/v1/web/key1
curl -H "X-Consul-Token: blizzmi" http://192.168.200.60:8500/v1/kv/hosts?keys=ture|python -m json.tool
curl -H "X-Consul-Token: blizzmi" http://192.168.200.60:8500/v1/kv/hosts?recurse=ture|python -m json.tool
md5-1503e1bee8da1edac9dae6d2957cca9d
key_prefix "" {
  policy = "read"
}
service_prefix "" {
  policy = "read"
}
service "consul" {
  policy = "deny"
}
md5-02e2ed9e015231918cf203653a92d4c2
curl -H 'X-Consul-Token: 523c5f68-fa26-6a29-1575-2dc4604d394c' http://192.168.200.60:8500/v1/catalog/services|python -m json.tool
curl -H 'X-Consul-Token: 523c5f68-fa26-6a29-1575-2dc4604d394c' http://192.168.200.60:8500/v1/agent/service/appdev/mysql-m|python -m json.tool
查询指定环境单个服务的信息:
curl http://192.168.200.60:8500/v1/agent/service/{环境}/{服务}|python -m json.tool
查询所有环境的服务列表
curl http://192.168.200.60:8500/v1/catalog/services|python -m json.tool
© 版权声明
THE END
喜欢就支持一下吧
点赞1 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片