1、在线下载
指定版本的Consul压缩包
具体版本可以在这里找到,Consul Install
可以使用wget等命令进行下载
2、解压
使用unzip命令进行解压,并拷贝至/usr/local/bin目录下
unzip consul-1.xxx.zip
mv consul /usr/local/bin
3、配置Consul
3.1、添加用户和组
groupadd consul
useradd -r -d /var/consul -m -g consul -s /bin/bash consul
3.2、修改Consul二进制文件的权限
chown root:consul /usr/local/bin/consul
chmod 755 /usr/local/bin/consul
// 添加访问日志的权限
usermod -a -G systemd-journal consul
3.3、创建/opt/consul/data文件夹并分配权限
mkdir -p /opt/consul/data
chown consul -R /opt/consul/data
3.4、创建配置文件
创建文件/etc/consul.d/consul.hcl,在文件中写入:
{
"datacenter": "dc1",
"data_dir": "/opt/consul/data",
"log_level": "INFO",
"node_name": "node1",
"server": true,
"bootstrap_expect": 1,
"ui_config": {
"enabled": true
},
"bind_addr": "10.1.4.8",
"client_addr": "0.0.0.0",
"bootstrap": false
}
4、配置服务并启动
创建文件/etc/systemd/system/consul.service
在文件中写入:
[Unit]
Description=Consul Agent
After=network.target
[Service]
User=consul
Group=consul
ExecStart=/usr/local/bin/consul agent -config-dir=/etc/consul.d
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动
systemctl start consul.service