I have a LB which is redirecting request in a round robin mechanism to my 4 servers configured. I have assigned a floating IP address(LOADBALANCERFLOATINGIPADDRESS) to the machine. Now I want my LB to listen on both the IP address. So I tried binding to both the IP address in listen but that does not works.
sudo nano /etc/haproxy/haproxy.cfg
#HAProxy for web servers
frontend web-frontend
bind LOADBALANCERIPADDRESS:80
mode http
default_backend web-backend
backend web-backend
http-request set-header X-Forwarded-Proto https if { ssl_fc } # For Proto
http-request add-header X-Real-Ip %[src] # Custom header with src IP
option forwardfor # X-forwarded-for
balance roundrobin
server web-server1 IP1:80 check
server web-server2 IP2:80 check
server web-server3 IP3:80 check
server web-server4 IP4:80 check
listen stats
bind LOADBALANCERIPADDRESS:8080
bind LOADBALANCERFLOATINGIPADDRESS:80
mode http
option forwardfor
option httpclose
stats enable
stats show-legends
stats refresh 5s
stats uri /stats
stats realm Haproxy\ Statistics
stats auth root:password #Login User and Password for the monitoring
stats admin if TRUE
default_backend web-backend
However when I check syntax of my config file, it says valid
root@ubuntu-s-1vcpu-1gb-blr1-01:~# sudo haproxy -f /etc/haproxy/haproxy.cfg -c
Configuration file is valid
But when I tried restarting HAProxy service, I am getting error
root@ubuntu-s-1vcpu-1gb-blr1-01:~# sudo systemctl restart haproxy.service
Job for haproxy.service failed because the control process exited with error code.
See "systemctl status haproxy.service" and "journalctl -xe" for details.
HAProxy logs says :
root@ubuntu-s-1vcpu-1gb-blr1-01:~# systemctl status haproxy.service
● haproxy.service - HAProxy Load Balancer
Loaded: loaded (/lib/systemd/system/haproxy.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2022-05-11 06:20:41 UTC; 10s ago
Docs: man:haproxy(1)
file:/usr/share/doc/haproxy/configuration.txt.gz
Process: 189373 ExecStartPre=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS (code=exited, status=0/SUCCESS)
Process: 189374 ExecStart=/usr/sbin/haproxy -Ws -f $CONFIG -p $PIDFILE $EXTRAOPTS (code=exited, status=1/FAILURE)
Main PID: 189374 (code=exited, status=1/FAILURE)
May 11 06:20:40 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: haproxy.service: Main process exited, code=exited, status=1/FAILURE
May 11 06:20:40 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: haproxy.service: Failed with result 'exit-code'.
May 11 06:20:40 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Failed to start HAProxy Load Balancer.
May 11 06:20:41 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: haproxy.service: Scheduled restart job, restart counter is at 5.
May 11 06:20:41 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Stopped HAProxy Load Balancer.
May 11 06:20:41 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: haproxy.service: Start request repeated too quickly.
May 11 06:20:41 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: haproxy.service: Failed with result 'exit-code'.
May 11 06:20:41 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Failed to start HAProxy Load Balancer.
root@ubuntu-s-1vcpu-1gb-blr1-01:~# sudo nano /etc/haproxy/haproxy.cfg
Note : I know that there is a workaround for this to bind it to all incoming IP address by using bind *.80
. But I want to specify my LB and floating IP address separately