tomcat cluster apache in front - How to load balance? - apache

What apache module would fit better to build the following cluster:
2x Red Hat each has a tomcat an apache.
No Scalability needs.
High availability needs.
Session replication needs.
DNS
|
Load Balancer
/ \
APACHE1 APACHE2
TOMCAT1 TOMCAT2
The question is regarding what module to use for the load balancing with apache?
mod_proxy
mod_cluster
other?

If I understand mod_cluster correctly, it must be used with JBoss, or with a modified Tomcat. So if you are using plain-old Tomcat (or TomEE), then I think mod_cluster is out.
The easiest out-of-the box option is to use mod_proxy with either the AJP or HTTP back-end. If you are comfortable building additional modules, mod_jk is available from the Tomcat folks and offers a few advantages over mod_proxy, though mod_proxy has nearly achieved feature-parity.
Your diagram suggests that a load-balancer will be choosing between two httpd instances which are coupled directly to a single Tomcat instance each. In that scenario, httpd is not performing any load-balancing at all (the lb is doing the work), and so httpd might be superfluous in that configuration.
If you instead want to cross-link both httpds with both Tomcats, that's when you start having to configure cluster-like behavior with mod_proxy's "balancer" configurations. It would look something like this:
<Proxy balancer://appA>
BalancerMember http://tomcatA:8080/appA
BalancerMember http://tomcatB:8380/appA
</Proxy>
ProxyPass /appA balancer://appA
ProxyPassReverse /appA balancer://appA
There are tons of options for mod_proxy that you should read about and apply to suit your configuration. You can configure things like sticky-sessions, hot-standbys (not present in your example diagram but a good idea if you really need HA), and asymmetric load-balancing.

Related

Apache HTTPD ProxyRemote and Balancer?

browser (IE) -> apache httpd proxy -> Proxy 1 -> target url
Proxy 2 -> target url
Proxy n -> target url
So basically I want to make my own apache httpd proxy that works as a loadbalancer between choosing external proxy setup'ed in httpd conf.
Current setup:
ProxyPreserveHost On
ProxyRequests On
ProxyVia On
ProxyRemote * http://proxy_ip:80
This version works nicely but I can't figure out how to add several proxy's to ProxyRemote?
... seems not working when setuping as:
ProxyRemote * balancer://mycluster
Any ideas? Can it be achieved with apache or some other load balancer should be used?
Perhaps I'm a bit too late to help you, but it seems there is no clear answer elsewhere to your question, so this could be useful in the future.
Unfortunately the answer is you cannot achieve this kind of load balancing with Apache: as per the Apache documentation (https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxyremote) the ProxyRemote directive only supports http and https schemas, not balancer://
Cannot really figure out why the Apache developers didn't consider this configuration, tough, since I found a patch for mod_proxy.c (http://apache-http-server.18135.x6.nabble.com/attachment/4777809/0/ProxyRemote-Balancer.patch) which seems to do the trick by essentially just adding the balancer:// schema to the list of matched protocols.
Maybe it could work if you set up another vhost on the proxy server mapping to the balancer, then proxy to that vhost via
ProxyRemote * http://balancer-proxy.vhost.local

ProxyPass module configuration in apache tomcat

I found one documentation here to run multiple node application on single port using proxypass, I understood the concept, it just forward the request to node application port unsing ProxyPass. In that example, they used httpd, and I am using tomcat.
My question is, how can I do same configuration in tomcat?
simply I am expecting tomcat configuration for this httpd configuration.
ProxyPass /node http://host.xyz.com:3000
You really should consider using Apache httpd (or any other frontend) for this purpose. This is the software that handles the requirement best - and tomcat best serves application data.
Also, Apache httpd knows how to handle port 80 or 443, something that needs some extra work with tomcat (if you don't want to run it as root. And you actually don't want to run it as root)
It doesn't require so many extra resources, use the appropriate tool for the job. And, when you use mod_proxy, look up all the related options and understand what they're there for. You probably also want ProxyPreserveHost On, but I'll stop here.
I hope the document will be helpful.

Which load balancer supports Master/Slave configuration?

I am looking for load balancer for my web application that will support master-slave kind of configuration or algorithm support.
For now I am using apache proxy but with round robin LB method.
I am not sure if apache load balancer has master-slave support or any module?
Here is what I want exactly: Forward all request to one back end server and once the master server is down the slave or other server will act as hot stub.
Please suggest if any open source load balancer I can use w.r.t to my above requirement.
You can use nginx with its Upstream module.
Example configuration:
upstream myBackend {
server main.example.com:8080;
server back.example.com:8080 backup;
}
server {
location / {
proxy_pass http://myBackend;
}
}
While the first server (main.example.com) is up, nginx will use it. When it comes down, it will use the second server. You can read in the linked manual page for various other tuning parameters (for example when to mark server as failed). Nginx supports HTTPS for both incoming connections and also for connections to the proxy backend.
EDIT: For Apache it seems to be possible in version 2.4 using the Proxy Balancer. I have not tested this config. For more details see manual for ProxyPass.
ProxyPass "/" "balancer://hotcluster/"
<Proxy "balancer://hotcluster">
BalancerMember "http://1.2.3.4:8000"
# The server below is on hot standby
BalancerMember "http://1.2.3.6:8000" status=+H
</Proxy>

running mod_cluster mod_proxy_htt and mod_proxy_ajp together

I need to use the mod_proxy_http for some requests and the mod_proxy_ajp to be used with mod_cluster. The documentation of mod_cluster specifies to either use mod_proxy_http OR the mod_proxy_ajp.
Does anybody know if it's possible to tell mod_cluster to use mod_proxy_ajp in virtual hosts while mod_proxy_http can still be used for other purposes like proxypass or mod_rewrite proxy redirects in the same Apache 2.2.xx server?
After quite a bit of research and testing I found out that the default protocol for mod_cluster is AJP if the mod_proxy_ajp is loaded, otherwise it reverts to HTTP protocol(mod_proxy_http). Exactly what I wanted.

Guide to setting up Apache2 with multiple distinct Tomcat 7 instances

I realize this question has probably been asked numerous times, but I have not been able to find a good, up-to-date answer. The only guide I have been able to find was from 2005 and was on tomcat 5. It seems a lot of the OS paths have changed.
Our situation is this:
We want to run multiple instances of tomcat 7 on a single server. Each tomcat serves up a different address. For instance, www.oursite.com should be served from a separate tomcat than test.oursite.com. So, for example the base tomcat installtion will sit in /opt/tomcat/ and the instance specific directories (this is what I could make out from that old tutorial) will be in /home/user1/some/path/ and /home/user2/some/path so that everything is seperated nicely.
Can anyone point to a good tutorial, or maybe explain here the steps to set this up? I'm a bit new to apache setups.
Are there any advantages / drawbacks to doing it this way? Would a single tomcat instance be better? We need to be able to bring down sites one at a time without influencing each other. Also, our DNS provider prevents us from setting up stealth redirects, so we have to go through apache to have nice URLs rather than redirecting straight to the tomcats.
Thanks
I believe you have 2 questions here:
How to run multiple tomcat instances in the same server and should
you?
How to configure apache httpd to do virtual host and front
tomcat?
For 1. The following is a very good tutorial on how to run multiple tomcat instances in the same server: http://java.dzone.com/articles/running-multiple-tomcat, but should you? the answer is "it depends". If you have a super powerful box and it is under utilized, you should. It also depends on what type of application you runs for each individual sites. It will definitely help you "bring down sites one at a time without influencing each other". With apache httpd configuration which I will explain in the next section, you can also run the each site on separate machines (physical or vm).
For 2. In you case, you just need to configure apache httpd to do virtual host and use ajp to connect to tomcat.
<VirtualHost *:80>
ServerName www.oursite.com
ProxyPass / ajp://tomcat.oursite.com:8009/www retry=5
ProxyPassReverse / ajp://tomcat.oursite.com:8009/www
</VirtualHost>
<VirtualHost *:80>
ServerName test.oursite.com
ProxyPass / ajp://tomcat.oursite.com:8010/test retry=5
ProxyPassReverse / ajp://tomcat.oursite:8010/test
</VirtualHost>
In the above configuration, you need to configure DNS entries of both www.yoursite.com and test.yoursite.com to point to the same host. It also assume you run both your www and test webapps on different tomcat instances on the same host tomcat.oursite.com, one on ajp port 8009 and the other one on ajp port 8010. You can also change it to a different server of its own. It's very flexible. FYI, following is how to configure ajp in tomcat: http://tomcat.apache.org/tomcat-6.0-doc/config/ajp.html
I found a problem with the apache mod_proxy_ajp connector in such a configuration, it absolutely won't allow you to use any other port when setting up multiple virtual hosts each with its own tomcat instance.
Having spent some time ruling out port conflicts, tomcat configuration issues, firewall issues I have concluded that ProxyPass and ProxyPassReverse will not work when using any port other than 8009 by default.
The solution is likely to be to switch to mod_jk, which also solves problems seen in mod_proxy_ajp with basic configurations not loading or rewriting urls embedded within tomcat hosted pages without extensive configuration changes if the tomcat instance is rooted to a subdirectory. This doesn't seem to happen with Mod_Jk