Skip to main content

GlassFish asadmin CLI-driven Cluster Setup

Posted by arungupta on April 24, 2009 at 1:38 PM PDT

Here is simple script that:

  • Installs GlassFish
  • Creates a new domain using style="font-style: italic;">cluster profile
  • Create 2 instances
    in the cluster
  • Deploys a sample application to verify the cluster setup

Everything in just one simple script!

This script can be used on a virtual (Virtual
, EC2 instance, etc.) or a physical image of an Operating

style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
cellpadding="2" cellspacing="2">
echo A | java -Xmx256m -jar
~/Downloads/glassfish-installer-v2.1-b60e-darwin.jar -console


chmod +x ./lib/ant/bin/ant

./lib/ant/bin/ant -f setup.xml


echo 'AS_ADMIN_ADMINPASSWORD=adminadmin' > password

echo 'AS_ADMIN_PASSWORD=adminadmin' >> password

echo 'AS_ADMIN_MASTERPASSWORD=changeit' >> password

create-domain --user admin --passwordfile ./password --savelogin=true
--portbase 5000 --interactive=false --profile cluster cloud

./bin/asadmin start-domain cloud

./bin/asadmin create-node-agent --user admin --port 5048
--interactive=false --passwordfile ./password cloud-nodeagent

./bin/asadmin start-node-agent --interactive=false --passwordfile
./password cloud-nodeagent

./bin/asadmin create-cluster --port 5048 wines

create-instance --port 5048 --nodeagent cloud-nodeagent
--systemproperties HTTP_LISTENER_PORT=58080 --cluster wines cabernet

create-instance --port 5048 --nodeagent cloud-nodeagent
--systemproperties HTTP_LISTENER_PORT=58081 --cluster wines merlot

./bin/asadmin deploy --target wines --port 5048
--availabilityenabled=true samples/quickstart/clusterjsp/clusterjsp.ear

./bin/asadmin start-cluster --port 5048 --interactive=false
--passwordfile ./password wines

the script execution is complete, open up
"http://localhost:58080/clusterjsp". The page shows it is served from
the "cabernet" instance. Enter some session data by adding values in
the text box placed towards end of the page. Then
stop the "cabernet" instance as explained in href="">TOTD
#67 after the string "OK, now show time!".

Now load the page "http://localhost:58081/clusterjsp" and it shows that
the page is served from "merlot" instance. And the exact same session
data is displayed towards the bottom of the page.

It basically shows that the session data added in one instance is
replicated to the "buddy instance" ("merlot" in this case)

This scipt is tested on href="">Open Solaris
2008/11, href="">Windows
Vista, and Mac
OSX 10.5.x

The cluster and instance creation can be easily done using the
web-based admin console as href="">described
here. But this TOTD also shows the power of scriptability for
common GlassFish administration commands - asadmin is your hidden gem
and learn more about it in this href="">recorded

#69 explains how to use Sun Web Server and Load-Balancer
Plugin for the load balancer + clustering setup on Windows Vista. href="">TOTD
#67 explains the same steps for Apache + mod_jk on Mac OSX.

Technorati: href="">glassfish
cli href="">asadmin href="">clustering

Related Topics >>