Tabla de contenido
Nowadays, the uninterrupted availability of digital services is an indispensable requirement for businesses and developers. Whether you manage a business-critical website or an essential application, having a robust high availability strategy is crucial. In this article, we will delve into how to achieve this using Keepalived on Ubuntu 22.04, focusing especially on the configuration of multiple Virtual IP addresses (VIP).
Understanding Keepalived and VRRP
Keepalived is a software solution that relies on the VRRP (Virtual Router Redundancy Protocol) to create high availability systems. It provides a mechanism for servers to back each other up, so that if one fails, another can automatically take its place, ensuring service continuity.
Installing Keepalived on Ubuntu 22.04
Before starting the configuration of the virtual IP addresses, it is necessary to install Keepalived on your Ubuntu 22.04 system. You can do this by following these simple steps:
Update your system: Before installing any packages, make sure your system is updated:
sudo apt update && sudo apt upgrade -y
Install Keepalived:
Now, install Keepalived using the APT package manager:
sudo apt install keepalived -y
Basic Configuration
The first thing you have to do is navigate to the main configuration file:
sudo nano /etc/keepalived/keepalived.conf
Once inside, start configuring the VRRP instance. Imagine you want to establish high availability between two servers, A and B. Server A will be the primary and B the backup.
vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 50 priority 100 advert_int 1 virtual_ipaddress { 192.168.1.100 } }
Here, server A is configured to be the MASTER and the virtual IP that both servers will share is 192.168.1.100.
Adjust Configuration for Server B
On server B, the configuration would be almost identical, with the only difference being that the state would be BACKUP and the priority would be a lower number, say 50.
This ensures that server A is always the primary, unless it fails. In that case, server B will take control.
Configuring Multiple VIPs on a Single Interface
Once Keepalived is installed, it’s time to move on to configuration. The ability to handle multiple VIPs is one of the most powerful features of Keepalived.
If you want to have several virtual IP addresses assigned to a single network interface, you can do so by adding multiple entries under virtual_ipaddress in your keepalived.conf configuration file.
Edit the Configuration File:
sudo nano /etc/keepalived/keepalived.conf
Add Your Configuration:
Here is an example of how to configure multiple VIPs on a single interface:
vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 virtual_ipaddress { 192.168.1.100 192.168.1.101 192.168.1.102 } }
In this example, three virtual IP addresses have been configured on the eth0 interface.
Configuring a VIP per Interface
If you prefer to have a virtual IP address assigned to different interfaces, you will need to create multiple VRRP instances.
Edit the configuration file:
sudo nano /etc/keepalived/keepalived.conf
Add Your Configuration:
Here is an example of how to configure a VIP per interface:
vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 52 priority 100 advert_int 1 virtual_ipaddress { 192.168.1.100 } } vrrp_instance VI_2 { state MASTER interface eth1 virtual_router_id 53 priority 100 advert_int 1 virtual_ipaddress { 192.168.2.100 } }
In this example, a VIP has been assigned to the eth0 interface and another VIP to the eth1 interface.
Restart Keepalived to Apply Changes
After making changes to the configuration file, it is necessary to restart the Keepalived service to apply the changes:
sudo systemctl restart keepalived
And to ensure it starts with the system:
sudo systemctl enable keepalived
Verification and Monitoring
Now that everything is set up, it is important to verify that everything is working as expected and to maintain constant monitoring.
Check the Service Status:
sudo systemctl status keepalived
Check the Logs
The logs will provide you with valuable information about the behavior of Keepalived:
sudo journalctl -u keepalived
Benefits of Using Keepalived for Multiple VIPs
By using Keepalived to manage multiple VIPs, you get a robust and flexible system that can adapt to the needs of your infrastructure. This not only ensures the availability of your services but also provides a balanced load distribution, which is vital for maintaining optimal performance.
Final Words
High availability is a critical component in today’s IT infrastructure, and tools like Keepalived offer an effective and efficient solution. With its ability to handle multiple VIPs, whether on a single interface or distributed across several interfaces, Keepalived positions itself as an indispensable tool for system administrators and developers looking to ensure the continuity of their digital services.
Therefore, invest time in configuring and understanding Keepalived; your infrastructure will thank you, and your users will enjoy an uninterrupted and reliable service. Go ahead, secure your environment with Keepalived today!