SlideShare a Scribd company logo
1 of 33
• High availability refers to a system or component that is continuously operational for a
desirably long length of time.
• Availability can be measured relative to “100% operational” or “never failing.”
• A widely-held but difficult-to-achieve standard of availability for a system or product is
known as “five 9s” (99.999 percent) availability.
• Since a computer system or a network consists of many parts in which all parts usually
need to be present in order for the whole to be operational, much planning for high
availability centers around backup and failover processing, data storage, and access.
• For any system to be highly available, the parts of a system should be well-designed,
configured thoroughly tested before they are used.
• In this guide, we will show you to use keepalived to set up a highly available web service
on Ubuntu 16.04 by using a floating IP address that can be moved between two capable
web servers.
• The keepalived daemon can be used to monitor services or systems and to automatically
failover to a standby if there’s any problems occur.
• If the primary server goes down, the floating IP will be moved to the second server
automatically, allowing service to resume by the help of floating IP that we are gonna use
in this tutorial.
Prerequisites:
• In this article we are going to use 2 Ubuntu 16.04 nodes, with 2 CPUs, 1 GB RAM and
40 GB disk on each server with their fully qualified domain name setup and Private
networking enabled within the same data center.
• Let’s log in to both your Ubuntu 16.04 nodes using non-root user with sudo privileges
and then follow the below steps to achieve the target of setting up high availability web
servers with keepalived and floating IP.
Nginx Installation:
• Here we will be using Nginx as a simple web server, in order to reduce our operational
complexity besides ‘keepalived’.
• Run the below commands to update your system first with latest packages and
security updates and then install Nginx package on your Ubuntu 16.04 servers.
$ sudo apt-get update
$ sudo apt-get install nginx
Nginx Installation:
• In order to setup high availability , we need both servers to serve the same content.
• We will use Nginx to indicate that the two servers are serving our requests at any given
time.
• Let’s change the default index.html page on each of our hosts by opening the below
file.
$ sudo vim /usr/share/nginx/html/index.html
Nginx Installation:
• On your first server, replace or append the contents of the file with below lines.
Primary Node
• On your second server, replace or append the contents of the file with below contents
and save your changes using :wq! .
Secondary Node
Build and Install Keepalived:
• Now install the keepalived daemon on both servers.
• There is a version of keepalived in Ubuntu’s default repositories, which is outdated and
suffers from a few bugs that might prevent our configuration from working.
• We will install the latest version of keepalived from source after installing the
dependencies needed to build the software using the command below.
$ sudo apt-get install build-essential libssl-dev
Build and Install Keepalived:
• Once the dependencies are in
place, we can download the
tarball for keepalived by
visiting Official Keepalive
download page to find the
latest version of the software.
Build and Install Keepalived:
• Just right-click on the latest version and copy the link address to download this
package on your server using wget on your system.
$ wget http://www.keepalived.org/software/keepalived-1.2.23.tar.gz
• After downloading, extract the archive using tar and move into the extracted folder
using below commands.
$ tar -zxf keepalived-1.2.23.tar.gz
$ cd keepalived-1.2.23
Build and Install Keepalived:
• Now compile and install the keepalived
package by flowing the commands
below.
$ ./configure
Build and Install Keepalived:
• Your system will be compiled by
showing the configuration parameters
like below.
Keepalived configuration
------------------------
Keepalived version : 1.2.23
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lssl -lcrypto –l
crypt Use IPVS Framework : Yes
IPVS sync daemon support : Yes
IPVS use libnl : No
fwmark socket support : Yes
Use VRRP Framework : Yes
Use VRRP VMAC : Yes
Use VRRP authentication : Yes
SNMP keepalived support : No
SNMP checker support : No
SNMP RFCv2 support : No
SNMP RFCv3 support : No
SHA1 support : No
Use Debug flags : No
Memory alloc check : No
libnl version : None
Use IPv4 devconf : No
Use libiptc : No
Use libipset : No
ubuntu@ubuntu-16:~/keepalived-1.2.23$
Build and Install Keepalived:
• Now it’s time to install keepalived, let run
the below command and we have all
done for the next step.
$ make
$ sudo make install
Setting up Upstart Script for Keepalived:
• After installation of keepalived, we are going to create a simple Upstart script to handle our keepalived service by
creating a new keepalived.conf file within the /etc/init directory to get started.
• Let’s open the file using any of your editor and then specify the run levels in which the service should be started
and stopped. We want this service to be active in all normal conditions (runlevels 2-5) and stopped for all other
runlevels (when reboot, poweroff, or single-user mode is initiated, for instance). So add the below entries in it
starting with its description.
$ sudo vim /etc/init/keepalived.conf
description "load-balancing and high-availability service”
start on runlevel [2345]
stop on runlevel [!2345]
Setting up Upstart Script for Keepalived:
Since the service is integral to ensuring our web service remains available, we want to restart this
service in the event of any failure. for that we need to specify the actual exec line that will start the
service by adding the --dont-fork option so that Upstart can track the pid correctly.
respawn exec /usr/local/sbin/keepalived --dont-fork
Setting up Upstart Script for
Keepalived:
Here is the image view of
the full configurations
shown below, now save
and close the file to move
ahead.
Setup Keepalived Configuration:
• The keepalived service looks for its configuration files in the /etc/keepalived directory.
• For this purpose we need to create a directory on both of your servers by using below commands.
$ sudo mkdir -p /etc/keepalived
Setup Keepalived Configuration:
• Now before we create the configuration file, find the private IP addresses of both of your servers.
• This can be found with the iproute2 tools by typing below command.
$ ip -4 addr show dev ens3
• Copy this value from both of your systems as we will need to reference these addresses inside of our
configuration files below.
Configuring Primary Server:
• On your primary server, create the main keepalived configuration file. The daemon looks for a file
called keepalived.conf inside of the /etc/keepalived directory with below command and put the
following contents in it.
$ sudo vim /etc/keepalived/keepalived.conf
vrr_script chk_nginx {
script "pidof nginx”
interval 2
}
Configuring Primary Server:
• Then open a block called vrrp_instance which is the main configuration section that defines the
way that keepalived will implement high availability.
• Then assign an ID for this cluster group that will be shared by both nodes.
• We also set up some simple authentication for our keepalived daemons to communicate with one
another.
• After that we will tell keepalived to use the routine we created at the top of the file,
labeled chk_nginx, to determine the health of the local system.
Configuring Primary Server:
• So the overall primary configuration should look like
below.
vrrp_script chk_nginx {
script "pidof nginx”
interval 2
}
vrrp_instance VI_1 {
interface ens3
state MASTER
priority 200
virtual_router_id 44
unicast_src_ip primary_private_IP
unicast_peer {
secondary_private_IP
}
authentication {
auth_type PASS
auth_pass password
}
track_script {
chk_nginx
}
notify_master /etc/keepalived/master.sh
}
Now save the Primary server’s configuration and
move to the Secondary server’s configurations file
setup.
Configuring Secondary Server:
• In our secondary server, we will create the companion script on our secondary server by creating file
at /etc/keepalived/keepalived.conf on it.
• The most of the configurations will be similar to our Primary server’s configurations file.
• Just make sure to update the proper parameters
for state, priority, unicast_src_ip and unicast_peer.
• And your final secondary server configuration files should be like as shown below.
Configuring Secondary Server:
vrrp_script chk_nginx {
script "pidof nginx”
interval 2
}
vrrp_instance VI_1 {
interface ens3
state BACKUP
priority 100
virtual_router_id 33
unicast_src_ip secondary_private_IP
unicast_peer {
primary_private_IP
}
authentication {
auth_type PASS
auth_pass password
}
track_script {
chk_nginx
}
notify_master /etc/keepalived/master.sh
}
Configuring Secondary Server:
Save the configuration file after making required changes and move to the next step.
Setup Floating IP
• Here we need to create and assign a floating IP address to the current node whenever the local
keepalived instance becomes the master server.
• The floating IP can assigned from the Vexxhost cloud portal to your working node. Just Login to the
portal and click on “Floating IPS” and then click to create new Floating IP and then Assign it to your
desired server as shown below.
Once you have assigned the Floating IP then if you visit the floating IP in your web browser, you
should see your “Primary Server Node” index.html page.
Starting Keepalived and Testing Failover:
• As we setup the floating IP to one or our master node. Now we can start the service on both of our
machines by issuing the below commands.
$ sudo systemctl start keepalived
• The service should start up on each server and contact its peer, authenticating with the shared secret we
configured. Each daemon will monitor the local Nginx process and will listen to signals from the remote
keepalived process.
• So, if you visit by opening your web browser by flowing the floating IP address then we will see the Nginx
page of your Primary web server.
Starting Keepalived and Testing Failover:
• Now, can test the failover of our configuration.
• The failover should occur the Nginx health check on the primary server indicates that Nginx is no longer running.
• In this case, the primary server’s keepalived daemon will enter the “fault” state.
• It will notify the secondary server that it should transition to the master state and claim the floating IP.
• Or when the secondary server loses its keepalived connection to the primary server.
• If the secondary server cannot reach the primary server for any reason, it will transition to the “master” state and
attempt to claim the floating IP.
Starting Keepalived and Testing Failover:
• We can test the first condition by stopping the Nginx service on the primary server.
Primary-Node$sudo service nginx stop
• Now refresh your web browser, you might initially get a response indicating that the page is not available,
but after a while, you will see the Nginx web page of your Secondary server node.
• If you refresh the page again, you will find that the primary server has reclaimed ownership of the floating
IP again.
Conclusion:
• That’s it, we have successfully installed and setup Highly Available Web Servers with Keepalived
and Floating IP on primary and secondary Ubuntu 16.04 nodes.
• As you can see, for a simple IP failover, keepalived is much simpler than corosync/pacemaker to set
up.
• So, i hope you have got this article much helpful and interesting.
• If you still found and issue or need to post your suggestions then you are more than welcome to
share your contributions in the comments section.
https://vexxhost.com/

More Related Content

Similar to How To Setup Highly Available Web Servers with Keepalived & Floating IPs on Ubuntu 16.04

Installing Lamp Stack on Ubuntu Instance
Installing Lamp Stack on Ubuntu InstanceInstalling Lamp Stack on Ubuntu Instance
Installing Lamp Stack on Ubuntu Instancekamarul kawnayeen
 
Drupal Continuous Integration with Jenkins - The Basics
Drupal Continuous Integration with Jenkins - The BasicsDrupal Continuous Integration with Jenkins - The Basics
Drupal Continuous Integration with Jenkins - The BasicsJohn Smith
 
Oracle forms and reports 11g installation on linux
Oracle forms and reports 11g installation on linuxOracle forms and reports 11g installation on linux
Oracle forms and reports 11g installation on linuxVenu Palakolanu
 
Configuration of Apache Web Server On CentOS 8
Configuration of Apache Web Server On CentOS 8Configuration of Apache Web Server On CentOS 8
Configuration of Apache Web Server On CentOS 8Kaan Aslandağ
 
Extracting twitter data using apache flume
Extracting twitter data using apache flumeExtracting twitter data using apache flume
Extracting twitter data using apache flumeBharat Khanna
 
02 Hadoop deployment and configuration
02 Hadoop deployment and configuration02 Hadoop deployment and configuration
02 Hadoop deployment and configurationSubhas Kumar Ghosh
 
How To Configure Nginx Load Balancer on CentOS 7
How To Configure Nginx Load Balancer on CentOS 7How To Configure Nginx Load Balancer on CentOS 7
How To Configure Nginx Load Balancer on CentOS 7VCP Muthukrishna
 
Professional deployment
Professional deploymentProfessional deployment
Professional deploymentIvelina Dimova
 
Ftp configuration in rhel7
Ftp configuration in rhel7Ftp configuration in rhel7
Ftp configuration in rhel7Balamurugan M
 
Philly security shell meetup
Philly security shell meetupPhilly security shell meetup
Philly security shell meetupNicole Johnson
 
图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库
图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库
图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库maclean liu
 
NGINX Installation and Tuning
NGINX Installation and TuningNGINX Installation and Tuning
NGINX Installation and TuningNGINX, Inc.
 
Quick-Start Guide: Deploying Your Cloudian HyperStore Hybrid Storage Service
Quick-Start Guide: Deploying Your Cloudian HyperStore Hybrid Storage ServiceQuick-Start Guide: Deploying Your Cloudian HyperStore Hybrid Storage Service
Quick-Start Guide: Deploying Your Cloudian HyperStore Hybrid Storage ServiceCloudian
 
RAC-Installing your First Cluster and Database
RAC-Installing your First Cluster and DatabaseRAC-Installing your First Cluster and Database
RAC-Installing your First Cluster and DatabaseNikhil Kumar
 
Install nginx on ubuntu 21.04 server
Install nginx on ubuntu 21.04 serverInstall nginx on ubuntu 21.04 server
Install nginx on ubuntu 21.04 serverLinuxConcept
 
Ansible Tutorial.pdf
Ansible Tutorial.pdfAnsible Tutorial.pdf
Ansible Tutorial.pdfNigussMehari4
 
Varnish Configuration Step by Step
Varnish Configuration Step by StepVarnish Configuration Step by Step
Varnish Configuration Step by StepKim Stefan Lindholm
 

Similar to How To Setup Highly Available Web Servers with Keepalived & Floating IPs on Ubuntu 16.04 (20)

Installing Lamp Stack on Ubuntu Instance
Installing Lamp Stack on Ubuntu InstanceInstalling Lamp Stack on Ubuntu Instance
Installing Lamp Stack on Ubuntu Instance
 
Drupal Continuous Integration with Jenkins - The Basics
Drupal Continuous Integration with Jenkins - The BasicsDrupal Continuous Integration with Jenkins - The Basics
Drupal Continuous Integration with Jenkins - The Basics
 
Oracle forms and reports 11g installation on linux
Oracle forms and reports 11g installation on linuxOracle forms and reports 11g installation on linux
Oracle forms and reports 11g installation on linux
 
Configuration of Apache Web Server On CentOS 8
Configuration of Apache Web Server On CentOS 8Configuration of Apache Web Server On CentOS 8
Configuration of Apache Web Server On CentOS 8
 
Extracting twitter data using apache flume
Extracting twitter data using apache flumeExtracting twitter data using apache flume
Extracting twitter data using apache flume
 
02 Hadoop deployment and configuration
02 Hadoop deployment and configuration02 Hadoop deployment and configuration
02 Hadoop deployment and configuration
 
Ansible.pdf
Ansible.pdfAnsible.pdf
Ansible.pdf
 
How To Configure Nginx Load Balancer on CentOS 7
How To Configure Nginx Load Balancer on CentOS 7How To Configure Nginx Load Balancer on CentOS 7
How To Configure Nginx Load Balancer on CentOS 7
 
Professional deployment
Professional deploymentProfessional deployment
Professional deployment
 
FTP(In_Linux).pptx
FTP(In_Linux).pptxFTP(In_Linux).pptx
FTP(In_Linux).pptx
 
Ftp configuration in rhel7
Ftp configuration in rhel7Ftp configuration in rhel7
Ftp configuration in rhel7
 
Philly security shell meetup
Philly security shell meetupPhilly security shell meetup
Philly security shell meetup
 
图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库
图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库
图文详解安装Net backup 6.5备份恢复oracle 10g rac 数据库
 
zLAMP
zLAMPzLAMP
zLAMP
 
NGINX Installation and Tuning
NGINX Installation and TuningNGINX Installation and Tuning
NGINX Installation and Tuning
 
Quick-Start Guide: Deploying Your Cloudian HyperStore Hybrid Storage Service
Quick-Start Guide: Deploying Your Cloudian HyperStore Hybrid Storage ServiceQuick-Start Guide: Deploying Your Cloudian HyperStore Hybrid Storage Service
Quick-Start Guide: Deploying Your Cloudian HyperStore Hybrid Storage Service
 
RAC-Installing your First Cluster and Database
RAC-Installing your First Cluster and DatabaseRAC-Installing your First Cluster and Database
RAC-Installing your First Cluster and Database
 
Install nginx on ubuntu 21.04 server
Install nginx on ubuntu 21.04 serverInstall nginx on ubuntu 21.04 server
Install nginx on ubuntu 21.04 server
 
Ansible Tutorial.pdf
Ansible Tutorial.pdfAnsible Tutorial.pdf
Ansible Tutorial.pdf
 
Varnish Configuration Step by Step
Varnish Configuration Step by StepVarnish Configuration Step by Step
Varnish Configuration Step by Step
 

More from VEXXHOST Private Cloud

10 Essential Laravel 4 Packages Everyone Should Use.pptx
10 Essential Laravel 4 Packages Everyone Should Use.pptx10 Essential Laravel 4 Packages Everyone Should Use.pptx
10 Essential Laravel 4 Packages Everyone Should Use.pptxVEXXHOST Private Cloud
 
How To Install Rails & Nginx with Passenger on Ubuntu
How To Install Rails & Nginx with Passenger on UbuntuHow To Install Rails & Nginx with Passenger on Ubuntu
How To Install Rails & Nginx with Passenger on UbuntuVEXXHOST Private Cloud
 
How To Create a SSL Certificate on Nginx for Ubuntu.pptx
How To Create a SSL Certificate on Nginx for Ubuntu.pptxHow To Create a SSL Certificate on Nginx for Ubuntu.pptx
How To Create a SSL Certificate on Nginx for Ubuntu.pptxVEXXHOST Private Cloud
 
How To Securely Set Up Shipyard 2.0.10 with TLS on CoreOS
How To Securely Set Up Shipyard 2.0.10 with TLS on CoreOSHow To Securely Set Up Shipyard 2.0.10 with TLS on CoreOS
How To Securely Set Up Shipyard 2.0.10 with TLS on CoreOSVEXXHOST Private Cloud
 
How to deploy a MariaDB Galera cluster on Ubuntu 14.04
How to deploy a MariaDB Galera cluster on Ubuntu 14.04How to deploy a MariaDB Galera cluster on Ubuntu 14.04
How to deploy a MariaDB Galera cluster on Ubuntu 14.04VEXXHOST Private Cloud
 
How To Mitigate & Fix OpenSSL Heartbeat on CentOS or Ubuntu
How To Mitigate & Fix OpenSSL Heartbeat on CentOS or UbuntuHow To Mitigate & Fix OpenSSL Heartbeat on CentOS or Ubuntu
How To Mitigate & Fix OpenSSL Heartbeat on CentOS or UbuntuVEXXHOST Private Cloud
 
How To Install Ruby on Rails on Ubuntu
How To Install Ruby on Rails on UbuntuHow To Install Ruby on Rails on Ubuntu
How To Install Ruby on Rails on UbuntuVEXXHOST Private Cloud
 
How To Run Nginx in a Docker Container on Ubuntu 16.04
How To Run Nginx in a Docker Container on Ubuntu 16.04How To Run Nginx in a Docker Container on Ubuntu 16.04
How To Run Nginx in a Docker Container on Ubuntu 16.04VEXXHOST Private Cloud
 
How To Install & Configure Varnish with Apache on Ubuntu
How To Install & Configure Varnish with Apache on UbuntuHow To Install & Configure Varnish with Apache on Ubuntu
How To Install & Configure Varnish with Apache on UbuntuVEXXHOST Private Cloud
 
CentOS 6 to CentOS 7 Upgrade Procedure
CentOS 6 to CentOS 7 Upgrade ProcedureCentOS 6 to CentOS 7 Upgrade Procedure
CentOS 6 to CentOS 7 Upgrade ProcedureVEXXHOST Private Cloud
 
How To Install GitLab As Your Private GitHub Clone
How To Install GitLab As Your Private GitHub CloneHow To Install GitLab As Your Private GitHub Clone
How To Install GitLab As Your Private GitHub CloneVEXXHOST Private Cloud
 

More from VEXXHOST Private Cloud (15)

10 Essential Laravel 4 Packages Everyone Should Use.pptx
10 Essential Laravel 4 Packages Everyone Should Use.pptx10 Essential Laravel 4 Packages Everyone Should Use.pptx
10 Essential Laravel 4 Packages Everyone Should Use.pptx
 
How To Install Rails & Nginx with Passenger on Ubuntu
How To Install Rails & Nginx with Passenger on UbuntuHow To Install Rails & Nginx with Passenger on Ubuntu
How To Install Rails & Nginx with Passenger on Ubuntu
 
How To Create a SSL Certificate on Nginx for Ubuntu.pptx
How To Create a SSL Certificate on Nginx for Ubuntu.pptxHow To Create a SSL Certificate on Nginx for Ubuntu.pptx
How To Create a SSL Certificate on Nginx for Ubuntu.pptx
 
How to Add Swap on Ubuntu
How to Add Swap on UbuntuHow to Add Swap on Ubuntu
How to Add Swap on Ubuntu
 
Getting Started with MEAN Stack
Getting Started with MEAN StackGetting Started with MEAN Stack
Getting Started with MEAN Stack
 
How To Securely Set Up Shipyard 2.0.10 with TLS on CoreOS
How To Securely Set Up Shipyard 2.0.10 with TLS on CoreOSHow To Securely Set Up Shipyard 2.0.10 with TLS on CoreOS
How To Securely Set Up Shipyard 2.0.10 with TLS on CoreOS
 
Fixing 403 Forbidden Nginx Errors
Fixing 403 Forbidden Nginx ErrorsFixing 403 Forbidden Nginx Errors
Fixing 403 Forbidden Nginx Errors
 
WordPress App on Ubuntu 14.04 LTS
WordPress App on Ubuntu 14.04 LTSWordPress App on Ubuntu 14.04 LTS
WordPress App on Ubuntu 14.04 LTS
 
How to deploy a MariaDB Galera cluster on Ubuntu 14.04
How to deploy a MariaDB Galera cluster on Ubuntu 14.04How to deploy a MariaDB Galera cluster on Ubuntu 14.04
How to deploy a MariaDB Galera cluster on Ubuntu 14.04
 
How To Mitigate & Fix OpenSSL Heartbeat on CentOS or Ubuntu
How To Mitigate & Fix OpenSSL Heartbeat on CentOS or UbuntuHow To Mitigate & Fix OpenSSL Heartbeat on CentOS or Ubuntu
How To Mitigate & Fix OpenSSL Heartbeat on CentOS or Ubuntu
 
How To Install Ruby on Rails on Ubuntu
How To Install Ruby on Rails on UbuntuHow To Install Ruby on Rails on Ubuntu
How To Install Ruby on Rails on Ubuntu
 
How To Run Nginx in a Docker Container on Ubuntu 16.04
How To Run Nginx in a Docker Container on Ubuntu 16.04How To Run Nginx in a Docker Container on Ubuntu 16.04
How To Run Nginx in a Docker Container on Ubuntu 16.04
 
How To Install & Configure Varnish with Apache on Ubuntu
How To Install & Configure Varnish with Apache on UbuntuHow To Install & Configure Varnish with Apache on Ubuntu
How To Install & Configure Varnish with Apache on Ubuntu
 
CentOS 6 to CentOS 7 Upgrade Procedure
CentOS 6 to CentOS 7 Upgrade ProcedureCentOS 6 to CentOS 7 Upgrade Procedure
CentOS 6 to CentOS 7 Upgrade Procedure
 
How To Install GitLab As Your Private GitHub Clone
How To Install GitLab As Your Private GitHub CloneHow To Install GitLab As Your Private GitHub Clone
How To Install GitLab As Your Private GitHub Clone
 

Recently uploaded

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

How To Setup Highly Available Web Servers with Keepalived & Floating IPs on Ubuntu 16.04

  • 1.
  • 2. • High availability refers to a system or component that is continuously operational for a desirably long length of time. • Availability can be measured relative to “100% operational” or “never failing.” • A widely-held but difficult-to-achieve standard of availability for a system or product is known as “five 9s” (99.999 percent) availability.
  • 3. • Since a computer system or a network consists of many parts in which all parts usually need to be present in order for the whole to be operational, much planning for high availability centers around backup and failover processing, data storage, and access. • For any system to be highly available, the parts of a system should be well-designed, configured thoroughly tested before they are used.
  • 4. • In this guide, we will show you to use keepalived to set up a highly available web service on Ubuntu 16.04 by using a floating IP address that can be moved between two capable web servers. • The keepalived daemon can be used to monitor services or systems and to automatically failover to a standby if there’s any problems occur. • If the primary server goes down, the floating IP will be moved to the second server automatically, allowing service to resume by the help of floating IP that we are gonna use in this tutorial.
  • 5. Prerequisites: • In this article we are going to use 2 Ubuntu 16.04 nodes, with 2 CPUs, 1 GB RAM and 40 GB disk on each server with their fully qualified domain name setup and Private networking enabled within the same data center. • Let’s log in to both your Ubuntu 16.04 nodes using non-root user with sudo privileges and then follow the below steps to achieve the target of setting up high availability web servers with keepalived and floating IP.
  • 6. Nginx Installation: • Here we will be using Nginx as a simple web server, in order to reduce our operational complexity besides ‘keepalived’. • Run the below commands to update your system first with latest packages and security updates and then install Nginx package on your Ubuntu 16.04 servers. $ sudo apt-get update $ sudo apt-get install nginx
  • 7. Nginx Installation: • In order to setup high availability , we need both servers to serve the same content. • We will use Nginx to indicate that the two servers are serving our requests at any given time. • Let’s change the default index.html page on each of our hosts by opening the below file. $ sudo vim /usr/share/nginx/html/index.html
  • 8. Nginx Installation: • On your first server, replace or append the contents of the file with below lines. Primary Node • On your second server, replace or append the contents of the file with below contents and save your changes using :wq! . Secondary Node
  • 9. Build and Install Keepalived: • Now install the keepalived daemon on both servers. • There is a version of keepalived in Ubuntu’s default repositories, which is outdated and suffers from a few bugs that might prevent our configuration from working. • We will install the latest version of keepalived from source after installing the dependencies needed to build the software using the command below. $ sudo apt-get install build-essential libssl-dev
  • 10. Build and Install Keepalived: • Once the dependencies are in place, we can download the tarball for keepalived by visiting Official Keepalive download page to find the latest version of the software.
  • 11. Build and Install Keepalived: • Just right-click on the latest version and copy the link address to download this package on your server using wget on your system. $ wget http://www.keepalived.org/software/keepalived-1.2.23.tar.gz • After downloading, extract the archive using tar and move into the extracted folder using below commands. $ tar -zxf keepalived-1.2.23.tar.gz $ cd keepalived-1.2.23
  • 12. Build and Install Keepalived: • Now compile and install the keepalived package by flowing the commands below. $ ./configure
  • 13. Build and Install Keepalived: • Your system will be compiled by showing the configuration parameters like below. Keepalived configuration ------------------------ Keepalived version : 1.2.23 Compiler : gcc Compiler flags : -g -O2 Extra Lib : -lssl -lcrypto –l crypt Use IPVS Framework : Yes IPVS sync daemon support : Yes IPVS use libnl : No fwmark socket support : Yes Use VRRP Framework : Yes Use VRRP VMAC : Yes Use VRRP authentication : Yes SNMP keepalived support : No SNMP checker support : No SNMP RFCv2 support : No SNMP RFCv3 support : No SHA1 support : No Use Debug flags : No Memory alloc check : No libnl version : None Use IPv4 devconf : No Use libiptc : No Use libipset : No ubuntu@ubuntu-16:~/keepalived-1.2.23$
  • 14. Build and Install Keepalived: • Now it’s time to install keepalived, let run the below command and we have all done for the next step. $ make $ sudo make install
  • 15. Setting up Upstart Script for Keepalived: • After installation of keepalived, we are going to create a simple Upstart script to handle our keepalived service by creating a new keepalived.conf file within the /etc/init directory to get started. • Let’s open the file using any of your editor and then specify the run levels in which the service should be started and stopped. We want this service to be active in all normal conditions (runlevels 2-5) and stopped for all other runlevels (when reboot, poweroff, or single-user mode is initiated, for instance). So add the below entries in it starting with its description. $ sudo vim /etc/init/keepalived.conf description "load-balancing and high-availability service” start on runlevel [2345] stop on runlevel [!2345]
  • 16. Setting up Upstart Script for Keepalived: Since the service is integral to ensuring our web service remains available, we want to restart this service in the event of any failure. for that we need to specify the actual exec line that will start the service by adding the --dont-fork option so that Upstart can track the pid correctly. respawn exec /usr/local/sbin/keepalived --dont-fork
  • 17. Setting up Upstart Script for Keepalived: Here is the image view of the full configurations shown below, now save and close the file to move ahead.
  • 18. Setup Keepalived Configuration: • The keepalived service looks for its configuration files in the /etc/keepalived directory. • For this purpose we need to create a directory on both of your servers by using below commands. $ sudo mkdir -p /etc/keepalived
  • 19. Setup Keepalived Configuration: • Now before we create the configuration file, find the private IP addresses of both of your servers. • This can be found with the iproute2 tools by typing below command. $ ip -4 addr show dev ens3 • Copy this value from both of your systems as we will need to reference these addresses inside of our configuration files below.
  • 20. Configuring Primary Server: • On your primary server, create the main keepalived configuration file. The daemon looks for a file called keepalived.conf inside of the /etc/keepalived directory with below command and put the following contents in it. $ sudo vim /etc/keepalived/keepalived.conf vrr_script chk_nginx { script "pidof nginx” interval 2 }
  • 21. Configuring Primary Server: • Then open a block called vrrp_instance which is the main configuration section that defines the way that keepalived will implement high availability. • Then assign an ID for this cluster group that will be shared by both nodes. • We also set up some simple authentication for our keepalived daemons to communicate with one another. • After that we will tell keepalived to use the routine we created at the top of the file, labeled chk_nginx, to determine the health of the local system.
  • 22. Configuring Primary Server: • So the overall primary configuration should look like below. vrrp_script chk_nginx { script "pidof nginx” interval 2 } vrrp_instance VI_1 { interface ens3 state MASTER priority 200 virtual_router_id 44 unicast_src_ip primary_private_IP unicast_peer { secondary_private_IP } authentication { auth_type PASS auth_pass password } track_script { chk_nginx } notify_master /etc/keepalived/master.sh }
  • 23. Now save the Primary server’s configuration and move to the Secondary server’s configurations file setup.
  • 24. Configuring Secondary Server: • In our secondary server, we will create the companion script on our secondary server by creating file at /etc/keepalived/keepalived.conf on it. • The most of the configurations will be similar to our Primary server’s configurations file. • Just make sure to update the proper parameters for state, priority, unicast_src_ip and unicast_peer. • And your final secondary server configuration files should be like as shown below.
  • 25. Configuring Secondary Server: vrrp_script chk_nginx { script "pidof nginx” interval 2 } vrrp_instance VI_1 { interface ens3 state BACKUP priority 100 virtual_router_id 33 unicast_src_ip secondary_private_IP unicast_peer { primary_private_IP } authentication { auth_type PASS auth_pass password } track_script { chk_nginx } notify_master /etc/keepalived/master.sh }
  • 26. Configuring Secondary Server: Save the configuration file after making required changes and move to the next step.
  • 27. Setup Floating IP • Here we need to create and assign a floating IP address to the current node whenever the local keepalived instance becomes the master server. • The floating IP can assigned from the Vexxhost cloud portal to your working node. Just Login to the portal and click on “Floating IPS” and then click to create new Floating IP and then Assign it to your desired server as shown below.
  • 28.
  • 29. Once you have assigned the Floating IP then if you visit the floating IP in your web browser, you should see your “Primary Server Node” index.html page.
  • 30. Starting Keepalived and Testing Failover: • As we setup the floating IP to one or our master node. Now we can start the service on both of our machines by issuing the below commands. $ sudo systemctl start keepalived • The service should start up on each server and contact its peer, authenticating with the shared secret we configured. Each daemon will monitor the local Nginx process and will listen to signals from the remote keepalived process. • So, if you visit by opening your web browser by flowing the floating IP address then we will see the Nginx page of your Primary web server.
  • 31. Starting Keepalived and Testing Failover: • Now, can test the failover of our configuration. • The failover should occur the Nginx health check on the primary server indicates that Nginx is no longer running. • In this case, the primary server’s keepalived daemon will enter the “fault” state. • It will notify the secondary server that it should transition to the master state and claim the floating IP. • Or when the secondary server loses its keepalived connection to the primary server. • If the secondary server cannot reach the primary server for any reason, it will transition to the “master” state and attempt to claim the floating IP.
  • 32. Starting Keepalived and Testing Failover: • We can test the first condition by stopping the Nginx service on the primary server. Primary-Node$sudo service nginx stop • Now refresh your web browser, you might initially get a response indicating that the page is not available, but after a while, you will see the Nginx web page of your Secondary server node. • If you refresh the page again, you will find that the primary server has reclaimed ownership of the floating IP again.
  • 33. Conclusion: • That’s it, we have successfully installed and setup Highly Available Web Servers with Keepalived and Floating IP on primary and secondary Ubuntu 16.04 nodes. • As you can see, for a simple IP failover, keepalived is much simpler than corosync/pacemaker to set up. • So, i hope you have got this article much helpful and interesting. • If you still found and issue or need to post your suggestions then you are more than welcome to share your contributions in the comments section. https://vexxhost.com/