Setting up Glassfish Cluster

Glassfish Server can run in various profile - developer, cluster etc. In order to setup the cluster we need to create a domain with Cluster Profile or in else you can enable the Cluster Support for the existing domain.
Let us create a cluster with 3 machines of which 2 machines will run Application Server Instances and one of them will run DAS - the Domain Administration Server. Following is the step-by-step procedure to setup the cluster.

  1. Install Glassfish on all the machines that must participate in the Cluster.
  2. Start the Server on all 3 machines , Test the working of server through Admin Console
  3. Change the master password (you must stop the domain before you change the master password). Keep the same master password on all machines. Not a must from Glassfish but for the ease of setting up things.
  4. Enable Cluster Support using Admin Console (Application Server >> Add Cluster Support. Alternatively, you can create a new domain using NetBeans specifying the profile of domain as Cluster)
  5. On Machine1 create a cluster using (we will consider this machine as DAS which will host Cluster Config). Use the following command to do so:
    1 asadmin create-cluster --user admin --passwordfile passwords.txt MyCluster
    I suggest you do not create any instance on this server and let this server be purely for Domain Administration Purpose.
  6. Do the following on other two machines i.e. Machine2 and Machine3
    1 asadmin create-node-agent --user admin --passwordfile passwords.txt --host Machine1 --port 4848 Machine2Agent
  7. Now create 1 instance on this machine as follows:
    1 asadmin create-instance --user admin --passwordfile passwords.txt --host Machine1 --port 4848  --nodeagent Machine2Agent
    2        --cluster MyCluster Machine2Instance

    Note that we are creating the agent and instance on Machine2 but for the Cluster on Machine1.
    Be patient - Creation of Instance will take some time as it needs to pick up config info from the Machine1. It communicates with Machine1 through 4848 the port mentioned.
  8. Execute the above steps on Machine3 as well. Change the name of agent and instance to reflect Machine3
    Make a note through Admin Console on Machine1 the Node Agents Sections. You will find the nodes of Machine2 and Machine3 along with their instances running there.
  9. Now start the agents on both the machines (Machine2 and Machine3) using the following CLI
    1 asadmin start-node-agent --user admin --passwordfile passwords.txt --syncinstances=true
    The --syncinstances==true is a must.
    Also note that it is at this time that the directory structure of the instance(s) created on this Machine gets created under nodeagents folder in your appserver. Take a look
  10. Verify that all instances of Machine2 and Machine3 are in running state - Use Admin Console >> Node Agents >> Select Node Agent. Also verify that the instances and their state is visible from Clusters >> MyCluster tab.
  11. Make note of the HTTP Ports allocated to the Instances - Admin Console >> Clusters >> MyCluster >> Instances >> Select Instance >> General Properties Tab Page
  12. Go to MyCluster >> Applications >> Deploy >> and Deploy a web application
    Ensure that your web.xml contains <distributable/> tag
    Also ensure that available checkbox is ticked before you deploy the application
  13. If required, restart all agents on their respective machines with --syncinstances option. Once the instances are restarted check the Clusters >> MyCluster >> Machine1Instance >> Monitor >> Applications >> Select the dropdown - You must be able to see the application you had deployed on the cluster.
  14. Use instance specific ports to check that the application is running on all Instances. for e.g.
    http://Machine1:38081/clusteredapplication


Congratulations - You have setted up the cluster and deployed an application on it. Check out my post on Load Balancing

你可能感兴趣的:(Web,UP,Netbeans,Go,Glassfish)