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
Box
, EC2 instance, etc.) or a physical image of an Operating
System.


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

cd $GLASSFISH_HOME

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

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

cd $GLASSFISH_HOME

echo 'AS_ADMIN_ADMINPASSWORD=adminadmin' > password

echo 'AS_ADMIN_PASSWORD=adminadmin' >> password

echo 'AS_ADMIN_MASTERPASSWORD=changeit' >> password

./bin/asadmin
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

./bin/asadmin
create-instance --port 5048 --nodeagent cloud-nodeagent
--systemproperties HTTP_LISTENER_PORT=58080 --cluster wines cabernet

./bin/asadmin
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



After
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="http://blogs.sun.com/arungupta/entry/totd_67_how_to_front">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)
automatically.



This scipt is tested on href="http://opensolaris.org/os/downloads/">Open Solaris
2008/11, href="http://www.microsoft.com/windows/windows-vista/default.aspx">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="http://blogs.sun.com/jclingan/entry/glassfish_clustering_in_under_10">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="http://wikis.sun.com/display/TheAquarium/ASAdmin">recorded
webinar!



href="http://blogs.sun.com/arungupta/entry/totd_69_glassfish_high_availability">TOTD
#69 explains how to use Sun Web Server and Load-Balancer
Plugin for the load balancer + clustering setup on Windows Vista. href="http://blogs.sun.com/arungupta/entry/totd_67_how_to_front">TOTD
#67 explains the same steps for Apache + mod_jk on Mac OSX.



Technorati: href="http://technorati.com/tags/glassfish">glassfish
cli href="http://technorati.com/tags/asadmin">asadmin href="http://technorati.com/tags/clustering">clustering
highavailability

Related Topics >>