Welcome to our guide on how to install and configure LVS (Linux Virtual Server) Load balancer on CentOS 8 and RHEL 8 Linux system. Linux Virtual Server is a highly scalable and highly available server built on a cluster of real servers, with the load balancer running on the Linux operating system.
We’ll install the Linux Virtual Server package on our CentOS 8 / RHEL 8 machine then configure it as a Load balancer to the backend servers. This setup assumes you have installed a CentOS/RHEL 8 server or workstation edition.
Install Linux Virtual Server (LVS on CentOS 8 / RHEL 8
Install Linux Virtual Server (LVS on CentOS 8 / RHEL 8 by running the following commands on your Server.
$ sudo yum install ipvsadm
Last metadata expiration check: 0:11:56 ago on Thu 05 Dec 2019 09:17:32 AM EAT.
Dependencies resolved.
===================================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================================
Installing:
ipvsadm x86_64 1.29-8.el8 AppStream 57 k
Transaction Summary
===================================================================================================================================================
Install 1 Package
Total download size: 57 k
Installed size: 83 k
Is this ok [y/N]: yStep 2: Enable IP forwarding and enable service
After the package installation, enable the service and IP forwarding in your machine.
echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p Confirm it is turned to 1.
$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1Now start the ipvsadm service. The ipvsadm command is used to configure, maintain or inspect the virtual server table in the Linux kernel.
sudo touch /etc/sysconfig/ipvsadm
sudo systemctl enable --now ipvsadm The service status should show as acitve:
$ systemctl status ipvsadm
● ipvsadm.service - Initialise the Linux Virtual Server
Loaded: loaded (/usr/lib/systemd/system/ipvsadm.service; enabled; vendor preset: disabled)
Active: active (exited) since Thu 2019-12-05 09:41:56 EAT; 4s ago
Process: 2949 ExecStart=/bin/bash -c exec /sbin/ipvsadm-restore < /etc/sysconfig/ipvsadm (code=exited, status=0/SUCCESS)
Main PID: 2949 (code=exited, status=0/SUCCESS)
Dec 05 09:41:56 centos8.novalocal systemd[1]: Starting Initialise the Linux Virtual Server...
Dec 05 09:41:56 centos8.novalocal systemd[1]: Started Initialise the Linux Virtual Server.Configure LVS as Load Balancer.
Now that we have installed and started the services required to manage LVS firewall. it’s time to configure LVS as a Load balancer to actual backend applications.
Start by clearing IP table rules
sudo ipvsadm -C Add a virtual service
Add a virtual service by using the syntax:
ipvsadm -A -t (ServiceIP:Port) -s (Distribution method)Distribution methods supported:
- rr : Round Robin – Equal load distribution among backend servers.
- wrr: Weighted Round Robin – Round robin distribution based on real servers weight.
- lc: Least-Connection – Servers with few active jobs are prioritized for new load assignment
- wlc: Weighted Least-Connection – Assign jobs to servers with fewer jobs and relative to the real servers’ weight (Ci/Wi). This is the default distribution method.
We’ll do a configuration based on below diagram.
On LVS Server, I’ll set it to listen on 192.168.122.52 port 80.
sudo ipvsadm -A -t 192.168.122.52:80 -s wlc The add the add the backend servers. The syntax is:
audo ipvsadm -a -t (ServiceIP:Port) -r (BackendServerIP:Port) -mIn my case, my configurations will look similar to below:
sudo ipvsadm -a -t 192.168.122.52:80 -r 192.168.122.178:80 -m
sudo ipvsadm -a -t 192.168.122.52:80 -r 192.168.122.6:80 -m List current rules:
$ sudo ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP cent01:http wlc
-> cent03:http Masq 1 0 0
-> cent02:http Masq 1 0 0 Open http port on the firewall.
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reloadIf you now load the LVS server IP or domain name from the browser, you should get the page on one of the backend servers.
Reload and the backend server 2 page should show.
There you have it on how to install and configure LVS on CentOS 8 and RHEL 8 Linux system.
Also check:
How To Install and Configure HAProxy on Debian 10 (Buster)
Galera Cluster High Availability With HAProxy on Ubuntu 18.04 / CentOS 7



































































