Apache web server multiple workers - apache

We have a webserver running apache 2.2, which connects to tomcat 5.5 in another server (say, repserver). This is done through ajp1.3 protocol, with mod_jk workers.properties file defining an ajp13 worker.
The workers.properties file contains:
ps=\
worker.ajp13.type=ajp13
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=#HOSTNAME
The httpd.conf file is using these three lines:
JkMount /* ajp13
JkMount /#Link1/* ajp13
JkMount /#Link2/* ajp13
Now we have another instance of tomcat 7 in the repserver, and we need the webserver to connect to this instance as well. I have defined the listening port for ajp as 9009 in this instance of tomcat.
This contains link3 and link4.
How can I define another worker to connect to these links?

You need to define a load balancer in that case:
Change your workers.properties to this:
worker.list=balancer
#lb config
worker.balancer.type=lb
worker.balancer.sticky_session=1
worker.balancer.balance_workers=ajp13,tomcat7
#(ajp13 is not a good name for a worker/server node)
worker.ajp13.type=ajp13
worker.ajp13.port=8009
worker.ajp13.host=#HOSTNAME
worker.tomcat7.type=ajp13
worker.tomcat7.port=9009
worker.tomcat7.host=#IP/HOSTNAME
Open server.xml of Tomcat 7 and define the jvmRoute (do that in Tomcat 5 too, if not still happend):
<Engine jvmRoute="tomcat7" name="Catalina" ...>
Map applications to the new Tomcat 7:
JkMount /APPLICATION_NAME balancer
JkMount /APPLICATION_NAME/* balancer

Related

Two loadbalacer with apache 2.2(for jboss and apapche tomcat)

I have a apache server with loadbalancer(apache-2.2) and two tomcat nodes(clusters). To communicate with tomcat nodes I'm using mod_jk. I've defined two loadbalancer in apache(by changing httpd.conf and worker property files). Apache is running in port 80. The configuration as follows. iSencer is one of my application.
In httpd.conf
=============
Listen localhost:80
ServerName localhost
DocumentRoot "/home/xx/projects/apache/content" (I've created a seperate root directory as content)
JkMount /iSencer loadbalancer
JkMount /iSencer/ loadbalancer
JkMount /iSencer/* loadbalancer
In worker.properites
====================
worker.list=loadbalancer
#------------------------
# iSencer node 1 - tomcat
#------------------------
worker.iSencer1.type=ajp13
worker.iSencer1.host=localhost
worker.iSencer1.port=8109
#------------------------
# iSencer node 2 - tomcat
#------------------------
worker.iSencer2.type=ajp13
worker.iSencer2.host=localhost
worker.iSencer2.port=8010
# ------------------------
# Load Balancer for yard
# ------------------------
worker.loadbalancer.sticky_session=1
worker.loadbalancer.balanced_workers=iSencer1,iSencer2
worker.loadbalancer.type=lb
worker.loadbalancer.method=B
and there are some changes in tomcat server.xml.So, cluster is working properly.
Now I want to add a jboss server to same apache. But need to run in different loadbalancer. My changes as follows as in httpd.conf in apache.
JkMount /index.html loadbalancer2
JkMount /servlet/* loadbalancer2
worker property
===============
worker.list=loadbalancer, worker.list=loadbalancer2
#------------------------
# tracker node 1
#------------------------
worker.track.port=8009
worker.track.host=localhost
worker.track.type=ajp13
worker.track.lbfactor=1
worker.track.connection_pool_size=10
# ------------------------
# Load Balancer for tracker
# ------------------------
worker.loadbalancer2.sticky_session=1
worker.loadbalancer2.balanced_workers=track
worker.loadbalancer2.type=lb
worker.loadbalancer2.method=B
But after adding jboss to apache as a cluster my tomcat cluster is not working properly ? In browser it will show two JSESSIONIDs. When I remove jboss form apache configuration still not working. Browser still showing two JSESSIONIDs. After clearing cookies in browser cluster is working fine. so what is the reason not to work cluster with jboss ?

apache mod_jk configuration for ssl tomcat6

I am trying to update my webserver from mod_proxy to mod_jk.
I am able to access http pages using following configurations
JkMount /* loadbalancer
and my workers.properties are
worker.list=loadbalancer,status
Define Node1
worker.node1.port=8009
worker.node1.host=10.255.255.77
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node1.cachesize=10
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1
worker.loadbalancer.sticky_session=1
worker.list=loadbalancer
worker.status.type=status
For our SSL tomcat is listening on diffrent port, so how can I pass this ssl to diffrent port. How I need to configure workers.properties.
My tomcat configurations are
Can you guide me on SSL please?
Sreenivas
Created new worker and assigned SSL port 8010. In ssl virtual host we mounted that worker.
Sreenivas

Load balancing with Apache and Tomcat combined with URL redirect

I now have one Apache server and two Tomcat servers. They are connected using mod_jk module. And the load balancing is configured. All request will be redirected to the loadbalancer, in httpd.conf:
JKMount /* controller
The controller is the loadbalancer, and the working tomcat servers are worker1, worker2.
The problem is that, in addition to the automatic load dispatch, I also need a url matching redirection. Speicifically, the request for http://www.example.com/test1/index.html should go to worker1 (Tomcat), and http://www.example.com/test2/index.html go to worker2.
However, in both worker1 and worker2, the application structure is webapps/test/ structure.
I can use the mod_jk url mapping to dispatch /test1/ to worker1 and /test2/ to worker2, but the PATH will be /test1/ and /test2/ not /test/. Meanwhile, if I use the apache redirectMatch or url rewrite to change the /test1/(/test2/) to /test/, the mod_jk will not dispatch the url to the different worker now, since they have the same PATH.
How can I deal with this situation?
You need to make the application a root application in Tomcat. You can do this by adding a META-INF/context.xml to your app with the following:
<Context path="/"/>
I'd suggest you remove other apps from the webapps directory. Then you need to alter your apps web.xml so the servlet(s) are now mapped to the appropriate url with the appropriate contexts:
<servlet-mapping>
<servlet-name>TestApp</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>TestApp</servlet-name>
<url-pattern>/test1</url-pattern>
</servlet-mapping>
The app in the second JVM would need the url-pattern /test2 instead. For Apache/Tomcat connection I use mod_ajp rather than mod_jk. Here is what you'd need in Apache for mod_ajp:
<Proxy balancer://cluster>
BalancerMember ajp://127.0.0.1:8015 route=ajp13_node1
BalancerMember ajp://127.0.0.1:8016 route=ajp13_node2
</Proxy>
<Location "/test">
ProxyPass balancer://cluster/test stickysession=JSESSIONID
</Location>
<Location "/test1">
ProxyPass ajp://127.0.0.1:8015/test1
</Location>
<Location "/test2">
ProxyPass ajp://127.0.0.1:8016/test2
</Location>
This is assuming the AJP connector is listening on 8015 for the first JVM and 8016 for the second.
Perhaps a simple way to do it is to use urlrewrite filter on tomcat workers. According to documantation you should have the following rule on your urlrewrite.xml file:
<rule>
<from>^/test[0-9]*/(.*)$</from>
<to type="redirect">/$1</to>
</rule>
So workers would ignore the test1 or test2 URI part. And apache could work just the way you planned with mod_jk.

Mapping a URL between Apache and Tomcat, using mod_jk

I am using Apache/2.2.14 and Apache Tomcat/6.0.29 in a Ubuntu Server 10.04.3 LTS.
This is my jk.conf:
JkWorkersFile /etc/libapache2-mod-jk/workers.properties
JkMount /portal/* worker1
JkLogLevel debug
JkMountCopy All
And this is my workers.properties:
ps=/
# Define 1 real worker named worker1
worker.list=worker1
# Set properties for worker named worker1 to use ajp13 protocol,
# and run on port 8009
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.lbfactor=1
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300
The problem is that whenever I try to access tomcat via apache with: http://my.host.com/portal, tomcat replies with:
13:39:30,683 INFO [PortalImpl:3829] Current URL /portal/ generates exception: null
The problem goes away if I use a different mountpoint for the worker:
JkMount /portal/* worker1
But this forces me to access my tomcat instance here: http://my.host.com, which I do not want.
Is there any way of rewriting the URL using mod-jk?
You can skip all that configuration if you just use mod_proxy instead of mod_ajp...
ProxyPass /foo http://localhost:8080/bar
ProxyPassReverse /foo http://localhost:8080/bar
This will proxy /foo to local server URL /bar running on port 8080.

Sticky Session in apache doesn't work

This is currently my environment setup.
Apache Tomcat: Apache-Tomacat-7.0.21
Apache HTTP Server: c. Apache HTTP Server 2.2.19
Tomcat Connector JK 1.2.32 for Apache HTTP Server 2, mod_jk
I'm trying to implement sticky session but i still can't get it to work. I'm able to load balance between 2 machines in a cluster. Please advise what else i have missed out!
Following is my workers.properties file
# Define 2 real workers using ajp13 & 1 balancer
worker.list=balancer
#
worker.balancer.type=lb
worker.balancer.balance_workers=worker1,worker2
worker.balancer.sticky_session=True
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.lbfactor=50
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.recycle_timeout=300
# Set properties for worker2 (ajp13)
worker.worker2.type=ajp13
worker.worker2.host=X.X.X.X
worker.worker2.port=8009
worker.worker2.lbfactor=50
worker.worker2.cachesize=10
worker.worker2.cache_timeout=600
worker.worker2.socket_keepalive=1
worker.worker2.recycle_timeout=300
I've also set the jvmRoute in server.xml to:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1">