Glassfish Clustering, after being absent from version 3, made its re-debut after 2.1 in the current version 3.1
I was eager to get my hands on and tried to make sense of some information from various sources (see reference).
Clustering is quite a sophisticated subject, which you dont need to cover during development time, but at some stage (deployment to production) you better off knowing how it works and verify your application runs in the clustering environment.
I compiled the most essential steps in this instant-15min-tutorial creating the most simple cluster: 2 nodes with 1 instance each, 1 node also runs the DAS.
Prerequisites:
- 2 Glassfish 3.1 installations. I recommend using 2 server running as Virtualbox or VMWare guests. Alternatively you could use 2 EC2 instances.
- The guest running node2 must run a SSH server. See Appendix.
- I recommend running as user “glassfish” not as root. Specifically because the admin console uses SSH to control the remote instance.
- Basic understanding of the terminology node, instance, cluster (see reference 3.)
- A simple webapp (hello-world level) to do a test deployment. Look for the Netbeans basic tutorials (without DB access) if you dont have one.
Limitations and Remarks:
- Ubuntu Linux is used for both host and guest server systems. For Windows the same steps in Glassfish apply, only the location and syntax might differ slightly.
But the installation of SSH for Windows server differs and is not part of this tutorial. - This tutorial only gets you going, there is lots of information to read up and it takes more time to harden and tune your cluster setup !
Check the reference section. - All steps can be done with console only (using asadmin command), but here the web console is used as far as possible.
- At least 3 GB RAM is required for a decent performance of 2 servers as virtual guests.
Tutorial:
- Create 2 server instances
I installed 2 Ubuntu 10.04 LTS server running in Virtualbox (link), added the last JDK and the Glassfish zip (link).
Call them n1 and n2 and make sure they can connect to each other. (Ping and SSH)
See appendix for installation hints. - Start DAS domain (Domain Administration Server)
The default domain in the Glassfish zip file is domain1. We will stick to it for this tutorial and keep the default user admin (without password) user.
From the bin folder execute: ./asadmin start-domain domain1 - Enable remote administration
From the bin folder execute: ./asadmin enable-secure-admin and restart the domain
It is crucial to this, otherwise you will bounce at the second node while creating the second instance with an error:
Failed to rendezvous with DAS on n1:4848. Please check if this server is running, that the host and port are correct, and that this server is configured to allow remote access.
You can check the remote administration by login into n2 and executing ./asadmin –host n1 –port 4848 list-instances
If you dont get “HTTP connection failed with code 403, message: Forbidden” its fine. - Start the web admin console
http://n1:4848
(because of 3. it will switch to https and complain about the non-trusted certificate, confirm the exception!)
- Create cluster c1
(command-line alternative: ./asadmin create-cluster c1)
- Create instance i1
(command-line alternative: /asadmin create-local-instance –cluster c1 i1)
- Start cluster c1
Starting the cluster will start up the relevant instances.
(command-line alternative: ./asadmin start-cluster c1)
- Create instance i2
Open a terminal for n2, navigate to the {glassfish_home}/bin folder and execute: ./asadmin –host n1 –port 4848 create-local-instance –cluster c1 i2 - Enable SSH for remote access (from DAS to n2)
Executing the above command (create-local-instance from n2) uses the hostname to create a new node entry in the DAS.We need to change to type SSH (to enable the remote control features) and enter proper node name and password. Before this step I recommend to test SSH access from n1 (DAS) to n2 in a terminal with ssh glassfish@n2
If you can access then proceed with the node settings.Remark: There are other authentication methods. I would recommend the keyfile option. For the sake of simplicity of this tutorial we use the fix password option.
Alternative to steps 8 and 9: You can create a new node in the DAS (above settings) and create the instance i2 from the DAS using the remote node.
- Start instance i2 with DAS
The next start of the cluster both instances will be started automatically. - Deployment of test application
We are going to a hello-world-class application to the cluster c1. - Run the test application on the 2 nodes
Where to go from here: There is a myriad of settings and tuning options to experiment with and to try out. I try to find out more about memory, sessions, load balancing, resources in part 2 (stay tuned).
Update 2011-05-12: Part2 (sessions)
Read the Oracle docs for details (some is a bit lengthy and hard to read and digest, if you are in a hurry).
Appendix
Virtualbox creating 2 identical instances
- Create one Ubuntu instance with JDK and Glassfish, export it and import it as a second instance with a different name
Reminder: Run glassfish under a separate user.
How to ..
..install ssh server (Ubuntu): sudo apt-get install openssh-server
..install JDK: enable the canonical partners entry in /etc/apt/sources.list (something like deb http://archive.canonical.com/ubuntu lucid partner)
sudo apt-get update
sudo apt-get install sun-java6-jdk
..install Glassfish: Download from glassfish.java.net (for example wget http://download.java.net/glassfish/3.1/release/glassfish-3.1.zip)
unzip it and make sure it belongs to the glassfish user ! (chown glassfish:glassfish -R * in the glassfish v3 folder) - Virtualbox Preferences
- Network settings for the 2 instances
1 adapter bridged (to access the web)
1 host-only, this way the host gets (with above settings) 192.168.56.1 and the 2 instances 192.168.56.101 and 102. - /etc/network/interfaces (fix IP)
# The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet dhcp auto eth1 iface eth1 inet static address 192.168.56.102 #101 for node n1 gateway 192.168.56.255 netmask 255.255.255.0
- add n1 and n2 with their respective ip addresses in the hosts file the host and the 2 guests, so you can use the domain n1 and n2
Reference
Thanks for the tutorial!
Very nice work!
nice tutorial, thank you!
looking forward to see the loadblalancing stuff
Pingback: Community documenting their GlassFish 3.1 experiences
Pingback: Glassfish 3.1 – Clustering Tutorial « Onur's Realm
Pingback: Glassfish 3.1 – Clustering Tutorial (via The JavaDude Weblog) « Onur's Realm
Pingback: Glassfish 3.1 – Clustering Tutorial Part2 (sessions) « The JavaDude Weblog
Hii…..
Thanks a lot for this tutorial, and Im new on Ubuntu.
How about if I using Ubuntu 10.04-Desktop (not server) for node-1 and node2…..???
Can it work properly….????
Thanks …
Does this really work on 2 EC2 instances? I read here: http://www.java.net/node/707204 that EC2 does not support multicast.
If you unable to install jdk6 on ubuntu10.4 please follow this step.
Since this installation make me problem and took 1/2day googling time (suppose 15minute configuration).
hope this will help
wget https://raw.github.com/flexiondotorg/oab-java6/master/oab-java6.sh -O oab-java6.sh
chmod +x oab-java6.sh
sudo ./oab-java6.sh
apt-get install sun-java6-jdk
One of the most wonderful tutorials I have ever seen . With your tutorial seems like a cake walk . Appreciate its just what you need concise.
Congratulation!! Your tutorial is very insteresting!
can i use this tutorial for a web application that use a database(JavaDB) ??? thank you very much
Thank you very much. this post is very useful.
excellent tutorial,it is much usefull thanks