Сервис Keepalived
Установка
Настройка VRRP
nodeN# cat /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
# state MASTER
# state BACKUP
interface eth0
# interface br0
virtual_router_id 1
virtual_ipaddress {
192.168.X.254 label eth0:1
# 192.168.X.254 label br0:1
172.16.1.X/24 dev eth1
# 172.16.2.X/24 dev eth2
}
# virtual_routes {
# 0.0.0.0/0 via 172.16.1.254 dev eth1
# }
notify_backup "/usr/local/bin/vrrp.sh BACKUP"
notify_master "/usr/local/bin/vrrp.sh MASTER"
}
nodeN# cat /usr/local/bin/vrrp.sh
#!/bin/sh
#echo $1 >> /tmp/vrrp.txt
case $1 in
MASTER)
ip route delete default
ip route add default via 172.16.1.254
# ip route add default via 172.16.1.254 table 101
# ip route add default via 172.16.2.254 table 102
# /root/select_isp.sh
;;
BACKUP)
ip route delete default
ip route add default via 192.168.X.254
;;
esac
nodeN# chmod +x /usr/local/bin/vrrp.sh
Настройка балансировки нагрузки
gate# cat /etc/keepalived/keepalived.conf
# prod_nodes
virtual_server 172.16.1.X 1194 {
protocol UDP
lb_algo wlc
lb_kind NAT
real_server 192.168.X.201 1194 {
weight 1
TCP_CHECK {
connect_port 7505
}
}
real_server 192.168.X.202 1194 {
weight 1
TCP_CHECK {
connect_port 7505
}
}
}
# test_nodes
virtual_server 172.16.1.X 2194 {
real_server 192.168.X.203 1194 {
TCP_CHECK {
connect_port 7505
}
}
}
#virtual_server 172.16.1.X 80 {
# protocol TCP
# lb_algo wlc
# lb_kind NAT
# real_server 192.168.X.10 82 {}
# real_server 192.168.X.10 8000 {}
# real_server 192.168.X.10 NNNNN {TCP_CHECK {}}
# ...
# real_server 192.168.X.201 NNNNN {TCP_CHECK {}}
# ...
# real_server 192.168.X.203 NNNNN {TCP_CHECK {}}
# ...
# real_server 192.168.X.10 80 {}
#}
Запуск и мониторинг
# keepalived -t
# service keepalived restart
# watch "service keepalived status | cat"
# watch ipvsadm -L -n
# ipvsadm -L -n -c