1.下载地址https://www.consul.io/downloads.html
2.将解压后的文件consul 拷贝到/usr/local/bin下sudo cp consul /usr/local/bin(不要放在中文目录下)
3.打开bin文件,执行consul,查看consul命令,如下即表示成功
macyjh:bin Mac$ consul
Usage: consul [--version] [--help] <command> [<args>]
Available commands are:
acl Interact with Consul's ACLs
agent Runs a Consul agent
catalog Interact with the catalog
config Interact with Consul's Centralized Configurations
connect Interact with Consul Connect
debug Records a debugging archive for operators
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.
intention Interact with Connect service intentions
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
login Login to Consul using an auth method
logout Destroy a Consul token created with login
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
services Interact with services
snapshot Saves, restores and inspects snapshots of Consul server state
tls Builtin helpers for creating CAs and certificates
validate Validate config files/directories
version Prints the Consul version
watch Watch for changes in Consul
macyjh:bin Mac$
4启动consul
Consul 在启动后分为两种模式:Server 模式:Client 模式:
macyjh:bin Mac$ consul agent -dev
==> Starting Consul agent...
==> Consul agent running!
Version: 'v1.5.1'
Node ID: '6bbe0946-94de-e6f4-2724-ac933667e38c'
Node name: 'macyjh.local'
Datacenter: 'dc1' (Segment: '<all>')
Server: true (Bootstrap: false)
Client Addr: [127.0.0.1] (HTTP: 8500, HTTPS: -1, gRPC: 8502, DNS: 8600)
Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
Encrypt: Gossip: false, TLS-Outgoing: false, TLS-Incoming: false
==> Log data will now stream in as it occurs:
2019/06/16 16:33:06 [DEBUG] agent: Using random ID "6bbe0946-94de-e6f4-2724-ac933667e38c" as node ID
2019/06/16 16:33:06 [WARN] agent: Node name "macyjh.local" will not be discoverable via DNS due to invalid characters. Valid characters include all alpha-numerics and dashes.
2019/06/16 16:33:06 [DEBUG] tlsutil: Update with version 1
2019/06/16 16:33:06 [DEBUG] tlsutil: OutgoingRPCWrapper with version 1
2019/06/16 16:33:06 [DEBUG] tlsutil: IncomingRPCConfig with version 1
2019/06/16 16:33:06 [DEBUG] tlsutil: OutgoingRPCWrapper with version 1
2019/06/16 16:33:06 [INFO] raft: Initial configuration (index=1): [{Suffrage:Voter ID:6bbe0946-94de-e6f4-2724-ac933667e38c Address:127.0.0.1:8300}]
2019/06/16 16:33:06 [INFO] raft: Node at 127.0.0.1:8300 [Follower] entering Follower state (Leader: "")
2019/06/16 16:33:06 [INFO] serf: EventMemberJoin: macyjh.local.dc1 127.0.0.1
2019/06/16 16:33:06 [INFO] serf: EventMemberJoin: macyjh.local 127.0.0.1
2019/06/16 16:33:06 [INFO] consul: Adding LAN server macyjh.local (Addr: tcp/127.0.0.1:8300) (DC: dc1)
2019/06/16 16:33:06 [DEBUG] agent/proxy: managed Connect proxy manager started
2019/06/16 16:33:06 [INFO] consul: Handled member-join event for server "macyjh.local.dc1" in area "wan"
2019/06/16 16:33:06 [INFO] agent: Started DNS server 127.0.0.1:8600 (tcp)
2019/06/16 16:33:06 [INFO] agent: Started DNS server 127.0.0.1:8600 (udp)
2019/06/16 16:33:06 [INFO] agent: Started HTTP server on 127.0.0.1:8500 (tcp)
2019/06/16 16:33:06 [INFO] agent: Started gRPC server on 127.0.0.1:8502 (tcp)
2019/06/16 16:33:06 [INFO] agent: started state syncer
2019/06/16 16:33:06 [WARN] raft: Heartbeat timeout from "" reached, starting election
2019/06/16 16:33:06 [INFO] raft: Node at 127.0.0.1:8300 [Candidate] entering Candidate state in term 2
2019/06/16 16:33:06 [DEBUG] raft: Votes needed: 1
2019/06/16 16:33:06 [DEBUG] raft: Vote granted from 6bbe0946-94de-e6f4-2724-ac933667e38c in term 2. Tally: 1
2019/06/16 16:33:06 [INFO] raft: Election won. Tally: 1
2019/06/16 16:33:06 [INFO] raft: Node at 127.0.0.1:8300 [Leader] entering Leader state
2019/06/16 16:33:06 [INFO] consul: cluster leadership acquired
2019/06/16 16:33:06 [INFO] consul: New leader elected: macyjh.local
2019/06/16 16:33:06 [INFO] connect: initialized primary datacenter CA with provider "consul"
2019/06/16 16:33:06 [DEBUG] consul: Skipping self join check for "macyjh.local" since the cluster is too small
2019/06/16 16:33:06 [INFO] consul: member 'macyjh.local' joined, marking health alive
2019/06/16 16:33:06 [DEBUG] agent: Skipping remote check "serfHealth" since it is managed automatically
2019/06/16 16:33:06 [INFO] agent: Synced node info
2019/06/16 16:33:06 [DEBUG] agent: Node info in sync
2019/06/16 16:33:07 [DEBUG] agent: Skipping remote check "serfHealth" since it is managed automatically
2019/06/16 16:33:07 [DEBUG] agent: Node info in sync
2019/06/16 16:34:06 [DEBUG] consul: Skipping self join check for "macyjh.local" since the cluster is too small
2019/06/16 16:34:29 [DEBUG] agent: Skipping remote check "serfHealth" since it is managed automatically
2019/06/16 16:34:29 [DEBUG] agent: Node info in sync
2019/06/16 16:35:06 [DEBUG] manager: Rebalanced 1 servers, next active server is macyjh.local.dc1 (Addr: tcp/127.0.0.1:8300) (DC: dc1)
2019/06/16 16:35:06 [DEBUG] consul: Skipping self join check for "macyjh.local" since the cluster is too small
5.停止consul
可以使用Ctrl-C(中断信号)正常停止代理。 中断代理之后,您应该看到它离开集群并关闭。
参考:https://blog.csdn.net/BigBingtang/article/details/83010209