====== Сервис Keepalived ====== * [[https://winitpro.ru/index.php/2019/09/09/keepalived-ha-balansirovka-plavayushhiy-ip-adres/|Keepalived: настройка высокой доступности и плавающих IP адресов в CentOS 7]] * [[https://habr.com/ru/post/524688/|Отказоустойчивый кластер с балансировкой нагрузки с помощью keepalived]] * [[https://youtu.be/oIczkkD-hOU|Видео урок: Доступ к приложениям в Bare-Metal Kubernetes]] ===== Установка ==== # apt install keepalived ===== Настройка VRRP ==== * Разобраться: как ведет себя в случае link down eth1/2 * [[https://github.com/acassen/keepalived/blob/master/doc/samples/keepalived.conf.vrrp.routes]] 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 ===== Настройка балансировки нагрузки ===== * [[https://habr.com/ru/post/104621/|Балансировка нагрузки с LVS]] 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