consul1.6实现Mysql-Gtid主从读写分离-03
规划
Mysql Gtid主从配置
https://blog.51cto.com/9025736/2500516
consul集群搭建
https://blog.51cto.com/9025736/2500976
创建mysql用户并授权(mysql服务器需要授权)
MySQL [(none)]> grant all on *.* to ‘han‘@‘%‘ identified by ‘hanye131‘; MySQL [(none)]> flush privileges;
配置consul (consul client端 server3 和server4)
[ consul.d]# cd /etc/consul.d [ consul.d]# cat mysql-write.json { "services": [ { "name": "mysql-master", "tags": [ "mysql-179" ], "address": "192.168.31.179", "port": 3306, "checks": [ { "args": ["/usr/bin/bash","/data/mysql_master.sh"], "interval": "10s", "timeout": "1s" } ] } ] } [ consul.d]# cat mysql-readonly.json { "services": [ { "name": "mysql-slave", "tags": [ "mysql-180" ], "address": "192.168.31.180", "port": 3306, "checks": [ { "args": ["/usr/bin/bash","/data/mysql_slave.sh"], "interval": "10s", "timeout": "1s" } ] } ] } [ consul.d]# cat /data/mysql_master.sh #!/bin/bash mysql -uhan -phanye131 -h 192.168.31.179 -e "select 1;" if [ $? -eq 0 ]; then exit 0 else exit 2 fi [ consul.d]# cat /data/mysql_slave.sh #!/bin/bash mysql -uhan -phanye131 -h 192.168.31.180 -e "select 1;" if [ $? -eq 0 ]; then exit 0 else exit 2 fi [ consul.d]# scp /data/mysql_*.sh server3:/data/ [ consul.d]# scp /etc/consul.d/mysql-* server3:/etc/consul.d/
重载consul(server3和server4)
consul reload
测试检测
停止server3 consul
[ consul.d]# dig mysql-master.service.consul
[ consul.d]# dig mysql-slave.service.consul
正常登录访问
相关推荐
emmm00 2020-11-17
暗夜之城 2020-11-11
疯狂老司机 2020-09-08
要啥自行车一把梭 2020-09-10
CoderToy 2020-11-16
王艺强 2020-11-17
ribavnu 2020-11-16
bianruifeng 2020-11-16
wangshuangbao 2020-11-13
苏康申 2020-11-13
vivenwan 2020-11-13
moyekongling 2020-11-13
云中舞步 2020-11-12
要啥自行车一把梭 2020-11-12
aydh 2020-11-12
kuwoyinlehe 2020-11-12
minerk 2020-11-12
vitasfly 2020-11-12