192.168.245.227 iot-node1 # server节点
192.168.245.228 iot-node2 # server节点
192.168.245.229 iot-node3 # server节点
sudo yum install -y zip unzip
sudo systemctl stop firewalld
https://releases.hashicorp.com/consul/1.2.2/
consul_1.2.2_linux_amd64.zip
1)进入到consul_1.2.2_linux_amd64.zip所在目录
执行解压命令:
sudo unzip consul_1.2.2_linux_amd64.zip
2)移动consul到/usr/bin/,并授予运行权限
sudo mv consul /usr/bin/
sudo chmod uog+x /usr/bin/consul
3)创建文件夹并授权
sudo mkdir -p /opt/consul/data
sudo mkdir -p /opt/consul/conf
sudo chmod uog+rw /opt/consul/data
4)编辑文件/etc/default/consul
sudo vi /etc/default/consul
/etc/default/consul内容:
CONSUL_FLAGS="-ui -disable-host-node-id -config-file
/opt/consul/conf/server.json"
1)配置consul-node1
sudo vi /opt/consul/conf/server.json
/opt/consul/conf/server.json内容:
{
“datacenter”: “dc1”,
“data_dir”: “/opt/consul/data”,
“log_level”: “INFO”,
“node_name”: “consul-node1”,
“server”: true,
“bootstrap_expect”: 3,
“bind_addr”: “192.168.245.227”,
“client_addr”: “192.168.245.227”,
“retry_join”: [“192.168.245.227”,
“192.168.245.228”,
“192.168.245.229”],
“retry_interval”: “30s”,
“enable_debug”: false,
“rejoin_after_leave”: true,
“start_join”: [“192.168.245.227”,
“192.168.245.228”,
“192.168.245.229”],
“enable_syslog”: true,
“syslog_facility”: “local0”
}
2)配置consul-node2
sudo vi /opt/consul/conf/server.json
/opt/consul/conf/server.json内容:
{
“datacenter”: “dc1”,
“data_dir”: “/opt/consul/data”,
“log_level”: “INFO”,
“node_name”: “consul-node2”,
“server”: true,
“bootstrap_expect”: 3,
“bind_addr”: “192.168.245.228”,
“client_addr”: “192.168.245.228”,
“retry_join”: [“192.168.245.227”,
“192.168.245.228”,
“192.168.245.229”],
“retry_interval”: “30s”,
“enable_debug”: false,
“rejoin_after_leave”: true,
“start_join”: [“192.168.245.227”,
“192.168.245.228”,
“192.168.245.229”],
“enable_syslog”: true,
“syslog_facility”: “local0”
}
3)配置consul-node3
sudo vi /opt/consul/conf/server.json
/opt/consul/conf/server.json内容:
{
“datacenter”: “dc1”,
“data_dir”: “/opt/consul/data”,
“log_level”: “INFO”,
“node_name”: “consul-node3”,
“server”: true,
“bootstrap_expect”: 3,
“bind_addr”: “192.168.245.229”,
“client_addr”: “192.168.245.229”,
“retry_join”: [“192.168.245.227”,
“192.168.245.228”,
“192.168.245.229”],
“retry_interval”: “30s”,
“enable_debug”: false,
“rejoin_after_leave”: true,
“start_join”: [“192.168.245.227”,
“192.168.245.228”,
“192.168.245.229”],
“enable_syslog”: true,
“syslog_facility”: “local0”
}
1)创建日志存放目录,并授权
sudo mkdir /var/log/consul
sudo chmod uog+rwx /var/log/consul
2)修改rsyslog默认配置文件
sudo vi /etc/rsyslog.d/50-default.conf
/etc/rsyslog.d/50-default.conf添加内容:
consul.* /var/log/consul/consul.log
3)创建日志轮循规则
sudo tee /etc/logrotate.d/consul <<-‘EOF’
/var/log/consul/*log {
missingok
compress
notifempty
daily
rotate 5
create 0600 root root
}
EOF
4)重启rsyslog
sudo systemctl daemon-reload
sudo systemctl restart rsyslog
sudo vi /usr/lib/systemd/system/consul.service
/usr/lib/systemd/system/consul.service内容:
[Unit]
Description=Consul service discovery agent
Requires=network-online.target
After=network-online.target
[Service]
User=root
Type=notify
Environment=GOMAXPROCS=2
EnvironmentFile=-/etc/default/consul
ExecStart=/usr/bin/consul agent $CONSUL_FLAGS
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGTERM
Restart=on-failure
TimeoutStopSec=5
[Install]
WantedBy=multi-user.target
sudo systemctl start consul
sudo systemctl stop consul
sudo systemctl status consul
sudo systemctl enable consul