Consul 服务注册中心。

目录

  1. 安装
    1. 配置
    2. Systemd 配置

安装

1
2
3
wget https://releases.hashicorp.com/consul/1.2.2/consul_1.2.2_linux_amd64.zip
unzip consul_1.2.2_linux_amd64.zip
chmod +x consul

配置

编辑web.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"datacenter": "dc",
"node_name": "node0",
"server": true,
"client_addr": "0.0.0.0",
"addresses": {
"http": "0.0.0.0"
},
"ports": {
"dns": 8600,
"http": 8500,
"https": -1,
"serf_lan": 8301,
"serf_wan": 8302,
"server": 8300
},
"bind_addr": "0.0.0.0",
"log_level": "INFO",
"retry_interval": "30s",
"ui": true,
"disable_update_check": true,
"bootstrap_expect": 3
}

Systemd 配置

1
2
3
4
mv consul /usr/local/bin
mkdir /etc/consul.d
mkdir /opt/consul
mv web.json /etc/consul.d/web.json

编辑/etc/systemd/system/consul.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=Consul Agent
Requires=network-online.target
After=network-online.target

[Service]
Restart=on-failure
PIDFile=/run/consul.pid
ExecStart=/usr/local/bin/consul agent -data-dir=/opt/consul -config-dir=/etc/consul.d -pid-file=/run/consul.pid
ExecStop=/bin/kill -s TERM $MAINPID
KillSignal=SIGINT
TimeoutStopSec=10

[Install]
WantedBy=multi-user.target