VRRP
VRRP config global_defs 'globals' option router_id 'LVS_DEVEL' option enabled '1' # 使能状态 option current_status 'NOTIFY_STOP' # 切换时记录当前的状态,也可在配置文件keepalived.conf option current_time '1590629298' # 记录一个时间 config ipaddress option name 'ipaddress0' option scope 'global' option device 'eth5' # 绑定接口 option address '10.10.10.110/24' # VIP config vrrp_instance option name 'VI_1' option auth_type 'PASS' option state 'MASTER' # 状态选择 list virtual_ipaddress 'ipaddress0' option virtual_router_id '128' # 相同的VRID是一个组 option priority '128' # 优先级 option accept '1' list track_script 'track_service' option auth_pass '12345678' # 密码 option use_vmac 'eth5' option interface 'eth5' # 绑定接口 option master_host '10.10.10.64' # 主机IP 用于同步文件 option slave_host '10.10.10.63' # 备机IP config vrrp_script option name 'script_track_service' option script '/usr/sbin/keepalived_track.sh' # 监控的脚本 option interval '5' option weight '-20' option fall '2' option rise '3' config track_script # option name 'track_service' option value 'script_track_service'
/tmp/keepalived.conf
! Configuration file for keepalived (autogenerated via init script) ! Written Thu May 28 04:19:01 2020 global_defs { router_id LVS_DEVEL # 机器标识 } static_ipaddress { # 一般不会用这个来配置 } static_routes { } vrrp_script script_track_service { script /usr/sbin/keepalived_track.sh ##openwrt\feeds\packages\net\keepalived\files\keepalived_track.sh interval 5 weight -20 fall 2 rise 3 } vrrp_instance VI_1 { # VRRP实例 authentication { auth_type PASS auth_pass 12345678 #密码 } state MASTER # 初始状态 interface eth5 # 实例绑定的网卡 virtual_router_id 128 # 这里设置VRID,这里非常重要,相同的VRID为一个组,他将决定多播的MAC地址 priority 128 # 设置本节点的优先级,优先级高的为master accept use_vmac notify_backup "/bin/busybox env -i ACTION=NOTIFY_BACKUP TYPE=INSTANCE NAME=VI_1 IFACE=eth5 /sbin/hotplug-call keepalived" notify_master "/bin/busybox env -i ACTION=NOTIFY_MASTER TYPE=INSTANCE NAME=VI_1 IFACE=eth5 /sbin/hotplug-call keepalived" notify_fault "/bin/busybox env -i ACTION=NOTIFY_FAULT TYPE=INSTANCE NAME=VI_1 IFACE=eth5 /sbin/hotplug-call keepalived" notify_stop "/bin/busybox env -i ACTION=NOTIFY_STOP TYPE=INSTANCE NAME=VI_1 IFACE=eth5 /sbin/hotplug-call keepalived"
# /etc/hotplug.d/keepalived# cat 01-user # 切换时会调用的脚本, 可以在里面干一些事情
# openwrt\feeds\packages\net\keepalived\files\keepalived.user
virtual_ipaddress { 10.10.10.110/24 dev eth5 scope global } track_script { script_track_service } }