haproxy 重启提示:cannot bind socket(无法绑定socket)




问题:
haproxy配置本机IP或0.0.0.0以外的IP,启动时报错,

报错信息:
[ALERT] 066/104255 (10558) : Starting frontend http-in: cannot bind socket


分析:
高可用虚IP配置后,无法启动。


经查看一篇文章:
https://www.leaseweb.com/labs/2011/09/setting-up-keepalived-on-ubuntu-load-balancing-using-haproxy-on-ubuntu-part-2/


绑定非本机的IP需要在sysctl.conf文件中配置: net.ipv4.ip_nonlocal_bind=1


vi   /etc/sysctl.conf
添加:net.ipv4.ip_nonlocal_bind=1

sysctl -p


再重新启动haproxy,发现haproxy已经正常启动,端口也正常绑定。