consul集群部署三server一client

发布于:2024-03-29 ⋅ 阅读:(25) ⋅ 点赞:(0)

环境:
consul:consul_1.16.2_linux_amd64.zip centos7.9
server:192.168.50.154 192.168.50.155 192.168.50.156
client:192.168.70.64

安装目录:

[root@rabbit4-64 consul]# pwd
/app/consul
[root@rabbit4-64 consul]# ls
consul  consul_1.16.2_linux_amd64.zip  consul.json  data
[root@rabbit4-64 consul]# 

192.168.70.64 client

[root@rabbit4-64 consul]# cat consul.json 
{
    "datacenter": "ybjdc1",
    "data_dir": "/app/consul/data",
    "log_level": "INFO",
    "node_name": "",
    "server": false,
    "ui": true,
    "bootstrap_expect": 0,
    "bind_addr": "192.168.70.64",
    "client_addr": "192.168.70.64",
    "retry_join": ["192.168.50.154","192.168.50.155","192.168.50.156"],
    "retry_interval": "3s",
    "raft_protocol": 3,
    "enable_debug": false,
    "rejoin_after_leave": true,
    "enable_syslog": false
}

192.168.50.154 server

[root@first-1 consul]# cat consul.json 
{
    "datacenter": "ybjdc1",
    "data_dir": "/app/consul/data",
    "log_level": "INFO",
    "node_name": "",
    "server": true,
    "ui": true,
    "bootstrap_expect": 2,
    "bind_addr": "192.168.50.154",
    "client_addr": "192.168.50.154",
    "advertise_addr": "192.168.50.154",
    "retry_join": ["192.168.50.155","192.168.50.156"],
    "retry_interval": "3s",
    "raft_protocol": 3,
    "enable_debug": false,
    "rejoin_after_leave": true,
    "enable_syslog": false
}

192.168.50.155 server

[root@second-2 consul]# cat consul.json 
{
    "datacenter": "ybjdc1",
    "data_dir": "/app/consul/data",
    "log_level": "INFO",
    "node_name": "",
    "server": true,
    "ui": true,
    "bootstrap_expect": 2,
    "bind_addr": "192.168.50.155",
    "client_addr": "192.168.50.155",
    "advertise_addr": "192.168.50.155",
    "retry_join": ["192.168.50.154","192.168.50.156"],
    "retry_interval": "3s",
    "raft_protocol": 3,
    "enable_debug": false,
    "rejoin_after_leave": true,
    "enable_syslog": false
}

192.168.50.156 server

[root@three-3 consul]# cat consul.json 
{
    "datacenter": "ybjdc1",
    "data_dir": "/app/consul/data",
    "log_level": "INFO",
    "node_name": "",
    "server": true,
    "ui": true,
    "bootstrap_expect": 2,
    "bind_addr": "192.168.50.156",
    "client_addr": "192.168.50.156",
    "advertise_addr": "192.168.50.156",
    "retry_join": ["192.168.50.154","192.168.50.155"],
    "retry_interval": "3s",
    "raft_protocol": 3,
    "enable_debug": false,
    "rejoin_after_leave": true,
    "enable_syslog": false
}

做成服务:

[root@rabbit4-64 consul]# cat /etc/systemd/system/consul.service 
[Unit]
Description=Consul agent server
Documentation=https://www.consul.io/
Requires=network-online.target
After=network-online.target
[Service]
EnvironmentFile=-/etc/sysconfig/consul
Environment=GOMAXPROCS=4
Restart=on-failure
#User=consul
LimitNOFILE=65536
ExecStart=/app/consul/consul agent -config-file /app/consul/consul.json
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
[Install]
WantedBy=multi-user.target

访问测试:http://192.168.50.154:8500/ui/ybjdc1/services/consul/instances
在这里插入图片描述

启动注意点:
可以先使用/app/consul/consul agent -config-file /app/consul/consul.json命令启动,会出现以下错误,但是当全部启动后,就没有出现connect: connection refused的情况了

2024-03-26T11:26:03.758+0800 [ERROR] agent.server.raft: failed to appendEntries to: peer="{Voter 31e197d0-480a-018f-392c-9a81fce11f98 192.168.50.155:8300}" error=EOF
2024-03-26T11:26:03.821+0800 [ERROR] agent.server.raft: failed to appendEntries to: peer="{Voter 31e197d0-480a-018f-392c-9a81fce11f98 192.168.50.155:8300}" error="dial tcp 192.168.50.154:0->192.168.50.155:8300: connect: connection refused"
2024-03-26T11:26:03.888+0800 [ERROR] agent.server.raft: failed to appendEntries to: peer="{Voter 31e197d0-480a-018f-392c-9a81fce11f98 192.168.50.155:8300}" error="dial tcp 192.168.50.154:0->192.168.50.155:8300: connect: connection refused"
本文含有隐藏内容,请 开通VIP 后查看