- SG: +65 64383504
- IN: 022 25771219
- IN: 022 25792714
- IN: +91 9987536436
High Availability in NGINX Plus
Sandeep Khuperkar I CTO and Director, Ashnik
In today’s world users expect applications and websites to be accessible 24×7. This means ensuring not only performance but high availability of website and applications.
Keepalived provides the keepalive daemon for Linux servers, an implementation of the Virtual Router Redundancy Protocol (VRRP) to manage virtual routers (virtual IP addresses), and a health check facility to determine whether a service is up and operational.
If a service on a node fails the configured number of health checks, keepalived reassigns the virtual IP address from the master (active) node to the backup (passive) node.
NGINX Plus Release 6 and later support HA configuration and is based on Keepalived The solution is based on the opensourc keepalived project, which combines three components to provide an HA solution for Linux systems: thekeepalived daemon, an implementation of the Virtual Router Redundancy Protocol (VRRP) that manages assignment of the virtual IP address for the HA pair, and a health-checking facility that determines whether a service (for example, a web server, PHP backend, or NGINX Plus) is up and operational.
VRRP ensures that there is a master node at all times. The backup node listens for VRRP advertisement packets from the master node. If it does not receive an advertisement packet for a period longer than three times the configured advertisement interval, the backup node takes over as master and assigns the configured virtual IP addresses to itself.
Configuring NGINX in HA mode
You may start configuration by running nginx-ha-setup script. This script is available in nginx-ha-keepalived package. This package needs to be installed in addition to the base NGINX Plus package.
This nginx-ha-script helps configuring NGINX Plus in active-passive mode. When you run this script it will ask for below inputs :
- IP address for both Master and Backup nodes
- One free IP address to be used as virtual IP address.
- The configuration of the keepalived daemon is in file /etc/keepalived/keepalived.conf.
Each node in HA setup needs its own copy of configuration file, The “priority” directive controls which host becomes the master. The “notify” directive names the notification script included in the distribution used to generate syslog message when transition or fault occurs.
Health Check script
In keepalived there is no fencing mechanism so in case where two nodes not aware of each other might end up assuming as a master and will try to assign the virtual IP address to itself. To prevent this situation a mechanism called chk_nginx_service that runs a script regularly to check weather NGINX Plus is operational, and adjusts the local node’s priority based on the script’s return code. If it returns 0(zero) indicates correct operation, and code1 indicates an error.
High-availability failover takes place in the event of a catastrophic failure on the master NGINX instance – a hardware failure, operating system shutdown, or termination of the NGINX Plus software. Internal health checks can be extended to identify more failure situations if necessary.
– Sandeep Khuperkar I CTO and Director, Ashnik
Sandeep is the Director and CTO at Ashnik. He brings more than 21 years of Industry experience (most of it spans across Red Hat & IBM India), with 14+ years in open source and building open source and Linux business model. He is on Advisory Board of JJMCollege of Engineering (Electronics Dept.) And visiting lecturer with few of Engineering colleges and works towards enabling them on open source technologies. He is author, Enthusiast and community moderator at Opensource.com. He is also member of Open Source Initiative, Linux Foundation and Open Source Consortium Of India.