1. Apache and Tomcat installation
1. Download Apache Cluster Server
Address: http://archive.apache.org/dist/httpd/binaries/win32/httpd-2.2.25-win32-x86-openssl-0.9.8y.msi
2. Install Apache Cluster Server
See the green triangle icon in the lower right corner, installed and started successfully for apache
3. Download Tomcat 7 to decompress and install
http://mirrors.shuosc.org/apache/tomcat/tomcat-7/v7.0.82/bin/apache-tomcat-7.0.82.zip
Unzip to tomcat1 and tomcat2 two folders, the content is exactly the same
Second, Apache configuration
1. Load proxy module
Configure Apache, open the apache configuration file: %APACHE_HOME%/conf/httpd.conf
Since all modules have been loaded, there is no need to modify the configuration. Remove the # comment at the beginning of the following line
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
2. Configure virtual host proxyblancer
<VirtualHost *:80> ServerAdmin [email protected] ServerName localhost ErrorLog "C:/app1_error.log" CustomLog "C:/app1_access.log" common ProxyPass / balancer://cluster/ stickysession=JSESSIONID|jsessionid nofailover=On lbmethod=byrequests timeout=5 maxattempts=3 ProxyPassReverse / balancer://cluster/ ProxyRequests Off ProxyPreserveHost On <proxy balancer://cluster> BalancerMember ajp: //127.0.0.1: 6009 route = tomcat_a BalancerMember ajp: //127.0.0.1: 8009 route = tomcat_b </proxy> </VirtualHost>
3. Modify the configuration of tomcat1 and tomcat2
1. Modify the conf/server.xml file of tomcat1
<Server port="6005" shutdown="SHUTDOWN"> <Connector port="6080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="6443" /> <Connector port="6009" protocol="AJP/1.3" redirectPort="6443" /> <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat_a"> <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> </Engine> </Server>
2. Modify the conf/server.xml file of tomcat2
<Server port="8005" shutdown="SHUTDOWN"> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat_b"> <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> </Engine> </Server>
Fourth, edit the test file
1. Add the test file %TOMCAT_ROOT%/webapps/ROOT/test.jsp to tomcat1
The content of test.jsp is:
this is tomcat1
2. Add the test file %TOMCAT_ROOT%/webapps/ROOT/test.jsp to tomcat2
The content of test.jsp is:
this is tomcat2
5. Test
Enter the address in the browser:
http://localhost:80/test.jsp
The displayed content is sometimes this is tomcat1, sometimes this is tomcat2, which means success