新版master上安装并启动keepalived
安装并启动keepalived
代码语言:javascript复制[root@new-master ~]# yum -y install keepalived.x86_64
...
...
[root@new-master ~]# cd /etc/keepalived/
[root@new-master keepalived]# cp keepalived.conf keepalived.conf.bak.201512xx
[root@new-master keepalived]# > keepalived.conf
[root@new-master keepalived]# vim keepalived.conf
[root@new-master keepalived]# vim /etc/sysconfig/iptables
[root@new-master keepalived]# grep 18 /etc/sysconfig/iptables
-A INPUT -d 224.0.0.18 -j ACCEPT
[root@new-master keepalived]# /etc/init.d/iptables reload
iptables: Trying to reload firewall rules: [ OK ]
[root@new-master keepalived]# iptables -L -nv | grep 224
0 0 ACCEPT all -- * * 0.0.0.0/0 224.0.0.18
[root@new-master keepalived]# /etc/init.d/keepalived start
Starting keepalived: [ OK ]
[root@new-master keepalived]#
确认配置
代码语言:javascript复制[testuser@new-master ~]$ ps faux | grep keep | grep -v grep
root 73609 0.0 0.0 110276 1144 ? Ss Sep25 2:17 /usr/sbin/keepalived -D
root 73610 0.0 0.0 112500 2908 ? S Sep25 2:21 _ /usr/sbin/keepalived -D
root 73611 0.0 0.0 112484 2064 ? S Sep25 18:15 _ /usr/sbin/keepalived -D
[testuser@new-master ~]$ cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_new_master
}
vrrp_instance VI_3 {
state BACKUP
interface em1
virtual_router_id 3
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.66.6/24
}
}
[testuser@new-master ~]$
Note:
- 优先级相对原master要低,否则会抢ip
- 两个keepalived 上 advert_int 要设为 1 为了尽快完成切换
切换时间选择在业务低点
一般选择业务低点进行数据库操作,目的是为了降低业务风险,和数据丢失的风险
通过监控历史数据可以确定这个时间窗口