Bookmark this page

Guided Exercise: Configuring Load Balancing

Load balance HTTP requests among a predefined set of servers by using undertow.

Resources
Instance directories:

/home/student/AD248/labs/cluster-lb/lb-instance

/home/student/AD248/labs/cluster-lb/server1

/home/student/AD248/labs/cluster-lb/server2

Application URLs:

http://172.25.250.9:8080/cluster

http://172.25.250.9:8180/cluster

http://172.25.250.9:8280/cluster

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

  1. Start the standalone JBoss EAP servers.

    1. 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
    2. 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

      Note

      The node name is required to use the sticky session feature.

    3. 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
  2. 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.

    1. 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
    2. Deploy the cluster application:

      [standalone@127.0.0.1:10090 /] deploy \
      /home/student/AD248/labs/cluster-lb/cluster.war
    3. Connect to the second instance of the cluster:

      [standalone@127.0.0.1:10090 /] connect 127.0.0.1:10190

      Deploy the cluster application:

      [standalone@127.0.0.1:10190 /] deploy \
      /home/student/AD248/labs/cluster-lb/cluster.war
  3. 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.

  4. 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.

    1. Return to the management CLI tool, and connect to the load balancer instance:

      [standalone@127.0.0.1:10190 /] connect 127.0.0.1:9990
    2. To 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"}
    3. 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"}

      Note

      The server1 standalone has a port offset of 100. Thus, the AJP port is 8109.

    4. 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"}

      Note

      To enable the sticky session, the instance-id attribute should have the same value specified by the jboss.node.name system property.

    5. 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"}
    6. 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"}
    7. 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"}
  5. Test the load balancer.

    1. 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 Response from label in the application.

    2. Stop the host that is handling the requests by pressing Ctrl+C in the appropriate terminal window.

    3. 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.

  6. Clean up.

    1. Exit the management CLI:

      [standalone@localhost:9990 /] exit
    2. Stop the JBoss EAP instances by pressing Ctrl+C in the terminal window where they are running.

Finish

On the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish cluster-lb

Revision: ad248-7.4-18a9db2