基于mysql主主互备实现keepalived高可用 方案
程序员文章站
2024-03-20 15:25:10
...
文章目录
keepalived安装与配置
安装包获取:https://www.keepalived.org
二进制安装:
# 同步时钟源
# yum -y install ntp ntpdate
# ntpdate cn.pool.ntp.org
# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
#获取安装包
[aaa@qq.com ~]# ls
keepalived-2.0.20.tar.gz
[aaa@qq.com ~]# tar xzf keepalived-2.0.20.tar.gz -C /usr/local/src/
# 配置编译环境
# yum install openssl-devel gcc gcc-c++ make
# 创建安装目录
# mkdir -p /data/keepalived
# cd /usr/local/src/keepalived-2.0.20/
# ./configure --prefix=/data/keepalived
# echo $?
0
# make
# echo $?
0
# make install
# echo $?
0
配置规范启动
# cd /usr/local/src/keepalived-2.0.20/keepalived/etc/
# cp -R init /data/keepalived/
# cp -R init /data/keepalived/etc/
# cp -R init.d /data/keepalived/etc/
# ll /data/keepalived/etc/
总用量 0
drwxr-xr-x. 2 root root 86 7月 31 21:58 init
drwxr-xr-x. 2 root root 135 7月 31 21:58 init.d
drwxr-xr-x. 3 root root 44 7月 31 18:01 keepalived
drwxr-xr-x. 2 root root 24 7月 31 17:59 sysconfig
修改配置文件
cp -p /etc/keepalived/keepalived.conf{,.bak}
#mysql01端
! Configuration File for keepalived
global_defs {
notification_email {
aaa@qq.com
aaa@qq.com
aaa@qq.com
}
notification_email_from aaa@qq.com
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id HA_MYSQL01
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script check_mysqld {
script "/etc/keepalived/check_mysqld.sh"
interval 2
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.10.201
}
track_script {
check_mysqld
}
}
# mysql02端
! Configuration File for keepalived
global_defs {
notification_email {
aaa@qq.com
aaa@qq.com
aaa@qq.com
}
notification_email_from aaa@qq.com
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id HA_MYSQL01
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script check_mysqld {
script "/etc/keepalived/check_mysqld.sh"
interval 2
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.10.201
}
track_script {
check_mysqld
}
}
验证
两端都开启keepalived —> systemctl start keepalived
mysql01端停止keepalived
注意
mysql01端恢复后ip又漂移到mysql01端上
故虽然此时能够完成故障的切换,但数据库的应用场景上不建议频繁的切换,因此将其配置为vip不抢占模式,具体配置如下
只需修改mysql01端的配置文件如下:
! Configuration File for keepalived
global_defs {
notification_email {
aaa@qq.com
aaa@qq.com
aaa@qq.com
}
notification_email_from aaa@qq.com
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id HA_MYSQL01
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script check_mysqld {
script "/etc/keepalived/check_mysqld.sh"
interval 2
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 50
advert_int 1
nopreempt #添加此选项,不抢占模式
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.10.201
}
track_script {
check_mysqld
}
}
此时重启mysql01端keepalived服务
相当于故障了,并随之恢复;此时ip漂移到mysql02端且不会漂移回mysql01
此时我们将mysql02端服务停掉,ip漂移到mysql01
用master主机测试
------------------------------------------------------------------------------------------------------- 返回目录
推荐阅读
-
基于mysql主主互备实现keepalived高可用 方案
-
MySQL双主+keepalived实现高可用
-
MYSQL 主主热备高可用方案与实现 博客分类: mysql
-
Mysql+Keepalived双主热备高可用操作记录
-
基于mysql+mycat搭建稳定高可用集群负载均衡主备复制读写分离操作
-
JAVAEE——宜立方商城03:Nginx负载均衡高可用、Keepalived+Nginx实现主备
-
Ubuntu搭建Mysql+Keepalived高可用的实现(双主热备)
-
Ansible实现主备模式的高可用(Keepalived)
-
关于使用Keepalived实现Nginx的自动重启及双主热备高可用问题
-
MySQL高可用性之Keepalived+MySQL(双主热备)