User Tools

Site Tools


сервис_keepalived

Сервис Keepalived

Установка

# apt install 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
    }
    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
virtual_server 172.16.1.X 1194 {
  delay_loop 1
  protocol UDP
  lb_algo wrr # makes no difference
  lb_kind NAT # no difference too
  real_server 192.168.X.10 1194 {
    weight 1
    TCP_CHECK {
        connect_timeout 3
        connect_port 7505
    }
  }
  real_server 192.168.X.20 1194 {
    weight 1
    TCP_CHECK {
        connect_timeout 3
        connect_port 7505
    }
  }
#  real_server 192.168.X.30 1194 {
#    weight 1
#    TCP_CHECK {
#        connect_timeout 3
#        connect_port 7505
#    }
#  }
}

Запуск и мониторинг

# service keepalived restart

# watch "service keepalived status | cat"
сервис_keepalived.txt · Last modified: 2022/06/16 16:20 by val