【MySQL】通过signal18 replication manage实现数据库高可用集群

[root@wallet03 ~]# vim /etc/yum.repos.d/signal18.repo
[signal18]
name=Signal18 repositories
baseurl=http://repo.signal18.io/centos/2.1/$releasever/$basearch/
gpgcheck=0
enabled=1

[root@wallet03 ~]# yum install -y replication-manager-osc

[root@wallet03 ~]# vim /etc/replication-manager/cluster.d/cluster1.toml 
db-servers-hosts = "192.168.40.201:3306,192.168.40.202:3306"
db-servers-prefered-master = "192.168.40.201:3306"
db-servers-credential = "root:abcd.1234"
db-servers-connect-timeout = 2
replication-credential = "repl:repl"

failover-mode = "automatic"
failover-pre-script = "/usr/local/bin/vip-down.sh" #在failover之前执行的脚本,删除vip
failover-post-script = "/usr/local/bin/vip-up.sh" #在failover之后执行的脚本,增加vip

failover-falsepositive-ping-counter = 5 ##在N次检测失败后执行failover

failover-limit = 0  ##如果已经执行N次failover则取消failover

failover-time-limit = 0 ##如果在N秒内执行过failover则取消failover

failover-max-slave-delay = 30 #当复制延迟大于N秒则取消failover

[root@wallet03 ~]# vim /usr/local/bin/vip-down.sh
#!/bin/bash
orig_master=$1
new_master=$2
old_port=$3
new_port=$4
  
interface=ens192
vip=192.168.40.100
ssh_user='root'
ssh_options=''
ssh=$(which ssh)
ip2util=$(which ip)

cmd_vip_del="sudo -n $ip2util address del ${vip}/32 dev ${interface}"
cmd_vip_chk="$ip2util address show dev ${interface} to ${vip%/*}/32"

$ssh ${ssh_options} -tt ${ssh_user}@${orig_master} \
"[ -n \"\$(${cmd_vip_chk})\" ] && ${cmd_vip_del} && || [ -z \"\$(${cmd_vip_chk})\" ]"

[root@wallet03 ~]# vim /usr/local/bin/vip-up.sh 
#!/bin/bash
orig_master=$1
new_master=$2
old_port=$3
new_port=$4

interface=ens192
vip=192.168.40.100
ssh_user='root'
ssh_options=''
ssh=$(which ssh)
arping=$(which arping)
ip2util=$(which ip)

cmd_vip_add="$ip2util address add ${vip} dev ${interface}"
cmd_vip_chk="$ip2util address show dev ${interface} to ${vip%/*}/32"
cmd_arp_fix="$arping -c 1 -I ${interface} ${vip%/*}"

cmd_local_arp_fix=`ip neigh flush dev ${interface}`

$ssh ${ssh_options} -tt ${ssh_user}@${new_master} \
"[ -z \"\$(${cmd_vip_chk})\" ] && ${cmd_vip_add} && ${cmd_arp_fix} || [ -n \"\$(${cmd_vip_chk})\" ]"

[root@wallet03 ~]# systemctl start replication-manager

上一篇:安装Jenkins报错 SSLHandshakeException


下一篇:Unity为Git项目部署Jenkins