三節點配置
- 下載安裝包
mkdir /data/consul
mkdir /data/consul/data
curl -SLO https://github.com/consul/1.9.5/consul_1.9.5_linux_amd64.zip
unzip consul_1.9.5_linux_amd64.zip
mv consul /data/consul/
- 建立配置檔案
生成叢集金鑰
/data/consul/consul keygen
# XYefgTnef1tB/X6Q3gVOfx2XlTbfbwvNzG0KLQMm1/s=
vim /data/consul/config.json
{
"bootstrap_expect": 3,
"client_addr": "0.0.0.0",
"bind_addr": "{{GetInterfaceIP \"eth0\"}}",
"datacenter": "lmtce",
"data_dir": "/data/consul/data",
"domain": "consul",
"enable_script_checks": true,
"dns_config": {
"enable_truncate": true,
"only_passing": true
},
"enable_syslog": true,
"encrypt": "P+8L7Z3K6ItXsvS9moNWlvnuYuT136tVVInmzsOxEVc=",
"leave_on_terminate": true,
"log_level": "INFO",
"rejoin_after_leave": true,
"server": true,
"start_join": [
"192.168.100.11",
"192.168.100.12",
"192.168.100.13"
],
"ui": true
}
注意修改 start_join
裡面的節點 ip;如果節點有多個網路卡,還要使用 bind_addr
指令將埠監聽到具體的網路卡上。
網路卡名只能使用雙引號引用並轉義,不能使用單引號。
- 建立systemd啟動檔案
vim /usr/lib/systemd/system/consul.service
[Unit]
Description=Consul Startup process
After=network.target
[Service]
User=worker
Type=simple
ExecStart=/data/consul/consul agent -server -config-dir /data/consul
TimeoutStartSec=0
[Install]
WantedBy=default.target
- 啟動服務
注意,由於是叢集節點,當只啟動一個節點時,服務狀態是 error 的,這個不用擔心,等其他兩個節點啟動起來就好了。
chown -R worker. /data
systemctl daemon-reload
systemctl restart consul
三個節點要重複執行上述配置。
單節點配置
{
"bootstrap_expect": 1,
"client_addr": "0.0.0.0",
"bind_addr": "{{GetInterfaceIP \"eth0\"}}",
"datacenter": "sloan",
"data_dir": "/data/consul/data",
"domain": "consul",
"enable_script_checks": true,
"dns_config": {
"enable_truncate": true,
"only_passing": true
},
"enable_syslog": true,
"encrypt": "XYefgTnef1tB/X6Q3gVOfx2XlTbfbwvNzG0KLQMm1/s=",
"leave_on_terminate": true,
"log_level": "INFO",
"rejoin_after_leave": true,
"server": true,
"start_join": [
"192.168.100.11"
],
"ui": true
}
注意 bootstrap_expect
為1 ,並且start_join
只有1個節點。