Consul CLI 入门
in Tutorial with 0 comment
Consul CLI 入门
in Tutorial with 0 comment

安装 consul cli

这里只在 macOS 上安装,需要先提前安装 homebrew,然后执行下面的命令:

brew instal consul

检查是否安装成功

consul --version 
// 返回
Consul v1.0.0
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)

使用 consul cli

Consul可以被命令行工具(CLI)非常容易的控制。此时Consul只是一个单一的命令行应用程序:consul。这个应用程序接收一些子命令,如“agent”或者“members”。完整的子命令列表请看左侧导航。

Consul CLI是一个易用的命令行应用程序。在错误情况下,将返回一个非零的退出状态码。它还响应你最可能期望的 -h 和 –help 。而且一些命令还接受“-”作为一个参数,来让Consul读取标准输入。

任何时候,要浏览所有可用的命令,只要运行consul且不带任何参数:

consul
Usage: consul [--version] [--help] <command> [<args>]

Available commands are:
    agent          Runs a Consul agent
    catalog        Interact with the catalog
    event          Fire a new event
    exec           Executes a command on Consul nodes
    force-leave    Forces a member of the cluster to enter the "left" state
    info           Provides debugging information for operators.
    join           Tell Consul agent to join cluster
    keygen         Generates a new encryption key
    keyring        Manages gossip layer encryption keys
    kv             Interact with the key-value store
    leave          Gracefully leaves the Consul cluster and shuts down
    lock           Execute a command holding a lock
    maint          Controls node or service maintenance mode
    members        Lists the members of a Consul cluster
    monitor        Stream logs from a Consul agent
    operator       Provides cluster-level tools for Consul operators
    reload         Triggers the agent to reload configuration files
    rtt            Estimates network round trip time between nodes
    snapshot       Saves, restores and inspects snapshots of Consul server state
    validate       Validate config files/directories
    version        Prints the Consul version
    watch          Watch for changes in Consul

要获取任何指定命令的帮助,将 -h 参数传递给相关的子命令。例如,要看 agent 子命令的帮助:

consul agent -h
==> Usage: consul agent [options]

  Starts the Consul agent and runs until an interrupt is received. The
  agent represents a single node in a cluster.

 Command Options

  -advertise=<value>
     Sets the advertise address to use.

  -advertise-wan=<value>
     Sets address to advertise on WAN instead of -advertise address.

  -bind=<value>
     Sets the bind address for cluster communication.

  -bootstrap
     Sets server to bootstrap mode.

  -bootstrap-expect=<value>
     Sets server to expect bootstrap mode.

  -client=<value>
     Sets the address to bind for client access. This includes RPC, DNS,
     HTTP and HTTPS (if configured).

  -config-dir=<value>
     Path to a directory to read configuration files from. This
     will read every file ending in '.json' as configuration in this
     directory in alphabetical order. Can be specified multiple times.

  -config-file=<value>
     Path to a JSON file to read configuration from. Can be specified
     multiple times.

...

  -ui-dir=<value>
     Path to directory containing the web UI resources.

收官

Responses