三节点配置

  • 下载安装包
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个节点。

版权声明:本文为valiantjiang原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/valiantjiang/p/15004565.html