Home > HowTo, Linux > How to setup Cluster on Glassfish v3

How to setup Cluster on Glassfish v3

August 30th, 2011 Leave a comment Go to comments

How to setup Cluster on Glassfish v3

This how to imposes that you already have glassfish v3 setup and:
– running under the user “fish”
– have ssh key trust between both servers (howto setup that)
To setup glassfish it is as simple as downloading .zip file and unzip into a folder, the importat
steps is to setup the path variables etc…
I did this setup on CentOS 6 / RedHat 6 (64x)
Pre-requisite
Set remote admin (on the DAS)
# asadmin enable-secure-admin
# service glassfish restart

CLUSTER ARCHITETURE

clustering glassfish 3

Important to note that the instance SSH (only hasĀ  JVMs for the applications running and the DAS is a JVM plus the apps JVMs)
another note the HTTP Load Balance is quite useless, it is a Apache Plugin that “talks” to the Glassfish. So you will always need
another
box for the LoadBalancing, I personally use balance witch is quite simple andĀ  amazing!

SETUP THE CLUSTER
1. Login to the DAS
http://server:4848/
2. Cluster > New (enter cluster1), Leave Instance blank Hit Save
3. Create New Cluster
Cluster > cluster1 > Instance > New, fish_1 (node: localhost-domain1 )
4. Start the Cluster
Cluster > (select cluster1), Start (should change to Running )
5. Create instance fish2
Open a terminal for fish2, navigate to the {glassfish_home}/bin folder and execute:
# ./asadmin –host infofishqlt1 –port 4848 create-local-instance –cluster cluster1 fish_2
( it will then ask for the user and password )
6. Setup Node
Nodes > fish2,
Type: SSH
Node Host: fish2
Force: [x] Enabled
(SAVE)
Then start Cluster > (select cluster1), Start (should change to Running )

::Troubleshooting tips::
Sometimes a glassfish instance get on Stop mode but its actually running.
What I usually do is login on the server list glassfish process
# ps -ef |grep glassfish
Manually kill the bad instance
# kill Then start it from the GUI

A good way to monitor if all is OK
# asadmin list-instances -l
NAME HOST PORT PID CLUSTER STATE
fish_1 localhost 24848 4606 cluster1 running
fish_2 fish2 24849 1823 cluster1 running

Logs:
Remote Instance:
$GLASSFISH_HOME/glassfish/nodes///logs/server.log
ex: /opt/glassfish3/glassfish/nodes/fishqlt2/fish_2/logs/server.log

Error:
“There is a process already using the admin port 4848 — it probably is another instance of a GlassFish server.”

Something is wrong with name resoultion of your local server!
set your server name to 127.0.0.1
# vim /etc/hosts
Be sure the server name is correctly set at
# cat /etc/sysconfig/network
# hostname
NOTE: On a Ubuntu system there is a file called /etc/hostname

Error:
“Failed to rendezvous with DAS”

Must enable remote admin and restart glassfish:
# asadmin enable-secure-admin

Error:
“WARNING: Command _register-instance-at-instance did not complete successfully on server instance fish_1: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake”

Setup the ssh key authentication before executing the command
# ssh-keygen -t rsa
# ssh-copy-id -i ~/.ssh/id_rsa.pub fish1
# ssh fish1 ls /tmp

::Apendix::
Setup JVM
Add 64 bit config,
Configurations > cluster1-config > JVM Settings > JVM Options (Add JVM Option)
-d64

Change to set how many memory you want your JVM to use:
-Xmx512m

Using the Command Line Interface for Monitoring Clusters
# get-health myCluster

Glassfish start script (copy to /etc/init.d/glassfish )

#!/bin/bash
#Script to start/stop/restart GlassFish
# chkconfig: 2345 13 87
# description: GlassFish v3 Daemon
# Source function library.
# Only works for user fish, if visudo is set correctly and path are loaded!
. /etc/init.d/functions

JAVA_HOME=/opt/jrockit
GLASSFISH_HOME=/opt/glassfish3/glassfish
PATH=$JAVA_HOME/bin:$PATH

#Set Env
export JAVA_HOME=$JAVA_HOME
export GLASSFISH_HOME=$GLASSFISH_HOME
export PATH

case $1 in
start)
sudo -u fish sh $GLASSFISH_HOME/bin/asadmin start-domain domain1
;;
stop)
sudo -u fish sh $GLASSFISH_HOME/bin/asadmin stop-domain domain1
;;
restart)
sudo -u fish sh $GLASSFISH_HOME/bin/asadmin stop-domain domain1
sudo -u fish sh $GLASSFISH_HOME/bin/asadmin start-domain domain1
;;
*)
echo “Usage: {start|stop|restart}”
exit 1
;;
esac
exit 0

NOTE:
Only works for user fish, if visudo is set correctly and path are loaded, and
correct permissions are setup correctly. Add this lines to visudo:
Defaults always_set_home
Defaults env_keep += “HOME”
Defaults env_keep += “PATH”
Defaults env_keep += “JAVA_HOME”

Now you should be able to do the cmd and have glassfish running on a non-root account:
# service glassfish start

Ref.
http://download.oracle.com/docs/cd/E18930_01/html/821-2426/index.html
http://glassfish.java.net/public/clustering31.html

  1. No comments yet.
  1. No trackbacks yet.

VAMOVE *

*