DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Zero Trust for AWS NLBs: Why It Matters and How to Do It
  • A Guide to Microservices Deployment: Elastic Beanstalk vs Manual Setup
  • A Deep Dive on Read Your Own Writes Consistency
  • Mastering Load Balancers: Optimizing Traffic for High Availability and Performance

Trending

  • Rethinking Recruitment: A Journey Through Hiring Practices
  • Docker Model Runner: Streamlining AI Deployment for Developers
  • Create Your Own AI-Powered Virtual Tutor: An Easy Tutorial
  • AI Meets Vector Databases: Redefining Data Retrieval in the Age of Intelligence
  1. DZone
  2. Software Design and Architecture
  3. Performance
  4. How to Configure Tomcat/JBoss and Apache HTTPD for Load Balancing and Failover

How to Configure Tomcat/JBoss and Apache HTTPD for Load Balancing and Failover

By 
Faheem Sohail user avatar
Faheem Sohail
·
Feb. 07, 14 · Interview
Likes (0)
Comment
Save
Tweet
Share
27.7K Views

Join the DZone community and get the full member experience.

Join For Free

In this post we will see how to setup a load balanced JBoss or Tomcat environment with the fail-over capability.

This post assumes that both Jboss/Tomcat and Apache httpd are setup and running properly.

Configure Apache Httpd

Step 1: Configure apache’s workers.properties

Go to /usr/local/apache2/conf/extra and open workers.properties and configure the properties indicated in bold.

# for mapping requests
# The configuration directives are valid
# for the mod_jk version 1.2.18 and later
#
worker.list=loadbalancer,status

# Define node
# modify the host as your host IP or DNS name.

worker.node.port=8009
worker.node.host=192.168.0.3 #(IP or DNS name of the server on which Jboss is running)
worker.node.type=ajp13
worker.node.lbfactor=1

worker.node2.port=8009
worker.node2.host=192.168.0.4 #(IP or DNS name of the server on which Jboss is running)
worker.node2.type=ajp13
worker.node2.lbfactor=1

# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node,node2
worker.loadbalancer.sticky_session=1
worker.status.type=status

The property balance_workers is used to specify the nodes to load balance. For example, if we specify only ‘node’, all requests will be routed to the server named ‘node’. Modify this to test that requests are going to both servers.

Step 2: Configure mod-jk.conf

Go to /usr/local/apache2/conf/extra and open mod-jk.conf and configure the bold properties according to your requirements.

#Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
JkWorkersFile conf/extra/workers.properties

# Where to put jk logs
JkLogFile /var/apache/logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel debug

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicates to send SSK KEY SIZE
# Note: Changed from +ForwardURICompat.
# See http://tomcat.apache.org/security-jk.html
JkOptions +ForwardKeySize +ForwardURICompatUnparsed -ForwardDirectories
JkOptions +FlushPackets
# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"

# Mount your applications
JkMount /* loadbalancer

# You can use external file for mount points.
# It will be checked for updates each 60 seconds.
# The format of the file is: /url=worker
# /examples/*=loadbalancer
JkMountFile conf/extra/uriworkermap.properties

# Add shared memory.
# This directive is present with 1.2.10 and
# later versions of mod_jk, and is needed for
# for load balancing to work properly
# Note: Replaced JkShmFile logs/jk.shm due to SELinux issues. Refer to
# https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=225452
JkShmFile /var/run/jk.shm

# Add jkstatus for managing runtime data
<Location /jkstatus/>
  JkMount status
  Order deny,allow
  Deny from all
  Allow from 127.0.0.1
</Location>

The JkMount /* loadbalancer indicates that all requests are to be routed through the load balancer.

Step 3: Go to /usr/local/apache2/conf and edit httpd.conf

Add

Include conf/extra/mod-jk.conf

to the end of the file.

Configure Tomcat/JBoss

These settings need to be made for each of the nodes we intend on placing behind the load balancer.

We need to modify the server.xml file which is located at

  • For Tomcat
    • ../apache-tomcat/conf/
  • For JBoss
    • ../jboss-5.1.0.GA/server/default/deploy/jbossweb.sar 

Edit the following tag:

<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node">

where the jvmRoute attribute is configured to ‘node’ (which is the name we gave the first worker while configuring workers.properties.)

Next, locate the following tag and edit the port to be the same as while configuring the workers.properties.

<Connector protocol="AJP/1.3" port="8009" address="${jboss.bind.address}" redirectPort="8443" />

Configure the other node(s) accordingly.

Next, Start Apache httpd and the Jboss/tomcat node(s) that you  have configured.



Load balancing (computing)

Published at DZone with permission of Faheem Sohail, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Zero Trust for AWS NLBs: Why It Matters and How to Do It
  • A Guide to Microservices Deployment: Elastic Beanstalk vs Manual Setup
  • A Deep Dive on Read Your Own Writes Consistency
  • Mastering Load Balancers: Optimizing Traffic for High Availability and Performance

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!