• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

How to Configure Load Balancer in Apache

833

To configure Load Balancer in Apache Webserver

Load Balancer manages the high network traffic in web services by distributing the workload. It is especially used to utilize the resources, avoid overload and maximize throughput. The Load Balancer can be configured in Apache web-server itself. This article explains the configuration of Load Balancer in Apache.

Testing Environment

Load Balancer:

IP Address &ndash 192.168.5.157
Hostname - lb.example.com

WebServer 1:

IP Address &ndash 192.168.5.158
Hostname - ws1.example.com

WebServer 2:

IP Address &ndash 192.168.5.159
Hostname &ndash ws2.example.com

Create some entry in the file /etc/hosts in all the three machines for hostname resolution.

Entry:

192.168.5.157 lb.example.com lb
192.168.5.158 ws1.example.com ws1
192.168.5.159 ws2.example.com ws2

Note: The Host file entry is not required, if you have DNS Server.


To configure Load Balancer in Apache

Here we have one load balancer and two web servers. First you need to configure the load balancer and then web servers. Then run the following steps on both the webservers.


To install Apache

Utilize the below command to install Apache package on both web servers.

[root@ws1 ~]# yum install httpd -y
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:01
updates | 3.4 kB 00:00:00
(1/2): extras/7/x86_64/primary_db | 166 kB 00:00:01
(2/2): updates/7/x86_64/primary_db | 9.1 MB 00:00:27
Determining fastest mirrors
* base: centos.excellmedia.net
* extras: centos.excellmedia.net
* updates: centos.excellmedia.net
Resolving Dependencies
-->  Running transaction check
.
.
.
httpd.x86_64 0:2.4.6-40.el7.centos.4

Dependency Installed:
apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-40.el7.centos.4 mailcap.noarch 0:2.1.41-2.el7

Complete!

Once the Apache is installed, start the service and configure firewall.

[root@ws1 ~]# systemctl start httpd
[root@ws1 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@ws1 ~]# firewall-cmd --permanent --add-service=http
success
[root@ws1 ~]# firewall-cmd &ndash reload
success

Now place the default file ' index.html' for the web servers and enter any content to that file.

[root@ws1 ~]# vim /var/www/html/index.html


To configure Load Balancer

Run the following command to install the Apache package on load balancer machine.

[root@lb ~]# yum install httpd -y
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/2): extras/7/x86_64/primary_db | 166 kB 00:00:03
(2/2): updates/7/x86_64/primary_db | 9.1 MB 00:00:30
Determining fastest mirrors
* base: centos.excellmedia.net
.
.
.
Installed:
httpd.x86_64 0:2.4.6-40.el7.centos.4

Dependency Installed:
apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-40.el7.centos.4 mailcap.noarch 0:2.1.41-2.el7

Complete!

Once the Apache is installed in Load balancer, start the service and configure the firewall.

[root@lb ~]# systemctl start httpd
[root@lb ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@lb ~]# firewall-cmd --permanent --add-service=http
success
[root@lb ~]# firewall-cmd --reload
Success

Now its time to create new Apache configuration file in the ' conf.d' directory.

[root@lb ~]# cd /etc/httpd/conf.d
[root@lb conf.d]# vim lb.conf

ProxyRequests off
< Proxy balancer://linuxhelp> 
BalancerMember http://192.168.5.158:80
BalancerMember http://192.168.5.159:80
ProxySet lbmethod=byrequests
< /Proxy> 

< Location /balancer-manager> 
SetHandler balancer-manager
< /Location> 

ProxyPass /balancer-manager !
ProxyPass / balancer://linuxhelp/

Replace the content with your webserver' s IP address and Load balancer name as linuxhelp.

Restart the apache service with the following command.

[root@lb ~]# systemctl restart httpd

Finally open the browser and point to load balancer IP address. It displays the content from any of your configured web server.

Load-Balancer-open

Tags:
cameron
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

how to configure nginx load balancer ?

A

To configure nginx load balancer follow this link : " https://www.linuxhelp.com/how-to-configure-nginx-load-balancer-ubuntu/ "

Q

How to install CROSSROADS Load Balancer ?

A

To install CROSSROADS Load Balancer follow this Link : " https://www.linuxhelp.com/set-xr-crossroads-load-balancer-linux/ "

Q

is it possible to configure HAProxy Load Balancer in Nginx?

A

Yes it is possible

follow this link : "https://www.linuxhelp.com/how-to-configure-load-balancer-with-haproxy-for-nginx-in-centos/ "

Q

how to install HAPROXY ?

A

follow this link : "https://www.linuxhelp.com/install-haproxy-load-balancer-ubuntu/" to install HAPROXY

Q

How to install Apache from command line while configuring Load Balancer in Apache

A

to install Apache from command line while configuring Load Balancer in Apache use the following command

#yum install httpd -y

Related Tutorials in How to Configure Load Balancer in Apache

Related Tutorials in How to Configure Load Balancer in Apache

How to install Apache from Source Code on CentOS 7
How to install Apache from Source Code on CentOS 7
Oct 21, 2017
How to Completely Remove and Install Apache package on CentOS 7.6
How to Completely Remove and Install Apache package on CentOS 7.6
May 23, 2019
How to Configure Nginx as a Reverse Proxy in CentOS
How to Configure Nginx as a Reverse Proxy in CentOS
Nov 26, 2016
How to install apache jmeter on ubuntu 18.04
How to install apache jmeter on ubuntu 18.04
May 19, 2018
How to Install Pligg - Content Management System
How to Install Pligg - Content Management System
Jul 26, 2016
How to Configure HAproxy Load Balancer with Keepalived in CentOS
How to Configure HAproxy Load Balancer with Keepalived in CentOS
Nov 21, 2016
How to enable the Apache server-status on centos 7
How to enable the Apache server-status on centos 7
Jan 28, 2019
How to Create Ansible Playbook to Install Apache Server
How to Create Ansible Playbook to Install Apache Server
May 12, 2021

Related Forums in How to Configure Load Balancer in Apache

Related Forums in How to Configure Load Balancer in Apache

CentOS
connor class=
How To Completely Remove Apache package On CentOS 7.6
May 14, 2019
Web Server
jacob class=
How to remove httpd completely from server
Apr 7, 2017
Apache
isaac class=
How to disable apache welcome page on Ubuntu
Dec 15, 2018
Apache
rebeccajazz class=
Apache2 : mod_proxy in opensuse
Jan 3, 2018
Apache
elijah class=
What is the difference between httpd and apache
Feb 18, 2017
Apache
logan class=
How to install Apache GUI
Feb 24, 2017
Apache
rolando class=
How to find apache user in opensuse
Sep 23, 2017
Web Server
wahab00727 class=
How to install Elastix PBX?
Dec 3, 2019

Related News in How to Configure Load Balancer in Apache

Related News in How to Configure Load Balancer in Apache

Attackers take advantage of Apache Struts vulnerabilities
Attackers take advantage of Apache Struts vulnerabilities
Mar 17, 2017
PHP7 bugs used by hackers to remotely hijack web servers
PHP7 bugs used by hackers to remotely hijack web servers
Nov 5, 2019
An Apache Web Server Bug That Grants Root Access on  Shared Web Hosts
An Apache Web Server Bug That Grants Root Access on Shared Web Hosts
Apr 10, 2019
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help keel johnston ?
Unhide the folders on windows Explorer

Give any solutions to unhide folder using command prompt?

forum3

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.