cd /tmp
wget https://releases.hashicorp.com/consul/1.6.1/consul_1.6.1_linux_amd64.zip
#创建安装和数据目录
mkdir /usr/local/consul/data -p
unzip /tmp/consul_1.6.1_linux_amd64.zip -d /usr/local/consul
chmod 777 /usr/local/consul/consul
echo "export PATH=/usr/local/consul:$PATH">>/etc/profile
source /etc/profile
consul -h
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
#node1
consul agent -server -ui -bootstrap-expect=3 -data-dir=/usr/local/consul/data -node=node1 -client=0.0.0.0 -bind=192.168.10.251 -datacenter=YL
#node2
consul agent -server -ui -data-dir=/usr/local/consul/data -node=node2 -client=0.0.0.0 -bind=192.168.10.252 -datacenter=YL -join 192.168.10.251
#node3
consul agent -server -ui -data-dir=/usr/local/consul/data -node=node3 -client=0.0.0.0 -bind=192.168.10.253 -datacenter=YL -join 192.168.10.251
-server 以服务端模式启动
-ui 开启webUI界面
-bootstrap-expect=3 节点数为三个
-data-dir 数据存放目录
-node 节点名称
-client 客户端IP
-bind 服务端IP
-datacenter 数据中心名称
-join 加入集群
#请求URL
http://192.168.10.251:8500/ui/
#红星表示当前节点是主节点
#关闭节点
consul leave -http-addr=192.168.10.252:8500
#查看集群
consul operator raft list-peers
consul members
#备份 还原
consul snapshot save --http-addr=http://192.168.10.251:8500 /tmp/xx.snap
consul snapshot restore xx.snap
#查看配置
[root@node1 ~]# consul members
Node Address Status Type Build Protocol DC Segment
node1 192.168.10.251:8301 alive server 1.6.1 2 yl <all>
node3 192.168.10.253:8301 alive server 1.6.1 2 yl <all>
[root@node1 ~]# consul info | grep leader
leader = true
leader_addr = 192.168.10.251:8300
#集群server成员
curl 192.168.10.251:8500/v1/status/peers
#集群Raft leader
curl 192.168.10.251:8500/v1/status/leader
#注册的所有服务
curl 192.168.10.251:8500/v1/catalog/servers
#服务信息
curl 192.168.10.251:8500/v1/catalog/servers/nginx
#集群节点详细信息
curl 192.168.10.251:8500/v1/catalog/nodes