1, Apache HTTP Server and Tomcat four ways to connectJK http_proxy Ajp_proxy Mod_cluster
Four comparisons:
The Http_proxy, Ajp_proxy, and Mod_cluster are relatively simple and flexible in their configuration relative to JK's connection method. But in terms of stability it's not as well-tried as JK, but over time, there are more and more Internet sites using Mod_cluster.
2. Benefits of using Mod_cluster
HTTPD workers can be configured dynamically
The application server relies on the Lifecyle event (server Startup/shutdown) to dynamically configure it by Adverties Broadcast mechanism notification HTTPD
Server-side load balancing factor calculation
By computing the load balancing factor on the server side, this article means that Tomcat is responsible for computing, and by placing the computation on the server side, the Mod_cluster can provide more robust and accurate load balancing than the proxy side.
Finer-grained web-app life cycle control
Web-app at Deploy/undeploy, the server will automatically notify httpd to add/Remove the Web-app's context route.
Supports multiple protocols (HTTP, HTTPS, AJP)
Unlike MOD_JK, Mod_proxy, ajp_proxy modules only support single protocol
3, physical deployment diagram
4. installation file preparation
apache:httpd-2.2.22-win32-x86-openssl-0.9.8t.msi Apache Mod_cluster module: mod_ Cluster-1.2.6.final-windows-x86.zip tomcat:apache-tomcat-7.0.53.tar.gz Tomcat Mod_cluster Integration: Mod_ Cluster-parent-1.2.6.final-bin.tar.gz Jdk7:jdk-7u79-windows-x64.exe
Note: the Mod_cluster module must correspond to the Apache version, or it may cause Apache to not start properly.
5, Apache httpd mod_cluster module installation configuration
Apache Installation:
Directly double-click the downloaded httpd-2.2.22-win32-x86-openssl-0.9.8t.msi file to install, here we install into the D:\Apache2.2 directory
Unzip the downloaded mod_cluster-1.2.6.final-windows-x86.zip file, get the httpd-2.2 directory, copy the httpd-2.2\modules Directory below the 4 so files to the D:\Apache2.2\modules directory under mod_advertise.so mod_manager.so mod_proxy_cluster.so mod_slotmem.so
Configure the Mod_cluster module to create a new http-mod_cluster.conf configuration file in the D:\Apache2.2\conf\extra directory as follows:
# Required modules
LoadModule proxy_module modules / mod_proxy.so
LoadModule proxy_ajp_module modules / mod_proxy_ajp.so
LoadModule slotmem_module modules / mod_slotmem.so
LoadModule manager_module modules / mod_manager.so
LoadModule proxy_cluster_module modules / mod_proxy_cluster.so
LoadModule advertise_module modules / mod_advertise.so
Listen 192.168.1.107:6666
<VirtualHost 192.168.1.107:6666>
<Location />
Order deny, allow
Deny from all
Allow from all
</ Location>
KeepAliveTimeout 60
MaxKeepAliveRequests 0
ManagerBalancerName mycluster
ServerAdvertise On
EnableMCPMReceive
</ VirtualHost>
# Set proxy forwarding to forward all requests to mycluster load balancer
ProxyPass / balancer: // mycluster /
# Configure mod_cluster-manager to access mod_cluster management interface through http: // ip: port / mod_cluster-manager
<Location / mod_cluster-manager>
SetHandler mod_cluster-manager
Order Deny, Allow
Deny from all
Allow from all
</ Location>
Modify the D:\Apache2.2\conf\httpd.conf file
Set the IP and listening ports used by Apache
ServerName 192.168.1.107:80
Comment out the Mod_proxy_balancer module because this module is incompatible with the Mod_cluster-related module
# LoadModule Proxy_balancer_module modules/mod_proxy_balancer.so
Add the following configuration after #Include/private/etc/apache2/extra/httpd-vhosts.conf configuration
# Mod_cluster
include/private/etc/apache2/extra/httpd-mod_cluster.conf
Verifying the D:\Apache2.2\conf\httpd.conf configuration
CMD command line executes the following command:
D:\Apache2.2\bin\httpd.exe-t
If you receive the following result, the configuration is correct, otherwise, you can correct it according to the error prompt
Syntax OK
Start Apache Server
CMD command line executes the following command:
D:\Apache2.2\bin\httpd.exe-k start
If you receive the following results, you have started normally
The Apache2.2 service is running.
] Advertise initialized for process 1764
[Sun Dec 18:01:37] [notice] apache/2.2.22 (WIN32) Mod_cluster/1.2.6.fin Al configured-resuming normal operations
[Sun Dec 18:01:37] [notice] Server Built:jan 11:16:39[sun Dec 18:01:37] [notice] parent:created child process 4996
[Sun Dec one 18:01:37] [notice] child 4996 : Child process was running
[Sun Dec 18:01:37] [notice] child 4996:acquired the start mutex.
[Sun Dec 11 18:01:37 2016] [Notice] Child 4996:starting threads worker.
[Sun Dec 11 18:01:37 2016] [Notice] Child 4996:starting thread to listen on port 6666.
[Sun Dec 11 18:01:37 2016] [Notice] Child 4996:starting thread to listen on port 80.
Enter the following address in the browser address bar to access the Mod_cluster management interface:
Http://192.168.1.107/mod_cluster-manager
If you see the following page, the Mod_cluster module installation configuration is successful
vi. Tomcat and mod_cluster connection configuration
TOMCAT7 installation steps: Slightly ...
TOMCAT7 mod_cluster Configuration
Modify %tomcat%\conf\server.xml new Modclusterlistener
<listener classname= "Org.jboss.modcluster.container.catalina.standalone.ModClusterListener" advertise= "true"/ >
Modified %tomcat%\conf\server.xml engine element added jvmroute= "Jvm-app1"
<engine name= "Catalina" defaulthost= "localhost" jvmroute= "Jvm-app1" >
Note: since Mod_cluster 1.1 Jvmroute is modified to an optional setting, if not set, an identity is automatically generated, primarily to differentiate between multiple Tomcat instances
Start TOMCAT, and view the %tomcat%\logs\catalina.out log. If the following log fragment is found, the Mod_cluster Tomcat side configuration is successful
2016-12-11 18:51:01 org.jboss.modcluster.ModClusterService init
INFO:MODCLUSTER000001:Initializing mod_cluster ${project.version}
2016-12-11 18:51:01 org.jboss.modcluster.advertise.impl.AdvertiseListenerImpl start
INFO:MODCLUSTER000032:Listening to proxy advertisements on/224.0.1.105:23364
2016-12-11 18:51:02 org.apache.coyote.AbstractProtocol Start
info: Starting Protocolhandler ["http-bio-8080"]
2016-12-11 18:51:02 org.apache.coyote.AbstractProtocol Start
info: Starting Protocolhandler ["ajp-bio-8009"]
2016-12-11 18:51:02 Org.apache.catalina.startup.Catalina Start
info: Server Startup in 980 Ms
2016-12-11 18:51:12 Org.jboss.modcluster.ModClusterService connectionestablished
INFO:MODCLUSTER000012:Catalina connector would use /192.168.1.107
Similarly, the configuration tomcat is installed on another machine, but Jvmroute is set to "JVM-APP2" vii. integrated validation
In the browser address bar input Http://192.168.1.107/mod_cluster-manager View Mod_cluster Management interface, if you see the following page, the Mod_cluster module installation configuration is successful
Enter http://192.168.1.107 in the browser address bar, and if you can see the TOMCAT7 home page as follows, since this Apache integration with Tomcat through the Mod_cluster module is successful.
Viii. broadcast address & port changes
For example: Modify the Mod_cluster module broadcast address and port to 224.0.1.200:60000 D:\Apache2.2\conf\extra\http-mod_cluster.conf configuration as follows:
# Required modules
LoadModule proxy_module modules / mod_proxy.so
LoadModule proxy_ajp_module modules / mod_proxy_ajp.so
LoadModule slotmem_module modules / mod_slotmem.so
LoadModule manager_module modules / mod_manager.so
LoadModule proxy_cluster_module modules / mod_proxy_cluster.so
LoadModule advertise_module modules / mod_advertise.so
Listen 192.168.1.107:6666
<VirtualHost 192.168.1.107:6666>
<Location />
Order deny, allow
Deny from all
Allow from all
</ Location>
KeepAliveTimeout 60
MaxKeepAliveRequests 0
ManagerBalancerName mycluster
ServerAdvertise On
# Broadcast address, the default is: 224.0.1.105:23364
AdvertiseGroup 224.0.1.200:60000
# httpd broadcast binding address port, binding when the host has multiple IPs, the default is: 0.0.0.0:23364
AdvertiseBindAddress 224.0.1.200:60000
EnableMCPMReceive
</ VirtualHost>
# Set proxy forwarding to forward all requests to mycluster load balancer
ProxyPass / balancer: // mycluster /
# Configure mod_cluster-manager to access mod_cluster management interface through http: // ip: port / mod_cluster-manager
<Location / mod_cluster-manager>
SetHandler mod_cluster-manager
Order Deny, Allow
Deny from all
Allow from all
</ Location>
%tomcat%\conf\server.xmlThe configuration changes are as follows:
<Listener className="org.jboss.modcluster.container.catalina.standalone.ModClusterListener" advertise="true" advertiseGroupAddress="224.0.1.200" advertisePort="60000" />
...
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm-app1">
A more detailed configuration of the Tomat terminal is available for reference: Chapter 9. Server-side configurantion Properteis
Nine, Mod_cluster load balancer Skip Settings
Sometimes we encounter scenes where some URLs map to other addresses, and these URLs do not need to go mod_cluster load balancer, we need to skip, here we use the rewrite module to rewrite the configuration, such as: /manager/ The beginning of the URL is mapped to http://192.168.1.111:8080/manager/address. Uncomment the mod_proxy_http ,mod_rewrite module in the D:\Apache2.2\conf\httpd.conf configuration, and configure the rewrite module later to use
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so
D:\Apache2.2\conf\extra\http-mod_cluster.confThe file is modified as follows:
# Required modules
LoadModule proxy_module modules / mod_proxy.so
LoadModule proxy_ajp_module modules / mod_proxy_ajp.so
LoadModule slotmem_module modules / mod_slotmem.so
LoadModule manager_module modules / mod_manager.so
LoadModule proxy_cluster_module modules / mod_proxy_cluster.so
LoadModule advertise_module modules / mod_advertise.so
Listen 192.168.1.107:6666
<VirtualHost 192.168.1.107:6666>
<Location />
Order deny, allow
Deny from all
Allow from all
</ Location>
KeepAliveTimeout 60
MaxKeepAliveRequests 0
ManagerBalancerName mycluster
ServerAdvertise On
EnableMCPMReceive
</ VirtualHost>
# Set proxy forwarding, here is to forward all requests to mycluster load balancer
ProxyPass / balancer: // mycluster /
# Set requests starting with / manager / through the rewrite module, skip mod_cluster load balancing processing (requires loading mod_rewrite, mod_proxy_http modules)
RewriteEngine on
RewriteRule ^ / manager /(.*) http://192.168.1.111:8080/manager/$1 [P]
# Configure mod_cluster-manager so that you can access the mod_cluster-manager management page
<Location / mod_cluster-manager>
SetHandler mod_cluster-manager
Order Deny, Allow
Deny from all
Allow from all
</ Location>
10. Reference materials:
[1]. Mod_cluster Documentation
[2]. Mod_cluster Quick Start Guide
[3]. Server-side Configuration
[4]. Server-side Configuration Properties
[5]. Initial pre-research on load balancing using Mod_cluster
[6]. JBoss Series II: High-availability clustered environments using Apache httpd (mod_cluster) and JBoss architecture
[7]. Three ways to connect Apache HTTP Server to Tomcat