首页 > 代码库 > keepalived+mysql 高可用集群
keepalived+mysql 高可用集群
mysql 为主主模式参考 https://my.oschina.net/sanmuyan/blog/877373
192.168.100.129 | mysql 主节点/keepalived 主节点 |
192.168.100.130 | mysql 备节点/keepalived 备节点 |
192.168.100.150 | 虚拟IP |
主备节点
yum install keepalived -y
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
vrrp_instance VI_1 {
state MASTER #备节点设置为BACKUP
interface eth0
virtual_router_id 51 #主备保持一致
priority 100 #备节点90
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.100.150 #虚拟IP
}
}
virtual_server 192.168.100.150 3306 { #虚拟IP
delay_loop 6
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.100.129 3306 { #真实IP 备节点为192.168.100.130
weight 3
notify_down /root/mysql.sh #如果本地IP 3306端口宕掉 则执行该脚本(杀死keepalived进程)
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
[root@localhost ~]# vim mysql.sh
#!/bin/bash
pkill keepalived
[root@localhost ~]# chmod +x mysql.sh
实验
说明keepalived已经开始工作
关闭主服务器 短暂的超时备服务器接管了虚拟IP
keepalived进程正在运行
[root@localhost ~]# ps -el | grep keepalived
1 S 0 16274 1 0 80 0 - 27926 poll_s ? 00:00:00 keepalived
5 S 0 16275 16274 0 80 0 - 28487 poll_s ? 00:00:00 keepalived
5 S 0 16276 16274 0 80 0 - 28457 poll_s ? 00:00:00 keepalived
[root@localhost ~]# systemctl stop mysqld 关闭mysql服务
keepalived 进程已经被kill
keepalived+mysql 高可用集群
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。