JBOSS via Apache Load Balancing method one: Using MOD_JK
In the first to second section of this article, we use Apache in the Linux environment and the front end of Windows to realize load balancing using IIS through AJP protocol and back-end jboss communication, and the corresponding parameters are explained in the third section.
First, Linux Environment Apache + mod_jk + JBOSS
Apache and JBoss Use the AJP protocol to communicate using port 8009 via MOD_JK.
- 1. Install and configure Apache
Download the Apache code package and upload it to the server.
Unlocking the Code package
[[email protected] app] #cd/opt/app
[[email protected] app] #tar-ZXVF httpd-2.2.23.tar.gz
[[email protected] app] #cd/opt/app/httpd-2.2.23
in [[email protected] httpd-2.2.23] #下编译
./configure-prefix=/usr/local/apache2-enable-module=so-enable-module=setenvif-enable-module=rewrite- Enable-rewrite=shared-enable-proxy=shared-with-mpm=prefork-enable-so-enable-auth-anon-enable-file-cache=shared -enable-cache=shared-enable-disk-cache=shared-enable-mem-cache=shared
Make clean
Make
Make install
Modify the configuration. In this case, the listening port for the service is 8090, please modify it according to the actual situation.
Vi/usr/local/apache2/conf/httpd.conf
Change Listen 80 to listen 8090
change user daemon and group daemon to user Apache and group Apache
Delete # before ServerName, change the line to ServerName 172.18.49.181:8090
Adding users and user groups
Groupadd Apache
Useradd apache–g Apache
Apache MOD_JK Configuration
Download MOD_JK, rename it to mod_jk.so, copy it to/usr/local/apache2/modules
Download path for MOD_JK: http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/
chmod +x/usr/local/apache2/modules/mod_jk.so
Add at the end of the/usr/local/apache2/conf/httpd.conf:
Include conf/mod_jk.conf
Create an empty file/usr/local/apache2/conf/uriworkermap.properties
Vi/usr/local/apache2/conf/mod_jk.conf Enter the following:
_____________________________________________________________________
# 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/workers.properties
# Where to put JK logs
Jklogfile Logs/mod_jk.log
# Set the JK log level [Debug/error/info]
Jkloglevel Info
# Select the log format
Jklogstampformat "[%a%b%d%h:%m:%s%Y]"
# jkoptions indicates to send SSK KEY SIZE
Jkoptions +forwardkeysize +forwarduricompat-forwarddirectories
# Jkrequestlogformat
Jkrequestlogformat "%w%V%T"
# Mount Your applications
Jkmount/* LoadBalancer
# you can use the external file for mount points.
# It'll be checked for updates each seconds.
# The format of the file is:/url=worker
#/examples/*=loadbalancer
Jkmountfile conf/uriworkermap.properties
# ADD shared memory.
# This directive are present with 1.2.10 and
# later versions of MOD_JK, and is needed for
# for the load balancing to work properly
Jkshmfile LOGS/JK.SHM
# ADD Jkstatus for managing runtime data
<Location/jkstatus/>
Jkmount status
Order Deny,allow
Deny from all
Allow from 172.18.49.181
</Location>
____________________________________________________________________________
Vi/usr/local/apache2/conf/workers.properties, add the following:
_______________________________________________
# Define List of workers that'll be used
# for mapping requests
Worker.list=loadbalancer
# Define Node1
# Modify the host as your host IP or DNS name.
worker.node1.port=8009
worker.node1.host=172.18.49.183
Worker.node1.type=ajp13
Worker.node1.lbfactor=1
worker.node1.connection_pool_timeout=600
#worker. node1.connection_pool_size=500
#worker. node1.connection_pool_minsize=250
Worker.node1.socket_timeout=5
# Define Node2
# Modify the host as your host IP or DNS name.
worker.node2.port=8009
worker.node2.host=172.18.49.184
Worker.node2.type=ajp13
Worker.node2.lbfactor=1
worker.node2.connection_pool_timeout=600
#worker. node2.connection_pool_size=500
#worker. node2.connection_pool_minsize=250
Worker.node2.socket_timeout=5
# load-balancing behaviour
Worker.loadbalancer.type=lb
Worker.loadbalancer.balance_workers=node1,node2
____________________________________________________
If there are more nodes, the order defines more node segments and is all listed after worker.loadbalancer.balance_workers.
The lbfactor is the load distribution weight, and the larger the value, the more load is allocated.
Configure Apache Auto-start
Ln–s/usr/local/apache2/bin/apachectl/etc/init.d/apache
chmod 777/etc/init.d/apache
Ln–s/etc/init.d/apache/etc/rc3.d/s80apache
Ln–s/etc/init.d/apache/etc/rc3.d/k20apache
Ln–s/etc/init.d/apache/etc/rc4.d/s80apache
Ln–s/etc/init.d/apache/etc/rc4.d/k20apache
Ln–s/etc/init.d/apache/etc/rc5.d/s80apache
Ln–s/etc/init.d/apache/etc/rc5.d/k20apache
- Start Jboss Cluster
Start the Load Balancer Apache first, and then start each JBoss node. The boot order of each JBoss node is not required. For Apache startup, refer to the following:
Executes under the/usr/local/apache2/bin directory./httpd–k Start (Stop command:./httpd–k stop), in/usr/local/apache2/logs/mod_ Jk.log, the following message indicates that Apache has successfully loaded the MOD_JK:
"[Info] init_jk::mod_jk.c (2743): mod_jk/1.2.23 initialized"
If you have MOD_JK-related error messages, it is generally because the version of MOD_JK is incompatible with the Apache version, you need to download the appropriate version on the Apache official website. Checking the presence of 8090 listening ports with netstat indicates that Apache started successfully.
- 3. Load Balancing Experiment
A simple test page is deployed on 172.18.49.183/184, which shows the following:
At this point, enter http://172.18.49.181:8090/cluster_test/in IE, and constantly refreshed, should be alternately appear the following two pages, the load balancer configuration is successful, if you turn off JBoss at 184, each access will only appear in Figure 1, Re-open JBoss on 184 and refresh the access continuously, then Figure 1 and Figure 2 re-alternate display.
Figure 1
Figure 2
Second, Windows environment under IIS + Isapi_redirect + JBOSS
IIS and JBoss use the AJP protocol, which uses port 8009 to enable communication by loading the Isapi_redirect.dll .
- Adding Isapi_redirect related information to the registry
Windows Registry Editor Version 5.00
[Hkey_local_machine\software\wow6432node\apache Software Foundation]
[Hkey_local_machine\software\wow6432node\apache software Foundation\jakarta Isapi Redirector]
[Hkey_local_machine\software\wow6432node\apache software Foundation\jakarta Isapi redirector\1.0]
"Extension_uri" = "/jakarta/isapi_redirect.dll"
"Log_file" = "E:\\ajp\\logs\\isapi_redirect.log"
"Log_level" = "Info"
"Worker_file" = "e:\\ajp\\conf\\workers.properties"
"Worker_mount_file" = "e:\\ajp\\conf\\uriworkermap.properties"
- Add the Workers.properties and uriworkermap.properties files as follows in the registry path, respectively:
Workers.properties content is basically consistent with Linux, just add worker.node1.connection_pool_size=500
worker.node1.connection_pool_minsize=250
worker.node2.connection_pool_size=500
worker.node2.connection_pool_minsize=250
Instead, Uriworkermap.properties needs to add the Web path to the JBoss deployment that you want to access, such as:/*.*=loadbalancer, to access any web on the load of JBoss.
- Load Isapi_redirect.dll in IIS
In IIS Manager, double-click ISAPI and CGI restrictions,
Click Add, select the Isapi_redirect.dll path in the pop-up box, and select Allow extension path
In IIS Manager, double-click the ISAPI filter, click Add, and in the pop-up box, fill in the name "Jakarta", which must be consistent with the registry.
Add a test site to a Web site
Add a virtual directory to your Web site, as shown in the path where the physical path is isapi_redirect.dll.
Double-click handler mappings, edit permissions function, tick "execute"
Edit Isapi-dll, add path
Restart IIS and view the E:\ajp\logs\isapi_redirect.log, if no file is generated, stating Isapi_ Redirect.dll is not loaded correctly, you need to check whether the above steps are wrong, if you can not load the error, try restarting the Windows Server until Isapi_redirect is loaded correctly, Isapi_redirect.log will generate "[ Fri APR 10:03:49.863] [16260:16312] [Emerg] INIT_JK::JK_ISAPI_PLUGIN.C (2867): Unable to read worker file E:\ajp\c Onf\workers.properties. (errno=0, err=no error) "Similar information.
- Verifying load Balancing
Authentication methods participate in the first part of the Linux environment with Apache + MOD_JK + JBoss related content.
Three, parameter description
- Worker.list
Represents a list of names of jboss clusters or other clusters to be loaded by Apache or IIS, separated by commas. This article has only one JBoss cluster, named LoadBalancer.
- WORKER.LOADBALANCER.TYPE=LB, which means the load is used to access the web, if WORKER.LOADBALANCER.TYPE=AJP13, the load is not used.
The worker.loadbalancer.balance_workers=node1,node2 indicates that the cluster has two nodes, namely Node1 and Node2.
- worker.node1.port=8009, this port is the port that JBoss uses AJP protocol to communicate with Apache or IIS and needs to be consistent with the ports in the <socket-binding name= "AJP" in the JBoss configuration file. The default is 8009.
worker.node1.host=172.18.49.183, resolves the address for the DNS of the node's JBoss
WORKER.NODE1.TYPE=AJP13,AJP protocol Type is 1.3
Worker.node1.lbfactor=1, load factor, two nodes are 1, which means 1:1 polling. worker.node1.connection_pool_timeout=600, which means that JK Connector will close the connection to the back-end JBoss After the connection is idle 600s, which must be associated with the "Default_" in the JBoss configuration Connection_timeout "remain consistent.
Worker.node1.connection_pool_size=500, which indicates the maximum number of connections allowed to back-end JBoss, it is important to note that this parameter is not recommended if using Apache because Apache is adaptive to assigning connections.
worker.node1.connection_pool_minsize=250 that indicates the number of idle connections that can be maintained when the resource pool is shrunk, and the official Apache recommendation is half the maximum number of connections. If you use Apache, this parameter is also deprecated.
Worker.node1.socket_timeout=5, which indicates that the timeout for a TCP transport is 5s, and if the parameter is not set, the timeout value is infinity, at which point there may be many dead connections if the network is in poor condition, resulting in low jboss pressure and performance. But if the setting is too small, the JK Connector is too sensitive to the network condition, not only to increase the jboss pressure, but also to mistakenly kill some of the connections that are slightly slower due to network or other reasons. The official recommended value for Apache is 1-5 seconds.
JBoss via Apache Load Balancing method one: Using MOD_JK