./consul agent -server -data-dir=/tmp/consul -node=agent-one -bind=192.168.2.101 -client=0.0.0.0 -enable-script-checks=true -ui -config-dir=/etc/consul.d
./consul agent -server -data-dir=/tmp/consul -node=agent-two -bind=192.168.2.102 -client=0.0.0.0 -enable-script-checks=true -ui -config-dir=/etc/consul.d
./consul agent -server -data-dir=/tmp/consul -node=agent-three -bind=192.168.2.103 -client=0.0.0.0 -enable-script-checks=true -ui -config-dir=/etc/consul.d
基本配置
-
/etc/consul.d/config.json
{
"bootstrap_expect": 3,
"encrypt": "qV5WVLHhFnwEle8l/Edi/Q==",
"data_dir": "/home/work/consul/data",
"log_level": "INFO",
"node_name": "dev-192_168_2_101",
"bind_addr": "192.168.2.101",
"client_addr": "0.0.0.0",
"ui": true,
"server": true,
"enable_script_checks": true,
"addresses": {
"https": "0.0.0.0",
"dns": "0.0.0.0"
}
}
- 启动
./consul agent -config-dir=/etc/consul.d
查看leader/follower情况
./consul operator raft list-peers
结果:
Node ID Address State Voter RaftProtocol
dev-192_168_2_101 faa14a6c-16cb-2e97-c383-dfbe1da73d0a 192.168.2.101:8300 leader true 3
dev-192_168_2_102 2cd9cdf9-cbfa-1794-ed3e-83d9813a1bed 192.168.2.102:8300 follower true 3
dev-192_168_2_103 b4517e53-0b41-72aa-f99f-63fc7723ac57 192.168.2.103:8300 follower true 3