Sticky Session in apache doesn't work - apache

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">

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 web server multiple workers

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

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

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.

Disable stickyness on apache mod_proxy_balancer

I want to configure Apache Web Server to meet the following requirement:
Access server1 while it's working.
Access server2 only when server1 does not respond. When server1 responds, access server1 again.
To do so, i tried configuring Apache Web Server (2.2) using mod_proxy_balancer. My problem is that session stickyness seems to be enabled by default. When server1 is not responding, the balancer redirects to server2, but when server1 recovers, the balancer does not access server1 until i clear sessions in my browser.
My balancer configuration:
ProxyPass /test balancer://mycluster
<Proxy balancer://mycluster>
BalancerMember server1-url retry=10 loadfactor=100
BalancerMember server2-url status=+H retry=10
</Proxy>
Is there any option to disable stickyness?
Thanks in advance.
You can do this with Mod_JK with below properties. Reference configuration can be found at Apache httpd 2.2.x + mod_jk 1.2.30 + tomcat 6 Error: Could not find worker with name 'XXXXX' in uri map post processing
# Disable Sticky Session
worker.loadbalancer.sticky_session=0
# Define preferred failover node for worker1
worker.worker1.redirect=worker2
# Disable worker2 for all requests except failover
worker.worker2.activation=disabled