Overview
After I looked around the web, I’ve found a few good howto’s about glassfish cluster configuration, but either they use only single machine clusters or they have some other disadvantages in my eyes. So I’ve decided to write my own article about this.
This article will describes how to set up a two machine cluster which consists of the domain administration server (DAS) and a “normal” node. Thereby the DAS also works as such a normal node.
This article uses Glassfish v2.1.
Before the installation
You have to ensure, that your network is configured properly, especially the dns system. If there are problems, there will be curious problems while setting all up. I’ve done this using the hosts file.
10.0.0.1 das-host 10.0.0.2 node2-host 10.0.0.x nodex-host
The next thing is the firewall. The nodes communicating using a couple of ports. For setup and testing I’ve configured my firewalls to accept everything from all the other nodes, so there are no problems for the nodes to communicate with each other.
Setting up the DAS
Because the DAS server needs cluster support, we have to configure this first.
There are two ways to do this.
- install the glassfish server using:
ant -f setup-cluster.xml
- activate cluster support using the admin console
- go the the admin console (e.g. http://localhost:4848)
- select from the common task: Enable Cluster Support
Now start up the server using:
asadmin start-domain domain1
In the next steps, I will create the cluster, then a node-agent and one instance running on the DAS server using the cli.
In most cases you have to specifiy your admin username and password. This can be done using the –user and –passwordfile parameters, but for simpler reading I will omit this. The server will ask you in this case.
- Create the cluster:
asadmin create-cluster cluster1
This creates a cluster on the local server (the DAS) with the name cluster1.
- Create the node agent:
asadmin create-node-agent das-agent
This will create the node agent for the current node.
- Create the instance for the current node:
asadmin create-instance --nodeagent das-agent --cluster cluster1 instance1
This will create the instance instance1 associated with the node agent das-agent and the cluster cluster1.
- Now start up the node agent and the associated instance:
asadmin start-node-agent --syncinstances=true --startinstances=true das-agent
- –syncinstances=true says that the node agent should synchronize its instances with the central repository of the DAS
- –startinstances=true says the the node agent should start all its instances (instance1 in our case)
Now the domain administration server is up and running.
The first node is also running.
Setting up the second node
Now come to setup the second node.
Because the second node should only work a “computing” node, we do not need to install the whole application server, just a node agent.
I omit user and password parameters here too. You have to enter the DAS login informations when asked for.
- Install the node agent:
ant -f setup-cluster.xml create-node-agent -Ddas.host=das-host -Dnodeagent.name=node2-agent
- -Ddas.host=das-host sets the hostname of the domain administration server
- -Dnodeagent.name=node2-agent sets the name of the local node agent
- Create the new instance:
asadmin create-instance --host das-host --nodeagent node2-agent --cluster cluster1 instance2
This will create the new instance associated with the node agent node2-agent and the cluster cluster1. The –host parameter specifies the hostname of the domain administration server.
- Start the instance:
asadmin start-node-agent --syncinstances=true --startinstances=true node2-agent
Now the local node agent starts, synchronizes with the das server and starts all local instances (only instance2 in our case)
Now your cluster is running with two nodes. To add more nodes, just repeat the three above steps as much as you want.
Deploying applications to the cluster
For deploying applications to the cluster, just type on the das server
asadmin deploy --user admin --target cluster1 MyApplication.ear
This will deploy the application to the whole cluster.