MySQL+Keepalived实现主主高可用方案
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了MySQL+Keepalived实现主主高可用方案,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4359字,纯文字阅读大概需要7分钟。
内容图文
![MySQL+Keepalived实现主主高可用方案](/upload/InfoBanner/zyjiaocheng/508/ff9a628ed5504ec7bb569c7894b535e1.jpg)
master配置
[root@master ~]# yum -y install keepalived
[root@master ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_MASTER-A
}
vrry_script mysql {
script "/opt/mysql.sh"
interval 2
weight -5
fall 2
rise 1
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
mysql
}
virtual_ipaddress {
192.168.200.210
}
}
}
[root@master ~]# vim /opt/mysql.sh
#!/bin/bash
counter=$(netstat -na |grep "LISTEN" |grep "3306" |wc -l)
if [ "${counter}" -eq 0 ]
then
systemctl stop keepalived
fi
~
[root@master ~]# chmod +x /opt/mysql.sh
[root@master ~]# systemctl start keepalived
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 192.168.30.25/24 brd 192.168.30.255 scope global noprefixroute ens33
inet 192.168.200.210/32 scope global ens33
[root@master ~]# tail -f /var/log/messages
Apr 9 15:36:43 master ntpd_intres[3721]: host name not found: 0.centos.pool.ntp.org
Apr 9 15:36:43 master ntpd_intres[3721]: host name not found: 1.centos.pool.ntp.org
Apr 9 15:36:43 master ntpd_intres[3721]: host name not found: 2.centos.pool.ntp.org
Apr 9 15:36:43 master ntpd_intres[3721]: host name not found: 3.centos.pool.ntp.org
Apr 9 15:36:45 master Keepalived_vrrp[9706]: Sending gratuitous ARP on ens33 for 192.168.200.210
Apr 9 15:36:45 master Keepalived_vrrp[9706]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.200.210
Apr 9 15:36:45 master Keepalived_vrrp[9706]: Sending gratuitous ARP on ens33 for 192.168.200.210
Apr 9 15:36:45 master Keepalived_vrrp[9706]: Sending gratuitous ARP on ens33 for 192.168.200.210
Apr 9 15:36:45 master Keepalived_vrrp[9706]: Sending gratuitous ARP on ens33 for 192.168.200.210
Apr 9 15:36:45 master Keepalived_vrrp[9706]: Sending gratuitous ARP on ens33 for 192.168.200.210
Apr 9 15:40:01 master systemd: Started Session 40 of user root.
Apr 9 15:40:01 master systemd: Starting Session 40 of user root.
第二台master2从
[root@master1 ~]# yum -y install keepalived
[root@master1 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_MASTER-B
}
vrry_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 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
mysql
}
virtual_ipaddress {
192.168.200.210
}
}
}
测试VIP转移
[root@master1 ~]# vim /opt/mysql.sh
#!/bin/bash
counter=$(netstat -na |grep "LISTEN"|grep "3306" |wc -l)
if [ "${counter}" -eq 0 ]
then
systemctl stop keepalived
fi
[root@master1 ~]# chmod +x /opt/mysql.sh
[root@master1 ~]# systemctl start keepalived
[root@master1 ~]# tail -f /var/log/messages
[root@master ~]# systemctl stop mariadb
[root@master ~]# ip a |grep ens33
[root@localhost ~]# ip a |grep ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 192.168.30.25/24 brd 192.168.30.255 scope global noprefixroute ens33
2,在远程客户端 测试
Mysql 服务器授权
[root@localhost ~]# mysql -uroot
MariaDB [(none)]> grant all on *.* to ‘root‘@‘192.168.30.%‘identified by ‘123456‘;
MariaDB [(none)]> flush privileges;
通过vip 登陆测试
[root@localhost ~]# mysql -uroot -p123456 -h 192.168.30.210;
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sampdb |
| test |
| test01 |
| test02 |
+--------------------+
MySQL+Keepalived实现主主高可用方案
标签:gre interface ystemd star yum ref tar script --
本文系统来源:https://www.cnblogs.com/zc1741845455/p/10921254.html
内容总结
以上是互联网集市为您收集整理的MySQL+Keepalived实现主主高可用方案全部内容,希望文章能够帮你解决MySQL+Keepalived实现主主高可用方案所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。