How do configure to release and obtain VIP (virtual IP) when nginx is dead, down or system is rebooted for the kernel upgrades?
Edit /usr/local/etc/keepalived/keepalived.conf and add the following section to check whether nginx is alive or dead:
# vi /usr/local/etc/keepalived/keepalived.conf
Updated file on both lb0 and lb1:
vrrp_script chk_http_port { script "/usr/bin/killall -0 nginx" interval 2 weight 2 } vrrp_instance VI_1 { interface eth0 state MASTER virtual_router_id 51 priority 101 authentication { auth_type PASS auth_pass Add-Your-Password-Here } track_script { chk_http_port } virtual_ipaddress { 202.54.1.1/29 dev eth1 } }
Save and close the file. Reload keealived:
# /etc/init.d/keepalived restart
If nginx died due to any issues keepalived will release master VIP and backup server will become active. When master nginx LB0 comes backs online, the backup LB1 will go down in backup state.
You should follow me on twitter here or grab rss feed to keep track of new changes.
This FAQ entry is 3 of 8 in the "CentOS / RHEL nginx Reverse Proxy Tutorial" series. Keep reading the rest of the series:- CentOS / Redhat Linux: Install Keepalived To Provide IP Failover For Web Cluster
- CentOS / Redhat: Install nginx As Reverse Proxy Load Balancer
- Handling nginx Failover With KeepAlived
- nginx: Setup SSL Reverse Proxy (Load Balanced SSL Proxy)
- mod_extforward: Lighttpd Log Clients Real IP Behind Reverse Proxy / Load Balancer
- HowTo: Merge Apache / Lighttpd / Nginx Server Log Files
- Linux nginx: Chroot (Jail) Setup
- HowTo: SPDY SSL Installation and Configuration














{ 4 comments… read them below or add one }
Hi,
I have been following blog since about 8 months now. I like it and I cant restrain from appreciating your efforts.
Can you share knowledge you have on “How to distribute load between several apache servers and decrease response delay for end users”.
Also a small advice: Please provide some back ground in addition to implementation. For example: you can explain about reverse proxy in 3-4 lines before you jump onto impementation.
Thanks.
In order to allow nginx to bind to the virtual IP on machine(s) which are in vrrp BACKUP state, on debian, I had to do the following –
1) Add net.ipv4.ip_nonlocal_bind=1 to /etc/sysctl.conf
2) Run sysctl -p
Then nginx can start even when the machine hasn’t got the virtual IP(s).
Thanks a lot Simon, that hint made my day!
We are using keepalived for vrrp facility to allow network level ip fail over for our application.
If we need to take care applicaiton hang issue or any problem with it so in that case , do we need any script to integrate with keepalived or what is the better way?