In my previous blog I showed how to cluster with JBoss EAP 6.0.3 in standalone mode, but standalone mode is really used in production, where the domain mode is the preferred way to manage multiple JBoss installations.
In this blog I will also cluster two JBoss nodes, but started in domain mode. To achieve that we need a domain master (domain controller) and slave (host controller), that push and respectively receive configuration. The deployment scenario is the following.
I have in the deployment diagram also added the concerned configuration file for each artifact, which I hope will help you to remember which configuration files goes to which artifact. Lets get started, but first some prerequisites.
- JBoss EAP 6 or AS 7. I will use JBoss EAP 6.0.1
- Apache Web Server. See http://magnus-k-karlsson.blogspot.se/2013/01/install-apache-web-server-on-red-hat.html
- mod_cluster for load balancing. See http://magnus-k-karlsson.blogspot.se/2013/01/how-to-install-jboss-eap-601-native.html
In this blog I will start everything up on the same machine, which is adequate for testing, but of course not for production, so when you move to production you need to change interfaces IP for each JBoss. But that is about it. Lets get started.
To simulate and keep things separated I have extracted the jboss-eap-6.0.1.zip into three folders:
The domain controller is configured with three configuration files.
- domain.xml - main configuration files
- host-master.xml - boot up configuration files, telling that this is domain controller.
- host.xml - additional configuration files for server group, such as system-wide properties and JVM configuration.
Lets first define our server group in ./domain/domain/configuration/domain.xml.
Then we will leave the ./domain/domain/configuration/host-master.xml unaltered and use defaults. The part that points out that this is domain controller is the below.
The last thing we need to do is to create a management user in the domain controller.
Now we are ready to start the domain controller.
If you wanted to bind the domain controller to a specific IP, you would have used the -Djboss.bind.address.management. Which property you see in the interface element in the host-master.xml configuration file.
Now lets move onto the host controller.
A host controller is a slave to the domain controller which listen for configuration and start/stop instruction. The host controller then feeds that information to all server node on a physical machine. The host controller is not really something special to only domain mode, but is also present in a standalone mode, but then not really used.
Lets get started with the configuration for the host controller. Lets open ./host1/domain/configuration/host-slave.xml and define the server nodes that will be managed by this host controller.
Since we are running everything on the same machine, we need to set the port-offset property. If this was running on a dedicated server you leave that out.
We use the server group that was defined in the domain controller.
Next we need to set up security to the domain controller. The host controller needs to know how to establish a connection to the domain controller. Here we use the same base64 password that we recieved when creating the management user for the domain controller.
The last thing we need to change, and this is because we are running everything on the same machine is the management port.
Now lets multiply the above configuration to host 2 also.
Now we are ready to start the host controllers.
You should now see the following in the domain controller log.
To test is installation, we need a clustered application. I will as in my earlier blog borrow a ready application from https://github.com/akquinet/jbosscc-as7-examples/tree/master/cluster-example.
But now we will use the new JBoss CLI tool to deploy and start and stop our server nodes. See my previous blog on how to deploy with CLI http://magnus-k-karlsson.blogspot.se/2013/01/how-to-deploy-and-undeploy-in-jboss-eap.html.
If you now look in each host controller log file, you should see the deployment. If everything is ok. Lets test the application, open http://127.0.0.1/cluster/index.jsf.
Now lets stop the server node, that you were served and test the replication.
And you should now see in that node server log.
Lets now hit the application again.