Edited 9 months ago by ExtremeHow Editorial Team
DebianFailoverNetworkingHigh AvailabilityServer SetupLinuxOpen SourceSystem AdministrationCLIIT
This content is available in 7 different language
Configuring failover in Debian can significantly increase the reliability and availability of your system. Failover means the process of automatically switching to a spare or standby system or component upon failure or abnormal termination of the currently active system. This is important in environments where uptime is critical.
In this comprehensive guide, we will explain how to set up network interface failover using a tool called Keepalived. We will go step-by-step to ensure that any reader, regardless of their experience level, can successfully understand and implement failover in their Debian systems.
The concept of failover in computer science ensures that automatic switching to a backup system occurs when a failure or abnormal termination occurs in the active system. This is important in maintaining the availability and reliability of a system. In networking, failover is often related to continuity of service by automatically redirecting requests to a standby network interface.
Over time, many systems have been designed with failover as a key mechanism to avoid downtime, especially in enterprise environments. For such critical setups, configuring failover is inevitable.
Keepalived is a robust and flexible daemon that provides load balancing and highly available networks using VRRP (Virtual Router Redundancy Protocol). Originally designed to provide stable quality failover for Linux systems, Keepalived facilitates environments where high availability is a must. It efficiently manages system failover with minimal downtime.
Using Keepalived in Debian ensures that if one of your nodes goes down, the other is automatically activated, thus continuing to provide service without interruption. Keepalived is therefore a reliable option for configuring a simple yet effective failover setup.
Before we start configuring failover, we need to install Keepalived on the Debian system. Follow these steps:
sudo apt-get update
sudo apt-get install keepalived
The above two commands will update the package list on the system and install the Keepalived package with all the required dependencies.
After installing Keepalived, the next step is to configure it. The Keepalived configuration files are located in the /etc/keepalived/
directory. To set up simple failover, we will mainly work with the keepalived.conf
file.
Open the Keepalived configuration file with your favorite text editor:
sudo nano /etc/keepalived/keepalived.conf
The configuration file is divided into three main sections: Global Definition, VRRP Script, and VRRP Instance. Let's configure each of these sections.
The Global Definitions section is where you set administrative settings for Keepalived. We'll keep it simple for our example, just setting a few basic parameters:
global_defs {
notification_email {
admin@example.com
}
notification_email_from keepalived@example.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEBIAN
}
This configuration sends notification emails to the specified email address. Adjust these email details accordingly by pointing to your server's SMTP server.
The next section is the VRRP script section, which is not often used for simple failover, but is sometimes needed to check additional conditions or conditions before failover. Here is how you can set up the script so that it checks whether the interface has an IP address assigned:
vrrp_script chk_eth0 {
script "ifconfig eth0 | grep 'inet '"
interval 2
}
This script checks on interface eth0
to see if it has an assigned IP address, and this check is repeated every two seconds.
The main part of the Keepalived configuration is in the VRRP instance section. An instance of VRRP can manage a single virtual IP address that runs on a switch network interface. Here is a sample configuration:
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass secret
}
virtual_ipaddress {
192.168.1.100
}
}
Here's a description of what each line represents:
Once the configuration is complete, start the Keepalived service on both the master and backup machines.
sudo systemctl start keepalived
sudo systemctl enable keepalived
Test the failover by disconnecting the network cable from the master machine. Note that the virtual IP will automatically switch to the backup machine, maintaining service continuity. You can reconnect to the network to see if it already becomes the master, as intended.
For effective failover monitoring, you can use log files to observe Keepalived operations. Logs are typically located in /var/log/syslog
. Use the following command to view the logs for troubleshooting:
tail -f /var/log/syslog | grep Keepalived
This command will print Keepalived-specific logs in real-time, helping to diagnose problems related to your configuration or general performance monitoring.
In this detailed guide, we have explored how to configure failover on a Debian system using Keepalived. We walked through the installation process, explained the sections in the Keepalived configuration file, and provided testing steps to ensure that failover works as expected. In addition, monitoring techniques were discussed to ensure any failover issues are promptly identified and corrected.
Setting up failover may initially seem complicated, yet it can significantly increase the stability and reliability of your network services, making it a worthwhile endeavor for system administrators.
If you find anything wrong with the article content, you can