Load balance HTTP requests among a predefined set of servers by using undertow.
| Resources | |
|---|---|
| Instance directories: |
|
| Application URLs: |
|
| Resources |
/home/student/AD248/labs/cluster-lb/cluster.war
|
Outcomes
You should be able to configure a Red Hat JBoss Enterprise Application Platform (JBoss EAP) load balancer responsible for balancing the requests between the available hosts in the cluster.
Run the following command to prepare the environment.
[student@workstation ~]$ lab start cluster-lb
In this guided exercise, you run three standalone instances.
The first instance is the load balancer, and uses the standalone-load-balancer.xml configuration.
The second and third instances are cluster members, and use the standalone-ha.xml configuration.
Instructions
Start the standalone JBoss EAP servers.
The first standalone server is a load balancer with the following configuration:
| Base directory |
/home/student/AD248/labs/cluster-lb/lb-instance
|
| Configuration |
standalone-load-balancer.xml
|
| IP for public interface |
172.25.250.9
|
To configure it, run the following commands from the workstation machine:
[student@workstation ~]$cd /opt/jboss-eap-7.4/bin[student@workstation bin]$./standalone.sh \--server-config=standalone-load-balancer.xml \-Djboss.server.base.dir=/home/student/AD248/labs/cluster-lb/lb-instance \-Djboss.bind.address=172.25.250.9
The second standalone server is a cluster member. Use the following parameters to start it:
| Base directory |
/home/student/AD248/labs/cluster-lb/server1
|
| Configuration |
standalone-ha.xml
|
| IP for public interface |
172.25.250.9
|
| Port offset |
100
|
| Node name |
server1
|
To configure it, run the following commands from the workstation machine:
[student@workstation ~]$cd /opt/jboss-eap-7.4/bin[student@workstation bin]$./standalone.sh --server-config=standalone-ha.xml \-Djboss.server.base.dir=/home/student/AD248/labs/cluster-lb/server1 \-Djboss.bind.address=172.25.250.9 -Djboss.socket.binding.port-offset=100 \-Djboss.node.name=server1
The node name is required to use the sticky session feature.
The third standalone server is a cluster member. Use the following parameters to start it:
| Base directory |
/home/student/AD248/labs/cluster-lb/server2
|
| Configuration |
standalone-ha.xml
|
| IP for public interface |
172.25.250.9
|
| Port offset |
200
|
| Node name |
server2
|
To configure it, run the following commands from the workstation machine:
[student@workstation ~]$cd /opt/jboss-eap-7.4/bin[student@workstation bin]$./standalone.sh --server-config=standalone-ha.xml \-Djboss.server.base.dir=/home/student/AD248/labs/cluster-lb/server2 \-Djboss.bind.address=172.25.250.9 -Djboss.socket.binding.port-offset=200 \-Djboss.node.name=server2
Deploy the cluster.war application.
The cluster application should be deployed to the two standalone servers of the cluster. You must deploy the application twice, once for each host.
Open a new terminal window and run the management CLI tool to connect to the first cluster instance cluster with the following commands:
[student@workstation ~]$cd /opt/jboss-eap-7.4/bin[student@workstation bin]$./jboss-cli.sh -c --controller=127.0.0.1:10090
Deploy the cluster application:
[standalone@127.0.0.1:10090 /]deploy \/home/student/AD248/labs/cluster-lb/cluster.war
Connect to the second instance of the cluster:
[standalone@127.0.0.1:10090 /] connect 127.0.0.1:10190Deploy the cluster application:
[standalone@127.0.0.1:10190 /]deploy \/home/student/AD248/labs/cluster-lb/cluster.war
Test the web sessions clustering.
Open a web browser and navigate to http://172.25.250.9:8180/cluster.
You should see the cluster application.
Notice that you have some information about the instance that replied to the request.
This information is the jboss.node.name system property value.
Refresh the page several times to increase the number of visits and then navigate to http://172.25.250.9:8280/cluster.
Notice that the total of visits increases by one on each request, even though you are running the application from a different server.
This means that the application is clustered.
Configure the load balancer.
Although the cluster is configured, each server must be accessed individually. Configure a new load balancer using first JBoss EAP instance, the one without a port offset.
Return to the management CLI tool, and connect to the load balancer instance:
[standalone@127.0.0.1:10190 /] connect 127.0.0.1:9990To configure a new load balancer, create a cluster-handler reverse proxy in the undertow subsystem:
[standalone@127.0.0.1:9990 /]/subsystem=undertow/configuration=\handler/reverse-proxy=cluster-handler:add{"outcome" => "success"}
Create a remote-server1 outbound socket binding.
This socket binding uses the AJP protocol running on the server named server1.
The AJP address and port are 172.25.250.9:8109.
[standalone@127.0.0.1:9990 /]/socket-binding-group=standard-sockets\/remote-destination-outbound-socket-binding=remote-server1\:add(host=172.25.250.9, port=8109){"outcome" => "success"}
The server1 standalone has a port offset of 100.
Thus, the AJP port is 8109.
Create a reference to the remote-server1 socket binding in the undertow subsystem.
Bind it with the AJP scheme and the context path:
[standalone@127.0.0.1:9990 /]/subsystem=undertow/configuration=handler\/reverse-proxy=cluster-handler/host=server1\:add(outbound-socket-binding=remote-server1, scheme=ajp, \instance-id=server1, path=/cluster){"outcome" => "success"}
To enable the sticky session, the instance-id attribute should have the same value specified by the jboss.node.name system property.
Create a remote-server2 outbound socket binding.
This socket binding uses the AJP protocol running on the server named server2.
The AJP address and port are 172.25.250.9:8209.
[standalone@127.0.0.1:9990 /]/socket-binding-group=standard-sockets\/remote-destination-outbound-socket-binding=remote-server2\:add(host=172.25.250.9, port=8209){"outcome" => "success"}
Create a reference to the remote-server2 socket binding in the undertow subsystem.
Bind it with the AJP scheme and the context path:
[standalone@127.0.0.1:9990 /]/subsystem=undertow/configuration=handler\/reverse-proxy=cluster-handler/host=server2\:add(outbound-socket-binding=remote-server2, scheme=ajp,\instance-id=server2, path=/cluster){"outcome" => "success"}
Create a new reverse proxy location named /cluster, and refer it to the cluster-handler handler:
[standalone@127.0.0.1:9990 /]/subsystem=undertow/server=default-server/\host=default-host\/location=\/cluster:add(handler=cluster-handler){"outcome" => "success"}
Test the load balancer.
Open a web browser and navigate to http://172.25.250.9:8080/cluster.
You should see the cluster application.
Refresh the browser several times and notice that each request is served by the same server.
Determine which JBoss EAP instance is handling your current request by looking at the label in the application.
Stop the host that is handling the requests by pressing Ctrl+C in the appropriate terminal window.
Return to the web browser and refresh the page. The load balancer sends your request to the other server without losing the current visits value.
Clean up.
Exit the management CLI:
[standalone@localhost:9990 /] exitStop the JBoss EAP instances by pressing Ctrl+C in the terminal window where they are running.