我最近尝试使用HAProxy对我的应用程序进行负载均衡,并且能够成功完成。后来,我遇到了一个名为Floating IP的概念,它可以与keepalived一起使用,以使负载均衡器具有高可用性。虽然我无法理解如何创建浮动Ip。如何创建浮动IP并使用它来配置HAProxy? 感谢。
答案 0 :(得分:9)
假设:
步骤:
sudo ufw allow in from 198.51.100.20 to 224.0.0.18
#on 198.51.100.10 sudo ufw allow in from 198.51.100.10 to 224.0.0.18
#on 198.51.100.20 /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind=1
sudo sysctl -p
#reload config change sudo apt-get install keepalived
/etc/keepalived/keepalived.conf
/etc/haproxy/haproxy.cfg
bind 198.51.100.50:80
sudo service haproxy restart
sudo ip addr show | grep eth0
#应列出共享IP sudo ip addr show | grep eth0
#不应列出共享IP sudo service haproxy stop
sudo ip addr show | grep eth0
#不应列出共享IP sudo ip addr show | grep eth0
#应列出共享IP sudo service haproxy start
sudo ip addr show | grep eth0
#应列出共享IP sudo ip addr show | grep eth0
#不应列出共享IP vrrp_script chk_haproxy { # Requires keepalived-1.1.13
script "killall -0 haproxy" # cheaper than pidof
interval 2 # check every 2 seconds
weight 2 # add 2 points of priority if OK
}
vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 101 # 101 on primary, 100 on secondary
virtual_ipaddress {
198.51.100.50
}
track_script {
chk_haproxy
}
}