Recent EntriesCouchbase Manager for Glassfish: Version 0.2
Friday, June 14 2013 HTTP Headers and JavaEE Saturday, June 1 2013 OCSP Java Bug (Part II) Saturday, May 18 2013 Debian 7.0 released! Sunday, May 5 2013 Glassfish HA using EJB Sunday, April 7 2013 BUG in Java OCSP Implementation (PKIX)? Friday, March 15 2013 SPNEGO/Kerberos in JavaEE (spnego.java.net) Sunday, March 3 2013 Testing WebRTC Saturday, February 16 2013 SPNEGO/Kerberos in JavaEE (PAC) Saturday, February 2 2013 SPNEGO/Kerberos in JavaEE Friday, January 18 2013 QuicksearchSyndicate This BlogAuthorBlog Administration |
Saturday, January 21. 2012Simple but Full Glassfish HA Using DebianDuring the past months I has been working in a project of which environment is mainly Windows (that is the reason of the previous entry about windows mod_proxy_html compilation The solutionLooking for information about the problem in the internet, I found lots of LB/HA sample solutions for TCP/IP enviroments in Linux, most of the times they involve two products (see for example this entry):
But in this entry a particular case is shown, a Java Application Server (Glassfish), and it is clear that there are better techniques for load balancing two Java Servers. For this reason my solution will use two other packages instead of haproxy:
Apache. The famous HTTP web server which is necessary to install mod_jk inside it. So the solution is quite clear now. First of all keepalived gives a virtual IP which commutes between two Apache/mod_jk boxes (only one httpd server works actively, the other one acts as a backup). The package uses scripts to check if the web server is working fine. The httpd box which has the active IP receives the requests and apache/mod_jk pair redistributes them between two Glassfish servers. So the first layer provides only HA and the second layer LB/HA (take into account that the work in the first layer is lighter, the hard process is performed by the App Server). My demo environment is the simplest one. Two debian wheezy boxes were virtualized (KVM) inside my laptop: debian1 (192.168.122.21) and debian2 (192.168.122.22). The Linux distribution was installed with the minimal number of packages. Each box will have an Apache/mod_jk and a Glassfish server. Cos the Glassfish 3.1.1 is configured as a cluster debian1 runs the Domain Administrator Server (DAS) too. Replicated session is used (session is sent from one instance to the other when it is changed) but mod_jk uses sticky distribution (the first request is distributed but all the rest from the same source are sent to the same Glassfish server). The keepalived software manages a virtual IP (192.168.122.23) which is assigned to the master host (host with the highest priority). I present a little diagram of my demo solution.
OpenJDK InstallationA Debian solution deserves OpenJDK (the open source JVM): # apt-get install openjdk-6-jdk Glassfish version 3.1.1 is going to be used and it is known that there are problems with old versions of JavaSE6. That was the reason to choose wheezy (OpenJDK 6b24) instead of squezze (6b18). JDK was installed in both machines. Glassfish InstallationThe Glassfish installation, although it is not very complicated, requires several steps (I have followed this guide).
So now we have a clustered (session replicated) application. Besides each cluster instance listens for AJP13 protocol in port 8009. Everything is ready for Apache/mod_jk configuration. In this demo I chose Glassfish but the main concepts (maybe changing some pieces) are the same for any application server. And as a final comment for this part, you already know that I personally recommend not to replicate sessions, this process has a big impact if the sessions are too many, too big and/or too volatile (but also be aware that in that case a server lost means a session lost). Apache/mod_jk InstallationBoth packages are part of the main Debian repository, so installing them is just a command like this: # apt-get install apache2 libapache2-mod-jk Configuration for JK module is placed in /etc/apache2/mods-available/jk.conf. I just used the debian default but commenting /jk-status and /jk-manager locations (I decided to define them inside the site). This config file points to /etc/libapache2-mod-jk/workers.properties as the workers configuration file. The important lines in the second file are the following: worker.list=loadbalancer,jk-status worker.debian1.port=8009 worker.debian1.host=debian1.demo.kvm worker.debian1.type=ajp13 worker.debian1.lbfactor=1 worker.debian2.port=8009 worker.debian2.host=debian2.demo.kvm worker.debian2.type=ajp13 worker.debian2.lbfactor=1 worker.loadbalancer.type=lb worker.loadbalancer.balance_workers=debian1,debian2 worker.loadbalancer.sticky_session=1 worker.jk-status.type=status There are two workers defined, debian1 and debian2 (the name of the worker has to be the same defined in the jvmRoute property), using AJP13 protocol on both virtual hosts with port 8009. Another worker loadbalancer is used to distribute requests between the two previously defined workers. The distribution is configured sticky. Finally the status worker (a page that informs about worker status) is defined with the name jk-status. No special tuning (timeouts and more) was done. Once mod_jk is configured the default site defined in /etc/apache2/sites-available/default adds two new locations to proxy the clusterjsp app and the status worker:
<Location /jk-status>
# Inside Location we can omit the URL in JkMount
JkMount jk-status
#Order deny,allow
#Deny from all
#Allow from 127.0.0.1
</Location>
# mount clusterjsp
JkMount /clusterjsp loadbalancer
JkMount /clusterjsp/* loadbalancer
Finally the mod_jk is enabled and apache2 restarted: # a2enmod jk # /etc/init.d/apache2 restart These steps have to be done in both hosts (debian1 and debian2). And, at this moment, both Apache servers are balancing the two glassfish clustered instances. As mod_jk detects application server failures the LB/HA of glassfish layer is achieved. Keepalived InstallationThe final package, keepalived, is installed following the debian way: # apt-get install keepalived This software has just a little configuration located in /etc/keepalived/keepalived.conf. This file just contains the following:
vrrp_script chk_http_port { # Requires keepalived-1.1.13
script "wget -q -T 1.0 -t 2 --delete-after -O /tmp/test.wget http://localhost:80/index.html"
interval 5 # check every 5 seconds
weight 2 # add 2 points of prio if OK
}
vrrp_instance VI_1 {
interface eth0
state MASTER # MASTER debian1, BACKUP debian2
virtual_router_id 51 # same id in both hosts
priority 101 # 101 on master, 100 on backup
virtual_ipaddress {
192.168.122.23 # virtual IP
}
track_script {
chk_http_port
}
}
A VRRP instance is defined in eth0 interface. This instance manages the IP 192.168.122.23. Host debian1 is declared MASTER with an initial priority of 101, debian2 is the backup instance with a priority of 100. A script chk_http_port is executed in both hosts and it assigns two points more. This way if debian1 Apache fails it only has 101 points while debian2 has 102 (100 + 2 added by the check) and the backup server is transitioned to master (the virtual IP moves from debian1 to debian2). As soon as debian1 Apache runs again (103 points are now assigned to debian1) this host become the master again. If whole debian1 fails (a hardware failure for example), the multicast packets, which are supposed to be sent by the master server, stop being received by the backup server and therefore its status will be risen to master (check VRRP protocol specification in RFC 2338). Take in mind that keepalived does not use typical virtual IPs (eth0:1 and so on), it does HA using VRRP which manages multicast and ARP. VRRP only works inside the same network (both machines have to be inside the same net). With keepalived the first layer is configured in HA (only one apache is working, the other is just awaiting as a backup server). The checking script is very simple, using wget a test page from the Apache is retrieved (timeout of one second but with two tries). If wget returns 0, the page was got successfully, in case of any other return code, the page was not returned and the check fails. Never test a glassfish page (doing that you are mixing layers and the results can be very weird). Here you have master configuration for debian1 and backup for debian2. ConclusionAs a conclusion I am going to present a video that shows my demo installation. By default debian1 is the master vrrp server and if clusterjsp page is requested, its apache/mod_jk redirects to any of the glassfish servers (debian1 in the video). Cos the module is configured sticky I can set some attributes in the session and debian1 is always my working glassfish. Now debian1-gf glassfish instance is stopped and clusterjsp is redirected to debian2 (now debian1 apache and debian2 glassfish are working). But then debian1 apache is stopped, debian2 transitions to master state (a tail for /var/log/messages displays keepalived information) and application is still working (now debian2 is doing all the job, apache and glassfish). After restarting debian1 Apache, this host becomes again the master. Finally the virtual machine of debian1 is suddenly stopped, debian2 transitions again to master. Because clusterjsp application was deployed with session replication the session is never lost in the video. For me it is clear that linux has also a good and simple LB/HA mechanism, keepalived is usually more than enough in typical TCP/IP client/server solutions. With this configuration a virtual IP that commutes between nodes is setup (only HA at the first layer). This layer consists in a software load balancer and, as I commented, usually generic haproxy is used. Nevertheless apache/mod_jk is a much proper solution for AJP13 capable Java Application Servers. The second layer (glassfish in this case) has LB/HA features, cos the load balancer (mod_jk) distributes the load between the two instances at the same time it checks the server status. So the second layer processes requests in parallel. The problem for my customer was that their linux boxes were RedHat6 and keepalived is not distributed by default in the distro (it seems that cluster extra software is needed in order to get this package). That's why Debian rules! Trackbacks
Glassfish 3.1.1 med Apache httpd og mod_JK som load balancer (under arbeid)
Overskrift Ingress... Laste ned programvare Installer apache httpd Installere modjk Last ned Konfigurere Glassfish Bug i grizzly GLASSFISH17068
Weblog: Confluence: Arkivportalen
Tracked: Feb 15, 09:56
Glassfish 3.1.1 med Apache httpd og mod_JK som load balancer (under arbeid)
Apache httpd og modJK som load balancer. Oppsett av Apache httpd som lastbalanserer (og failover) i front av Glassfish 3.1.1. Eksemplet er testet i vårt utviklingsmiljø. Miljø Maskin Clusterinstans mesan1PC DAS,...
Weblog: Confluence: Arkivportalen
Tracked: Feb 15, 10:36
Couchbase Manager for Glassfish: More Tests
I am continuing with my little coubase-manager project. Following the ideas that I already commented in the previous entry, I have setup a two KVM debian boxes with a two-instance glassfish cluster, both instances access to a single couchbase installed in
Weblog: Ricky's Hodgepodge
Tracked: May 19, 22:59
Couchbase Manager for Glassfish: In Action
All the last entries in the blog are dealing with my new idea about the couchbase-manager whose first version was released a few weeks ago. I think the current status is good enough to release a first testing version. The main problem is that I have teste
Weblog: Ricky's Hodgepodge
Tracked: Aug 11, 13:21
Glassfish HA using EJB
I have received some comments about the old entry that installed a full glassfish HA solution using debian, people complain that the post did not deal with Stateful EJBs. A Stateful EJB is a enterprise bean that acts as a server-side extension of the clie
Weblog: Ricky's Hodgepodge
Tracked: Apr 07, 11:26 |

Comments
Mon, 17.06.2013 17:51
Wonderful article! We are linking to this great article on our site. Keep up the good writing.
Fri, 07.06.2013 17:56
Hi Aleksadar, It depends on what library you're using. In case of the spnego filter I'm usi [...]
Thu, 06.06.2013 15:16
I set tomcat 7 with spnego on red hat machine and automatic authentification on windows server [...]
Tue, 04.06.2013 15:39
Hi Simon, I wrote another entry about this issue and, at least, another one is coming. I'm [...]
Mon, 03.06.2013 15:07
Hey Ricky Thanks for the cool writeup! Did you get any respone concerning the JAVA bug rep [...]
Tue, 28.05.2013 05:48
Do you really want your blog to be in light-grey on a white background? Its so hard to read [...]
Thu, 04.04.2013 10:13
Hi Rulet, Usually this is a bug in the distribution packages, I suppose you're using ubuntu [...]
Wed, 03.04.2013 18:05
Whem trying to install libasound2:i386 it gives an error that /usr/share/alsa/alsa.conf cannot [...]