One of the major enhancements in release 2.2 of Apache httpd is the addition of the mod_proxy_ajp and mod_proxy_balancer modules to the standard distribution. Gone are the days of needing to build special modules such as Jserv, jk, jk2 and warp to have httpd act as a "front" to a Java (Tomcat) server - the module you need is already there.
Proxy forwarding to a Java Server
Here's an example of a proxied request from Apache httpd on to a server (probably Apache Tomcat) that's running the ajp protocol on port 5090:
ProxyPass /harry ajp://192.168.200.215:5090/latmjdemo
ProxyPassReverse /harry ajp://192.168.200.215:5090/latmjdemo
That's code to be added to the end of your httpd.conf file!
Proxy forwarding to a group of Java Servers
It gets even better ... mod_proxy_balancer lets you define a group of Java servers which you can forward your traffic on to - ideal on a busy site where the background task that's running in Java is a resource hog and needs to be shared between systems. Here's an example of what you would add to httpd.conf:
BalancerMember ajp://192.168.200.215:5090/latmjdemo
BalancerMember ajp://192.168.200.214:5009/latmjdemo
ProxyPass /prince balancer://catbox/
In this example, any references to the web resources on the server under the /prince directory will be forwarded to one of two other machines, on port 5090, and will be directed to the "latmjdemo" web application on there.
On our private Apache Tomcat course yesterday (based on / extended from our public course), we set up exactly this; although a production system would have identical applications on the two servers, we altered the background colour on one of them and it was fascinating to watch different delegates, and different reloads, coming up in either green or white.
More flexibility in forwarding to a group of Servers
The example above uses the default "round robin" scheduler - but there are other facilities available too to help you tune your forwarding. Here's a further example:
BalancerMember ajp://192.168.200.219:5009/latmjdemo loadfactor=1
BalancerMember ajp://192.168.200.218:5009/latmjdemo loadfactor=3
BalancerMember ajp://192.168.200.215:5009/latmjdemo status=+h
ProxySet lbmethod=bytraffic
ProxySet stickysession=JSESSIONID
ProxyPass /corgi balancer://kennel/
In this example, we are forwarding to 2 systems, in a ratio of 1 : 3 and we're allocating traffic based on the traffic quantities coming back from each server rather than the number of requests (so queries that generate a lot of traffic count for more). An extra machine has been designated as "hot swap" if neither of the others is available. Once a visitor is allocated to a particular machine for his forward, he'll continue to be forwarded to that same system while his JSESSIONID cookie remains live.
Some other notes about mod_proxy and family in Apache 2.2:
• ProxyPassMatch is available, which lets you specify a pattern (Regular Expression) for your forwarding - for example, if you wanted to forward all you image requests to an image server:
ProxyPassMatch ^/(.*\.jpg)$ http://images.wellho.net/$1
• mod_rewrite IS aware of mod_proxy_balancer, so that you can rewrite your requests as we do in many parts of our site, and then forward them on to other systems through an appropriate balancer.
• As from Apache 2.2.9, ProxyPassReverse is also mod_proxy_balancer aware.
Further reading ... There's a very good paper by Jim Jagielski - here - on these and more extra facilities. Documentation for mod_proxy_balancer is here, and there's a good description of reverse proxies here.
(written 2008-12-13 08:53:06)
No comments:
Post a Comment