Jk_proxy implements apache + tomcat Load Balancing
Apache + tomcat implements SERVER CLUSTERS
Main reference: http://blog.csdn.net/welun521/article/details/4169879
UseJK_PROXY implementation! The ajp method will be studied in the future, and a document will be provided, to be continued ......!
1. install apache
Main reference: http://llying.iteye.com/blog/335342
Note: The above input must be in the given format. It is best to enter an available email! During the first installation, I did not input the file in the format and the file cannot be started. I had to unload the file and reinstall it. It should be changeable, but I didn't study ^-^!
Ii. tomcat installation
Omitted
Iii. apache configuration
Note: When modifying httpd. conf, it is best to use NotePad to open it. Do not use other edit tools!
This is the conf directory after configuration. During apache configuration, pay special attention to the following. conf is used as a backup, because some strange phenomena are found during the configuration process, and it cannot be used for no reason! Backup is the best. In case of configuration errors, at least the initial state can be restored. This should be the basic cultivation of programmers in various fields. ^_^!
The detailed configuration is as follows:
1. Place the mod_jk-1.2.26-httpd-2.2.4.so under The Apache2/modules directory
2. Create the mod_jk.conf file with the following content:
# Load mod_jk Module LoadModule jk_module modules/mod_jk-1.2.26-httpd-2.2.4.so # specify workers. properties file path JkWorkersFile conf/workers. properties # specify the requests to tomcat for processing, and "controller" is in workers. the specified Server Load balancer controller JkMount/* In propertise /*. jsp controller # If you want to specify *. do also adds one more line when distributing the traffic # JkMount /*. do controller # If you want to distribute all requests, you only need to write JkMount/* controller
Note: It is best to remove annotated Chinese characters in the practical process to prevent errors! (Comment out unnecessary user)
In fact, this file can also be implemented without being added, but it needs to be configured in httpd. conf. In order not to affect the original file, just add one more!
With this file, we only need to add the following in httpd. conf:
Include conf/mod_jk.conf
That's enough. Some of them are added to the end of the file, but I am still used to putting it behind the Include tag!
3. Add the work. properties file under conf. The content is as follows:
Worker. list = controller, worker at1, tomcat2 # server list #======= worker AT1 ======= worker. tomcat1.port = 8009 # ajp13 port number, in tomcat server. xml configuration. The default value is 8009 worker. tomcat1.host = localhost # tomcat host address. If not, enter the IP address worker. tomcat1.type = ajp13 worker. tomcat1.lbfactor = 1 # server's weighted weight. The higher the value, the more requests are allocated. #========= tomcat2 ======= worker. tomcat2.port = 8109 # ajp13 port number, in tomcat server. xml configuration. The default value is 8009 worker. tomcat2.host = localhost # tomcat host address. If not, enter the IP address worker. tomcat2.type = ajp13 worker. tomcat2.lbfactor = 2 # server weighting ratio. The higher the value, the more requests are allocated. #======= controller, server Load balancer controller ======= worker. controller. type = lb worker. controller. balanced_workers = worker at1, tomcat2 # specify tomcat worker that shares the request. controller. sticky_session = 1
The above configurations are clear. If you want to add tomcat, add it according to the above configuration!
Iv. Tomcta Configuration
Tomcata configuration is not special. It is important to modify the port number of the second tomcat server When configuring different tomcat servers on the same machine. do not conflict with the First tomcat server, otherwise, it cannot be started!
During session sharing, you need to add the following configuration, which is not found on the Internet in tomcat server. xml. However, it has been tested and can be used normally! The configuration is as follows:
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"channelSendOptions="6"> <Manager className="org.apache.catalina.ha.session.BackupManager"expireSessionsOnShutdown="false"notifyListenersOnReplication="true"mapSendOptions="6"/> <Channel className="org.apache.catalina.tribes.group.GroupChannel"> <Membership className="org.apache.catalina.tribes.membership.McastService"address="228.0.0.4" port="45564" frequency="500"dropTime="3000"/> <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="auto" <span style="color:#ff0000;">port="4001"</span>selectorTimeout="100"maxThreads="6"/> <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter"> <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/> </Sender> <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/> </Channel> <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"filter=".*\.gif|.*\.js|.*\.jpeg|.*\.jpg|.*\.png|.*\.htm|.*\.html|.*\.css|.*\.txt"/> <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"tempDir="/tmp/war-temp/" deployDir="/tmp/war-deploy/"watchDir="/tmp/war-listen/" watchEnabled="false"/> <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/> </Cluster>
Note the red part. Do not repeat the two tomcat servers. do not modify the other tomcat servers!
In this way, session sharing can be realized!
V. Test Items
The content of index. jsp in tomcat1 is as follows:
<%@ page language="java"contentType="text/html; charset=utf-8" pageEncoding="utf-8"%><%@ pagesession="false"%><!DOCTYPE htmlPUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
The content of index. jsp in Tomcat 2 is as follows:
<%@ pagelanguage="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%><%@ pagesession="false"%><!DOCTYPE htmlPUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
Test result:
Page effect:
Pay attention to these points!