原 【DB宝45】MySQL高可用之MGR+Consul架构部署
三、搭建Consul Server集群
3.1、申请3台Consul Server主机
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | docker rm -f lhrconsulmgr66 lhrconsulmgr67 lhrconsulmgr68 docker run -d --name lhrconsulmgr66 -h lhrconsulmgr66 \ --net=mhalhr --ip 192.168.68.66 \ -p 8566:8500 \ -v /sys/fs/cgroup:/sys/fs/cgroup \ --privileged=true lhrbest/lhrcentos76:8.0 \ /usr/sbin/init docker run -d --name lhrconsulmgr67 -h lhrconsulmgr67 \ --net=mhalhr --ip 192.168.68.67 \ -p 8567:8500 \ --privileged=true lhrbest/lhrcentos76:8.0 \ /usr/sbin/init docker run -d --name lhrconsulmgr68 -h lhrconsulmgr68 \ --net=mhalhr --ip 192.168.68.68 \ -p 8568:8500 \ --privileged=true lhrbest/lhrcentos76:8.0 \ /usr/sbin/init docker cp consul_1.9.4_linux_amd64.zip lhrconsulmgr66:/ docker cp consul_1.9.4_linux_amd64.zip lhrconsulmgr67:/ docker cp consul_1.9.4_linux_amd64.zip lhrconsulmgr68:/ docker network connect bridge lhrconsulmgr66 docker network connect bridge lhrconsulmgr67 docker network connect bridge lhrconsulmgr68 docker restart lhrconsulmgr66 lhrconsulmgr67 lhrconsulmgr68 |
3.2、安装Consul Server
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | docker exec -it lhrconsulmgr66 bash docker exec -it lhrconsulmgr67 bash docker exec -it lhrconsulmgr68 bash unzip consul_1.9.4_linux_amd64.zip mv consul /usr/local/bin/ mkdir -p /consul/logs/ -- 66节点 启动 nohup consul agent -server -bootstrap-expect 3 -bind=192.168.68.66 -client=0.0.0.0 -data-dir=/consul/data \ -node=n66 -ui >> /consul/logs/consul.log 2>&1 & -- 67节点 启动 nohup consul agent -server -bootstrap-expect 3 -bind=192.168.68.67 -client=0.0.0.0 -data-dir=/consul/data \ -node=n67 -ui >> /consul/logs/consul.log 2>&1 & -- 68节点 启动 nohup consul agent -server -bootstrap-expect 3 -bind=192.168.68.68 -client=0.0.0.0 -data-dir=/consul/data \ -node=n68 -ui >> /consul/logs/consul.log 2>&1 & -- 67和68节点加入集群 consul join 192.168.68.66 -- 查询集群状态 [root@lhrconsulmgr66 /]# consul members Node Address Status Type Build Protocol DC Segment n66 192.168.68.66:8301 alive server 1.9.4 2 dc1 <all> n67 192.168.68.67:8301 alive server 1.9.4 2 dc1 <all> n68 192.168.68.68:8301 alive server 1.9.4 2 dc1 <all> [root@lhrconsulmgr66 /]# consul operator raft list-peers Node ID Address State Voter RaftProtocol n66 719e2a32-5c4b-bd0f-35ef-9ac11a8e79e0 192.168.68.66:8300 leader true 3 n67 f80e2542-3d30-ca5a-af79-08879723c882 192.168.68.67:8300 follower true 3 n68 43520b16-1b65-7d22-4172-6c2822070a44 192.168.68.68:8300 follower true 3 |
为了后续启动方便,我们使用参数文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | -- 66节点,其它节点修改node_name、advertise_addr和bind_addr即可: mkdir -p /etc/consul.d/ pkill -9 consul cat > /etc/consul.d/server.json <<"EOF" { "data_dir": "/consul/data", "datacenter": "dc1", "node_name": "n66", "enable_syslog": true, "log_level": "INFO", "server": true, "advertise_addr":"192.168.68.66", "bootstrap_expect": 3, "bind_addr": "192.168.68.66", "client_addr": "0.0.0.0", "retry_join": ["192.168.68.66","192.168.68.67","192.168.68.68"], "retry_interval": "10s", "rejoin_after_leave": true, "start_join": ["192.168.68.66","192.168.68.67","192.168.68.68"] , "ui": true } EOF nohup consul agent -config-dir=/etc/consul.d > /consul/consul.log & |