I am able to achieve load balancing using Tomcat 7 and Apache mod_jk by running the same application from two different tomcat instances using load balancer configured in httpd.conf and worker.properties works fine.
httpd.conf
JkMount /myApp/* loadbalancer
worker.properties
worker.list= worker,worker1,loadbalancer
worker.worker1.port=8009
worker.worker1.host=IP
worker.worker1.type=ajp13
worker.worker.port=8009
worker.worker.host=IP
worker.Worker.type=ajp13
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=worker,worker1
However I am trying to have multiple load balancers so that in case single load balancer fails then in such a case we have a fallback load balancer as in this case there is only one load balancer. Is this possible with Apache mod_jk.
In the case you describe in your question, Apache httpd is the loadbalancer, which happens to use mod_jk to do the actual balancing job. If Apache httpd goes away, you'll no longer balance. Therefor the question "I'm trying to have multiple load balancers - is this possible with mod_jk" doesn't make sense to me...
You can have multiple loadbalancers, each of them using their own mod_jk. But it's got nothing to do with this.
Technically a correct answer to this question would be: Sure - just configure an identical Apache httpd and put it onto the same network, then configure whatever you need (IP failover, Round Robin DNS) to make sure that both loadbalancers now distribute the load. Make sure that the tomcat backends accept enough connections to now serve two loadbalancers.
But mod_jk has, IMHO, nothing to say in that question.
Related
Problem:
We have many applications in Tomcat and each one needs a lot of time to start.
During that time, if you make an HTTP request to the Tomcat port, it gets waiting till all the applications are fully started.
As we have a load balancer that only checks Tomcat TCP connections, it is not smart enough to discard that Tomcat instance.
Wanted solution:
I would like to know how to start Tomcat so it starts to listen HTTP requests only after all applications are fully deployed. In this way, the load balancer will notice that it is not possible to make a TCP connection and it will discard that Tomcat during that time.
The tomcat wiki has a "how to" on this
How do I make Tomcat startup faster?
In short:
Web app configuration
Remove unnecessary JARs
Exclude JARs from scanning
Entropy Source configuration
Enable start of webapps in parallel with startStopThreads
Tweak memory parameters
Trim the config files as much as possible. XML parsing is not cheap. The less there is to parse - the faster things will go.
Remove any web applications that you do not need. (So remove the all the web applications installed with tomcat)
Make sure your code is not doing slow things. (Use a profiler)
I have two Jboss instances installed on different servers. My aim is to manage a failover recovery between these Jboss instances. Load balancing is not needed. This is customer requirement. Normally client is connected to JBoss 1, perform a failover, and which the client will automatically connect to JBoss 2.
As I said I want to serve only one Jboss instance at a time.
Actually I have a solution, but I don't know if it works. My aim was to write a service that checks if Jboss is running. When I catch a failover, I want to change jndi.properties of client, then other Jboss instance will start to serve client request. But I do not know this solution works. Also Jboss can provide me a service( or other property) to check a specific instance is running?
Do you think my solution can work? Or How can I do this? Do I have to install Apache ? Apache provides failover without load balancing.
Background: In my application, I use ServiceMix instances to serve HTTP requests. To load balance these, we figured out(according to some requirement) that we need to use Tomcat.
Question: As I think it should be said that tomcat has its own http server built into it, can Tomcat and mod_jk(without Apache Http Server) be used as a load balancer?
My readings: I read few of the Tomcat domcumentation like Tomcat Clustering doc
, Tomcat JK load balancer (which wasn't quite helpful)
So I wonder is it even possible to use only Tomcat and mod_jk for the purpose of load balancing!!
Any help is appreciated.
To load balance your application you'll need to run two or more Tomcat instances with the same application. You could run two instances on the same machine on different ports (e.g. www.myapp.com:8080 and www.myapp.com:9090) or on different machines on the same port (e.g. www1.myapp.com:8080 and www2.myapp.com:8080). Usually the instances share the same backend data store. Each Tomcat is its own webserver, so you'll have multiple web servers running.
Because you now have two identical instances a user can use either of the two instances. They can also switch from one to the other if something happens to the machine they are currently using. But you don't want your users to have to choose a machine or swap manually. This is where a load balancer comes in.
A load balancer takes a request from the user and dynamically routes it to one of your load balanced instances. A load balancer is also a web server. It can be a hardware load balancer like a BIG-IP F5, or software like Apache, nginx or even another Tomcat server.
If you use an Apache web server to do the load balancing you'll need an Apache module to pass on the request to one of your Tomcat servers. Typically this is mod_jk or mod_proxy.
So the short answer is that if you use Apache as your load balancer then you have to use mod_jk (or mod_proxy). If you use another load balancer then you can't use mod_jk.
Also refer to Tomcat load balancer solutions
mod_jk runs inside of apache httpd server or some other server it is written in native code, Here are some configurations that will work.
Apache httpd or IIS with mod_jk load balances requests to tomcat server
A web server with reverse proxy support with and a load balancing feature can be used
A dedicated load balancer product can be used
For load balancing you need to make sure to determine weather you need sticky session routing or not.
Also you do don't need to configure tomcat clustered session manager in order to configure and use load balancing.
I am fairly certain that tomcat itself the java part does not ship with a built in load balancer it expect users to use one of the above options.
Is it possible to forward the request from a servlet running to another servlet running in a different tomcat in the same machine? I think its possible to configure this out in a cluster environment but not quite sure how to get this when two tomcat servers are not related in a cluster environment. Please help.
Yes. You can configure a load balancer to redirect the requests based on whatever rules you want. Here is how to do it: http://tomcat.apache.org/tomcat-5.5-doc/balancer-howto.html#Comments
If needed, you can configure each instance of tomcat to run on a different port.
Please tell me what is better in supporting clustering and ssl between mod_jk and mod_proxy_ajp.
Thank you.
Regarding SSL, it should not make any difference if you use mod_jk or mod_proxy_ajp. Especially if you offload SSL in apache and not in tomcat, the transport between httpd <-> tomcat (mod_jk/mod_proxy_ajp) would not be affected.
As mod_proxy_ajp is the newer solution (that grew out of mod_jk), the general advice would be to go for mod_proxy_ajp (at least I'd use this one).
Cheers,
Martin
PS: mod_jk and mod_proxy_ajp are load-balancing solutions. clustering is more referring to the part where sessions are replicated between several cluster nodes.
I would say, session replication is one aspect of clustering, and clustering also to do with how a client is dispatched certain instence (one tomcat instance) of a cluster, that is load balancing.
A cluster should be see from outsite as one sinlge entry point, and hence, there are good reasons to have SSL handling in a central loation, we call this "ssloffloading" or "ssl termination" at load balancer / apache.
More info about ssloffloading see this post:
http://milestonenext.blogspot.de/2012/09/ssl-offloading-with-modjk-part-1.html