$ consul -h 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
Starts the Consul agent and runs until an interrupt is received. The agent represents a single node in a cluster.
HTTP API Options
-datacenter=<value> Datacenter of the agent.
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.
-config-format=<value> Config files are in this format irrespective of their extension. Must be 'hcl' or 'json'
-data-dir=<value> Path to a data directory to store agent state.
-dev Starts the agent in development mode.
-disable-host-node-id Setting this to true will prevent Consul from using information from the host to generate a node ID, and will cause Consul to generate a random node ID instead.
-disable-keyring-file Disables the backing up of the keyring to a file.
-dns-port=<value> DNS port to use.
-domain=<value> Domain to use for DNS interface.
-enable-script-checks Enables health check scripts.
-encrypt=<value> Provides the gossip encryption key.
-hcl=<value> hcl config fragment. Can be specified multiple times.
-http-port=<value> Sets the HTTP API port to listen on.
-join=<value> Address of an agent to join at start time. Can be specified multiple times.
-join-wan=<value> Address of an agent to join -wan at start time. Can be specified multiple times.
-log-level=<value> Log level of the agent.
-node=<value> Name of this node. Must be unique in the cluster.
-node-id=<value> A unique ID for this node across space and time. Defaults to a randomly-generated ID that persists in the data-dir.
-node-meta=<key:value> An arbitrary metadata key/value pair for this node, of the format `key:value`. Can be specified multiple times.
-non-voting-server (Enterprise-only) This flag is used to make the server not participate in the Raft quorum, and have it only receive the data replication stream. This can be used to add read scalability to a cluster in cases where a high volume of reads to servers are needed.
-pid-file=<value> Path to file to store agent PID.
-protocol=<value> Sets the protocol version. Defaults to latest.
-raft-protocol=<value> Sets the Raft protocol version. Defaults to latest.
-recursor=<value> Address of an upstream DNS server. Can be specified multiple times.
-rejoin Ignores a previous leave and attempts to rejoin the cluster.
-retry-interval=<value> Time to wait between join attempts.
-retry-interval-wan=<value> Time to wait between join -wan attempts.
-retry-join=<value> Address of an agent to join at start time with retries enabled. Can be specified multiple times.
-retry-join-wan=<value> Address of an agent to join -wan at start time with retries enabled. Can be specified multiple times.
-retry-max=<value> Maximum number of join attempts. Defaults to 0, which will retry indefinitely.
-retry-max-wan=<value> Maximum number of join -wan attempts. Defaults to 0, which will retry indefinitely.
-segment=<value> (Enterprise-only) Sets the network segment to join.
-serf-lan-bind=<value> Address to bind Serf LAN listeners to.
-serf-wan-bind=<value> Address to bind Serf WAN listeners to.
-server Switches agent to server mode.
-syslog Enables logging to syslog.
-ui Enables the built-in static web UI server.
-ui-dir=<value> Path to directory containing the web UI resources.
2018/02/03 16:34:56 [INFO] serf: EventMemberJoin: zhangxiaodeMacBook-Pro.local 192.168.31.222 2018/02/03 16:34:56 [WARN] serf: Failed to re-join any previously known node 2018/02/03 16:34:56 [INFO] agent: Started DNS server 127.0.0.1:8600 (tcp) 2018/02/03 16:34:56 [INFO] agent: Started DNS server 127.0.0.1:8600 (udp) 2018/02/03 16:34:56 [INFO] agent: Started HTTP server on 127.0.0.1:8500 (tcp) 2018/02/03 16:34:56 [INFO] agent: started state syncer 2018/02/03 16:34:56 [WARN] manager: No servers available 2018/02/03 16:34:56 [ERR] agent: failed to sync remote state: No known Consul servers 2018/02/03 16:34:57 [WARN] manager: No servers available 2018/02/03 16:34:57 [ERR] http: Request GET /v1/kv/config/account-service/?recurse&wait=55s&index=1, error: No known Consul servers from=127.0.0.1:54630
启动是启动了,但是尴尬的是报Err了。 对了,第一篇文章中有说道:Agent有Client 和 Server 两种模式 看来默认启动的方式是Client,所有一直报错没有可用服务器
2018/02/03 16:45:43 [INFO] raft: Initial configuration (index=0): [] 2018/02/03 16:45:43 [INFO] raft: Node at 192.168.31.222:8300 [Follower] entering Follower state (Leader: "") 2018/02/03 16:45:43 [INFO] serf: EventMemberJoin: zhangxiaodeMacBook-Pro.local.dc1 192.168.31.222 2018/02/03 16:45:43 [WARN] serf: Failed to re-join any previously known node 2018/02/03 16:45:43 [INFO] serf: EventMemberJoin: zhangxiaodeMacBook-Pro.local 192.168.31.222 2018/02/03 16:45:43 [INFO] consul: Adding LAN server zhangxiaodeMacBook-Pro.local (Addr: tcp/192.168.31.222:8300) (DC: dc1) 2018/02/03 16:45:43 [INFO] consul: Handled member-join event for server "zhangxiaodeMacBook-Pro.local.dc1" in area "wan" 2018/02/03 16:45:43 [INFO] agent: Started DNS server 127.0.0.1:8600 (udp) 2018/02/03 16:45:43 [INFO] agent: Started DNS server 127.0.0.1:8600 (tcp) 2018/02/03 16:45:43 [INFO] agent: Started HTTP server on 127.0.0.1:8500 (tcp) 2018/02/03 16:45:43 [INFO] agent: started state syncer 2018/02/03 16:45:49 [WARN] raft: no known peers, aborting election 2018/02/03 16:45:50 [ERR] agent: failed to sync remote state: No cluster leader
我去,有报错:failed to sync remote state: No cluster leader
-bootstrap - This flag is used to control if a server is in “bootstrap” mode. It is important that no more than one server per datacenter be running in this mode. Technically, a server in bootstrap mode is allowed to self-elect as the Raft leader. It is important that only a single node is in this mode; otherwise, consistency cannot be guaranteed as multiple nodes are able to self-elect. It is not recommended to use this flag after a cluster has been bootstrapped.