Glassfish 3.1 – Clustering Tutorial

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.

Glassfish Cluster


  • 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.


  1. 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.

    2 server instances

  2. 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
  3. 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.
  4. Start the web admin console
    (because of 3. it will switch to https and complain about the non-trusted certificate, confirm the exception!)

    Glassfish Admin Console

  5. Create cluster c1

    Glassfish Admin Console

    (command-line alternative: ./asadmin create-cluster c1)

  6. Create instance i1

    Glassfish Admin Console

    (command-line alternative: /asadmin create-local-instance –cluster c1 i1)

  7. Start cluster c1
    Starting the cluster will start up the relevant instances.

    Glassfish Admin Console

    (command-line alternative: ./asadmin start-cluster c1)

  8. 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

    Create instance i2

  9. 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.

    New Node

    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.

    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.

  10. Start instance i2 with DAS
    The next start of the cluster both instances will be started automatically.

    Instances i1 and i2

  11. Deployment of test application
    We are going to a hello-world-class application to the cluster c1.

    Deployment Test Application

    Deployment Test Application

  12. Run the test application on the 2 nodes

    Sample application on 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).


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 lucid partner)
    sudo apt-get update
    sudo apt-get install sun-java6-jdk
    ..install Glassfish: Download from (for example wget
    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) and the 2 instances and 102.

    Network adapters

  • /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
    #101 for node n1
  • 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


  1. Oracle GlassFish Server 3.1 High Availability Administration Guide
  2. Oracle Administration Guide (asadmin utility) 
  3. Clustering in GlassFish Version 3.1 (Introduction on
  4. Tim Quinn’s Blog – Securing Administration in GlassFish Server 3.1

15 thoughts on “Glassfish 3.1 – Clustering Tutorial

  1. Pingback: Community documenting their GlassFish 3.1 experiences

  2. Pingback: Glassfish 3.1 – Clustering Tutorial « Onur's Realm

  3. Pingback: Glassfish 3.1 – Clustering Tutorial (via The JavaDude Weblog) « Onur's Realm

  4. Pingback: Glassfish 3.1 – Clustering Tutorial Part2 (sessions) « The JavaDude Weblog

  5. 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 …

  6. 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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s