• Consul 使用手册(感觉比较全了)


    HTTP API

    consul的主要接口是RESTful HTTP API,该API可以用来增删查改nodes、services、checks、configguration。所有的endpoints主要分为以下类别:

    kv - Key/Value存储
    agent - Agent控制
    catalog - 管理nodes和services
    health - 管理健康监测
    session - Session操作
    acl - ACL创建和管理
    event - 用户Events
    status - Consul系统状态

    下面我们就单独看看每个模块的具体内容。

    agent

    agent endpoints用来和本地agent进行交互,一般用来服务注册和检查注册,支持以下接口

    /v1/agent/checks : 返回本地agent注册的所有检查(包括配置文件和HTTP接口)
    /v1/agent/services : 返回本地agent注册的所有 服务
    /v1/agent/members : 返回agent在集群的gossip pool中看到的成员
    /v1/agent/self : 返回本地agent的配置和成员信息
    /v1/agent/join/<address> : 触发本地agent加入node
    /v1/agent/force-leave/<node>>: 强制删除node
    /v1/agent/check/register : 在本地agent增加一个检查项,使用PUT方法传输一个json格式的数据
    /v1/agent/check/deregister/<checkID> : 注销一个本地agent的检查项
    /v1/agent/check/pass/<checkID> : 设置一个本地检查项的状态为passing
    /v1/agent/check/warn/<checkID> : 设置一个本地检查项的状态为warning
    /v1/agent/check/fail/<checkID> : 设置一个本地检查项的状态为critical
    /v1/agent/service/register : 在本地agent增加一个新的服务项,使用PUT方法传输一个json格式的数据
    /v1/agent/service/deregister/<serviceID> : 注销一个本地agent的服务项

    catalog

    catalog endpoints用来注册/注销nodes、services、checks

    /v1/catalog/register : Registers a new node, service, or check
    /v1/catalog/deregister : Deregisters a node, service, or check
    /v1/catalog/datacenters : Lists known datacenters
    /v1/catalog/nodes : Lists nodes in a given DC
    /v1/catalog/services : Lists services in a given DC
    /v1/catalog/service/<service> : Lists the nodes in a given service
    /v1/catalog/node/<node> : Lists the services provided by a node

    health

    health endpoints用来查询健康状况相关信息,该功能从catalog中单独分离出来

    /v1/healt/node/<node>: 返回node所定义的检查,可用参数?dc=
    /v1/health/checks/<service>: 返回和服务相关联的检查,可用参数?dc=
    /v1/health/service/<service>: 返回给定datacenter中给定node中service
    /v1/health/state/<state>: 返回给定datacenter中指定状态的服务,state可以是"any", "unknown", "passing", "warning", or "critical",可用参数?dc=

    session

    session endpoints用来create、update、destory、query sessions

    /v1/session/create: Creates a new session
    /v1/session/destroy/<session>: Destroys a given session
    /v1/session/info/<session>: Queries a given session
    /v1/session/node/<node>: Lists sessions belonging to a node
    /v1/session/list: Lists all the active sessions

    acl

    acl endpoints用来create、update、destory、query acl

    /v1/acl/create: Creates a new token with policy
    /v1/acl/update: Update the policy of a token
    /v1/acl/destroy/<id>: Destroys a given token
    /v1/acl/info/<id>: Queries the policy of a given token
    /v1/acl/clone/<id>: Creates a new token by cloning an existing token
    /v1/acl/list: Lists all the active tokens

    event

    event endpoints用来fire新的events、查询已有的events

    /v1/event/fire/<name>: 触发一个新的event,用户event需要name和其他可选的参数,使用PUT方法
    /v1/event/list: 返回agent知道的events
    • 1
    • 2

    status

    status endpoints用来或者consul 集群的信息

    /v1/status/leader : 返回当前集群的Raft leader
    /v1/status/peers : 返回当前集群中同事
    • 1
    • 2

    Consul-Template

    在consul-template没出现之前,大家构建服务发现系统,大多采用的是zookeeper、etcd+confd这样类似的系统,之前写过一篇consul+confd的文,讲的是如何动态生成配置文件的,如今consul官方推出了自己的模板系统,就是consul-template,这样的话动态的配置系统可以分化为etcd+confd和consul+consul-template两大阵营。consul是一个和etcd类似但又强于etcd的系统,关于etcd和consul可以翻阅以前的文章,consul-template的定位就和confd差不多一样了,confd的后端可以是etcd或者consul,相信consul搭配consul-template能发挥更大的效果。consul-template提供了一个便捷的方式从consul中获取存储的值,consul-template守护进程会查询consul实例,来更新系统上指定的任何模板,当更新完成后,模板可以选择运行一些任意的命令。

        consul template的使用场景:consul template可以查询consul中的服务目录、key、key-values等。这种强大的抽象功能和查询语言模板可以使consul template特别适合动态的创建配置文件。例如:创建apache/nginx proxy balancers、haproxy backends、varnish servers、application configurations。
    • 1

    consul template的特性:

        quiescence:consul template内制静止平衡功能,可以智能的发现consul实例中的更改信息。这个功能可以防止频繁的更新模板而引起系统的波动。
        dry mode:不确定当前架构的状态?担心模板的变化会破坏子系统?无须担心,因为consul template还有-dry模式。在dry模式,consul template会将结果呈现在STDOUT,所以操作员可以检查输出是否正常,以决定更换模板是否安全
        CLI and Config:如果你喜欢在命令行上指定一切,consul template都可以hold住。随着内置HCL的支持,consul template接收一个配置文件,命令行参数,或者两者的混合。通过这种方式你可以继续使用你现在已有的配置管理工具和consul template来配合。
        verbose debugging:即使每件事你都做的近乎完美,但是有时候还是会有失败发生。consul template可以提供更详细的debug日志信息。
  • 相关阅读:
    微信机器人11python自制微信机器人,定时发送天气预报
    微信机器人10Python创建微信机器人
    微信小程序如何调用后台service(图文教程)
    python爬虫:使用Selenium模拟浏览器行为
    Python模拟浏览器发送http请求
    TextClip的list和search方法报错:UnicodeDecodeError: utf-8 codec canot decode byte 0xb7 in position 8
    TextClip构造方法报OSError:MoviePy creation of None failed because of the following [WinError 2]系统找不到指定的文件
    moviepy音视频剪辑:视频基类VideoClip子类DataVideoClip、UpdatedVideoClip、ImageClip、ColorClip、TextClip类详解
    moviepy音视频剪辑:视频基类VideoClip子类DataVideoClip、UpdatedVideoClip、ImageClip、ColorClip、TextClip及使用案例
    moviepy音视频剪辑:mask clip遮罩剪辑、遮片、蒙版的作用以及其包含的构成内容
  • 原文地址:https://www.cnblogs.com/Qing-840/p/10144184.html
Copyright © 2020-2023  润新知