Modern technology gives us many things.

How to Utilize Load Balancing in RHEL7

0 208

Load Balancing in RHEL7

Yesterday I was going through various features in Amazon AWS and this topic caught my eye. It was about load balancers. According to Amazon, “load balancing is a method for distributing incoming HTTP requests for a web application onto multiple web servers.” Hmm. Interesting. So you have to pay almost around $0.50/hour to have your web application distributed over multiple servers to manage the huge amount of load at a certain amount of time on a certain day. It got my attention and I thought what if I wanna do it on my own. So I spent rest of the day into researching and reading lot of articles around the web. Finally, at the night, it was the time to try everything that I’ve learned out and eventually save $0.50/hour :p

In this scenario, I’ll be hosting a simple web application (probably just one HTML page with analytics to monitor) and I will be managing load sent out over to it using LOIC (Low Orbit Ion Cannon) a really famous tool for DDoS.

Preparations:

  1. An HTML Page with live analytics built in. (Consider this as a live app)
  2. An RHEL7 Server (to host the page and utilize load balancer)
  3. Knowledge of basic system administration

[If you’re not familiar with command line then you must know these 15 commands to start with https://www.malc0de.org/top-15-must-know-cli-commands-for-every-linux-user/]

So to begin with I’ve taken a complete out of the box RHEL7 server OS and installed Apache HTTPD on it. After that, I’ve created my magical HTML page and downloaded it in “/var/www/html/index.html” path.

To check, I opened up the firefox and in the URL section inserted the IP address of RHEL server and tada! My one-page application was live!

It’s time to make the web application persistent even after the reboot. Create a new file and add following entry into it. If you don’t know how just do this:

# vim /etc/httpd/conf.d/mynewfile.conf

Press i and type the following

persistance web host - load balancer configuration

# systemctl restart httpd && systemctl enable httpd

And you’re done! So far you’ve created your own web server and hosted your own web application into it. It’s time to set up load balancers for a maximum live time period at the time of peak load.

You can try this tutorial over your cloud, virtual hosts and physical servers since it works for all and helps a lot into managing service availability to your visitors.

For this purpose, we’ll be needed two NIC cards if we’re using only one server in our local environment to host our web application. If you’re in the enterprise than I would suggest to follow the same procedure with two or more machines to separate the load on various servers.

The benefit of managing the load on various servers is that if one server goes down, other servers can provide the web application without any issues.

Anyway, let’s start with load balancers. So what actually are load balancers and what are its different algorithms that we’re going to look at. There’s a really good definition that defines load balancers by Nginx,

“A load balancer acts as the “traffic cop” sitting in front of your servers and routing client requests across all servers capable of fulfilling those requests in a manner that maximizes speed and capacity utilization and ensures that no one server is overworked, which could degrade performance. If a single server goes down, the load balancer redirects traffic to the remaining online servers. When a new server is added to the server group, the load balancer automatically starts to send requests to it.”

Let’s look at how could we implement load balancing algorithms on our RHEL 7 Server. So if you’re familiar with working with RHEL you must have heard about Network Teaming, “a method for linking NICs together logically to allow for failover or higher throughput.”

RHEL7 use software called runners to implement load balancing and active-backup logic. The “runners” are interchangeably known as “load balancing algorithms”.

Types of load balancing algorithms available in RHEL7:

Broadcast: Transmits each package from all ports.
Round-Robin: Requests are transmitted across the group of servers sequentially.
Active backup: A failover algorithm that watches for link changes and selects an active port for data transfer.
Load Balance: Algorithm monitors traffic and uses a hash function to try to reach to a perfect port selection.
Lacp: Implements the 802.3ad Link Aggregation Control Protocol.

We’ll discuss all these algorithms later. Right now, we’re dealing with a situation where our web server is receiving a high amount of traffic that we like to separate on multiple NIC’s for providing high availability and flexibility.

The algorithm that I am going to choose for this purpose is activebackup. Since if one of my NIC cards goes down the other could serve the traffic relentlessly. Tip: If you’re doing this with multiple machines than I would suggest to go with either roundrobin or loadbalance.

load balancing
Round Robin algorithm serving equal tasks to all the servers at a time.

The benefit of round robin algorithms is that it distributes traffic evenly on all servers in the cluster but I was kind of thinking about that since all the servers in a cluster are going to receive a similar amount of traffic to serve for. All has equal chances of going down and hence this solution won’t be reliable.

Anyways, back to our topic. Now we’ve chosen a best algorithm for our purpose. To implement, however, follow the steps below:

We’re going to add a team which will handle logic and interface processing in RHEL.
# nmcli con add type team con-name team1 ifname team ‘{“runner”: {“name”: “activebackup”}}’

2. Now give an IP address to your newly created team interface. If you’ve already setted up DHCP before committing this practical than this step is optional.

# nmcli con mod team1 ipv4.addresses 192.168.1.10/24 ipv4.method manual

3. Time to assign the NIC cards which will be incharge to server web application.
Check the interface names of your NIC cards using # ip addr
For me, it was eno1 for NIC 1 and eno2 for NIC 2.

# nmcli con add type team-slave con-name team1-nic1 ifname eno1 master team1
# nmcli con add type team-slave con-name team1-nic2 ifname eno2 master team1

4. Restart and enable the teamd service in order to make it persistent even at boot time and make changes successfully.

# systemctl restart teamd && systemctl enable teamd

5. Now let’s check that state of our newly configured activebackup algorithm.

# teamdctl team1 state

Output:

Setup:
Runner: activebackup
Ports:
Eno1
Link watches:
Link summary: up
Instance[link_watch_0]:
Name: ethtool
Link: up
Eno2
Link watches:
Link summary: up
Instance[link_watch_0]:
Name: ethtool
Link: up
Runner:
Active port: eno1

However, LOIC did no damage as I expected since both the NIC’s were virtual and that amount of load haven’t affected it. So i’ve tried another method which was about disconnecting NICs to check if the algorithms is doing its work or not. So what I did is i’ve disconnected the NIC1 and returned the output which was like this:

# nmcli dev dis eno1
# teamdctl team1 state

Output:

Setup:
Runner: activebackup
Ports:
Eno1
Link watches:
Link summary: up
Instance[link_watch_0]:
Name: ethtool
Link: up
Active port: eno2

See? How beautifully the load balancing algorithms changed the link for reliable page serve. Now, bringing back the eno1 gives exact same output as before and it puts active port as eno1 back again. To start the NIC back again:

# nmcli con up team1-port1
# teamdctl team1 state

Output:

Setup:
Runner: activebackup
Ports:
Eno1
Link watches:
Link summary: up
Instance[link_watch_0]:
Name: ethtool
Link: up
Eno2
Link watches:
Link summary: up
Instance[link_watch_0]:
Name: ethtool
Link: up
Runner:
Active port: eno1

See? It’s that easy and you’ve just learned to save $0.50/hour. Next time we’ll be discussing about roundrobin specifically to see its pros and cons on live working environments. If you liked my article to share and give your feedback and requests in the comment section and donate to malc0de if you can.


Recommended Read

  1. No More Ransom: New Free Decryption Tools Available
  2. Commodity Ransomware Is Here
  3. RoT: Ransomware of Things
  4. Probably Everything You Need to Know About WannaCry Ransomware Organised Chronologically
  5. Intriguing Career Opportunities in Data Science for Freshers
  6. Top 10 Best Command Line Networking Utilities in Windows
  7. List of 7 Best Anti-Ransomware Tools to Protect You
  8. 7 Best Tips for Choosing the Best Data Backup Tools
  9. 4 Ways Big Businesses Can Protect Their Data
  10. Top 15 must-know CLI commands for every Linux user.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.