2020-12-04


       **

mysql基于keepalived双主高可用*

环境:两台Linux服务器
mysql基于keepalived双主高可用和

在双主的基础上
主A配置
[root@localhost ~]# yum -y install keepalived
[root@localhost ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
router_id LVS_MASTER-A
}

vrrp_script mysql {
script “/opt/ mysql.sh”
interval 2
weight -5
fall 2
rise 1
}

vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 100
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
mysql
}
virtual_ipaddress {
/ 192.168.1.254
}
}

脚本
[root@localhost ~]# cat /opt/mysql.sh
#!/bin/bash
counter= ( n e t s t a t − n a ∣ g r e p " L I S T E N " ∣ g r e p " 3306 " ∣ w c − l ) i f [ " (netstat -na|grep "LISTEN"|grep "3306"|wc -l) if [ " (netstatnagrep"LISTEN"grep"3306"wcl)if["{counter}" -eq 0 ]; then
systemctl stop keepalived
fi
[root@localhost ~]# chmod +x /opt/mysql.sh
[root@localhost ~]# systemctl start keepalived
[root@localhost ~]# ip a | grep ens32
[root@localhost ~]# mysql
MariaDB [(none)]> grant all on . to ‘root’@‘192.168.1.%’ identified by ‘123456’;
MariaDB [(none)]> flush privileges;

主B配置
[root@localhost ~]# yum -y install keepalived
[root@localhost ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
router_id LVS_MASTER-B
}

vrrp_script mysql {
script “/opt/mysql.sh”
interval 2
weight -5
fall 2
rise 1
}

vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
mysql
}
virtual_ipaddress {
192.168.1.254
}
}

脚本
[root@localhost ~]# cat /opt/mysql.sh
#!/bin/bash
counter= ( n e t s t a t − n a ∣ g r e p " L I S T E N " ∣ g r e p " 3306 " ∣ w c − l ) i f [ " (netstat -na|grep "LISTEN"|grep "3306"|wc -l) if [ " (netstatnagrep"LISTEN"grep"3306"wcl)if["{counter}" -eq 0 ]; then
systemctl stop keepalived
fi
[root@localhost ~]# chmod +x /opt/mysql.sh
[root@localhost ~]# systemctl start keepalived
[root@localhost ~]# ip a | grep ens32
[root@localhost ~]# mysql
MariaDB [(none)]> grant all on . to ‘root’@‘192.168.1.%’ identified by ‘123456’;
MariaDB [(none)]> flush privileges;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值