ColdFusion provides cluster support if it is installed with Enterprise license, Trial, or Developer edition. Clustering is a process of grouping of two or more instances of ColdFusion servers for better performance, load balancing, and failover.
In this blog, we’ll see how to configure a horizontal cluster by adding remote instances and create connector using webserver configuration tool. We will be using two ColdFusion 2021 local instances (from server A) and two remote instances (from server B ) to create the cluster in a Windows environment.
The setup
- The two local instances are named as localsrv1 and localsrv2 on server A.
- The two remote instances are named as remotesrv1 and remotesrv2 on server B.
- IIS is installed on server A.
Note: For session replication or sticky sessions, enable J2EE session variables under Memory Variables page in ColdFusion administrator for all the server instances in the cluster.
Registering a remote instance
Let’s see how to register remote instances – remotesrv1 and remotesrv2 on local server A.
1). In the ColdFusion Administrator of server A, click Enterprise Manager >Instance Manager>Register Remote Instance.
2). Add details, such as, instance, remote host, remote port, http port, JVM route, AJP secret key, and PMT shared secret key.
* The instance name is a string that is used to identify the instance. In our setup, they’re called remotesrv1 and remotesrv2.
* The remote port and HTTP port are displayed in the instance manager page of remote server. These ports are defined in the server.xml file available in “\instance-name\runtime\conf” folder of the instance.
*Enter Admin Component port, Admin Component username, and Admin Component password. The default port is 8993 defined in start.ini file located at \ColdFusion2021\cfusion\jetty(not a mandatory field).
*PMT shared secret key is generated in remote instance’s ColdFusion Administrator page under monitoring section.
*AJP secret key value can be found in the server.xml file of remote instance located at \ColdFusion2021\remotesrv1\runtime\conf.
*JVM route is nothing but remote instance name. The JVM route is an attribute that acts as an identifier for a particular Tomcat worker.
Note: A remote instance and a local instance cannot have the same JVM route if they are added in a cluster with sticky session enabled . Registering “remotesrv1” instance:
Registering “remotesrv2” instance:
Create a cluster:
The ColdFusion administrator console provides easy and simple way to create and manage the clusters. Follow the below steps to create a cluster:
1). Go to the Enterprise Manager > Cluster Manager section in ColdFusion administrator.
2). Create a new cluster and add the required instances. We are adding two local and two remote instances.
3). Check/Clear the sticky session and enable session replication and click on Submit.
4). ColdFusion will automatically add the cluster configuration in “server.xml” of all the instances participating in cluster on local server (in our case, Server A). To add the cluster block in remote instance’s server.xml file (i.e remotesrv1 and remotesrv2), add the following block between the entries </host> and </engine>:
Open the server.xml file in remotesrv1 and add the below cluster block:
<Cluster channelSendOptions=”8″ className=”org.apache.catalina.ha.tcp.SimpleTcpCluster”>
<Channel className=”org.apache.catalina.tribes.group.GroupChannel”>
<Membership address=”228.0.0.4″ port=”45564″ className=”org.apache.catalina.tribes.membership.McastService” dropTime=”3000″ frequency=”500″/>
<Receiver selectorTimeout=”5000″ address=”auto” autoBind=”100″ port=”4001″ className=”org.apache.catalina.tribes.transport.nio.NioReceiver” maxThreads=”6″/>
<Sender className=”org.apache.catalina.tribes.transport.ReplicationTransmitter”>
<Transport className=”org.apache.catalina.tribes.transport.nio.PooledParallelSender”/>
</Sender>
<Interceptor className=”org.apache.catalina.tribes.group.interceptors.TcpFailureDetector”/>
<Interceptor className=”org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor”/>
</Channel>
<Valve filter=”” className=”org.apache.catalina.ha.tcp.ReplicationValve”/>
<Valve className=”org.apache.catalina.ha.session.JvmRouteBinderValve”/>
<ClusterListener className=”org.apache.catalina.ha.session.ClusterSessionListener”/>
</Cluster>
Note that the Membership IP address (228.0.0.4) and multicast port (45564) remains same for all the instances, but the receiver port is unique to avoid port conflicts among the instances in cluster. Above, we have assigned “4001” as receiver port for remotesrv1, add the cluster block and change the receiver port for remotesrv2 to “4002”.
Cluster block from remotesrv2:
<Cluster channelSendOptions=”8″
className=”org.apache.catalina.ha.tcp.SimpleTcpCluster”>
<Channel className=”org.apache.catalina.tribes.group.GroupChannel”>
<Membership address=”228.0.0.4″ port=”45564″
className=”org.apache.catalina.tribes.membership.McastService”
dropTime=”3000″ frequency=”500″/>
<Receiver selectorTimeout=”5000″ address=”auto” autoBind=”100″ port=”4002″
className=”org.apache.catalina.tribes.transport.nio.NioReceiver” maxThreads=”6″/>
..
..
</Cluster>
5). The next step is to add the “address” attribute in server.xml file of all the instances to bind the AJP connector with IP address (default binding is 127.0.0.1 or ::1, depends on the machine) .
Open the server.xml file and bind the IP address by adding the “address” attribute in AJP connector block for all the instances in cluster. Save the changes and restart all the instances in cluster.
6). Create a connector using webserver configuration tool in Server A. Run wsconfig.exe tool located at \ColdFusion2021\cfusion\runtime\bin folder as an administrator and select the cluster name under AppServer Cluster option. Click OK.
7). Make sure the IP address in server.xml matches the “host” name property in “workers.properties” file located at \ColdFusion2021\config\wsconfig\{magic-number} folder.
Our cluster is now ready to accept the requests via IIS. To check if our cluster is configured correctly and working properly, run the below code which reports IP address and instance name. If a node in the cluster goes down, request should be automatically routed to next available node in round robin fashion.
<cfscript>
hostaddress = createObject("java", "java.net.InetAddress").localhost.getHostAddress();
instancename = createobject("component","CFIDE.adminapi.runtime").getinstancename();
</cfscript>
IP Address: <cfdump var="#hostaddress#"><br />
Instance Name : <cfdump var="#instancename#">
You must be logged in to post a comment.