24.4.3. Undertow を静的ロードバランサーとして設定

Undertow の静的ロードバランサーを設定するには、undertow サブシステムでプロキシーハンドラーを設定する必要があります。Undertow でプロキシーハンドラーを設定するには、静的ロードバランサーとして動作する JBoss EAP インスタンスで以下を行う必要があります。

  1. リバースプロキシーハンドラーを追加します。
  2. 各リモートホストのアウトバウンドソケットバインディングを定義します。
  3. 各リモートホストをリバースプロキシーハンドラーへ追加します。
  4. リバースプロキシーの場所を追加します。

以下の例は、JBoss EAP インスタンスを静的ロードバランサーとして設定する方法を示しています。JBoss EAP インスタンスは lb.example.com にあり、2 つの追加サーバーである server1.example.comserver2.example.com との間で負荷分散を行います。ロードバランサーは /app に逆プロキシーを行い、AJP プロトコルを使用します。

  1. リバースプロキシーハンドラーを追加するには、以下を指定します。

    /subsystem=undertow/configuration=handler/reverse-proxy=my-handler:add
  2. 各リモートホストのアウトバウンドソケットバインディングを定義するには、以下を指定します。

    /socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=remote-host1/:add(host=server1.example.com, port=8009)
    
    /socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=remote-host2/:add(host=server2.example.com, port=8009)
  3. 各リモートホストをリバースプロキシーハンドラーに追加するには、以下を指定します。

    /subsystem=undertow/configuration=handler/reverse-proxy=my-handler/host=host1:add(outbound-socket-binding=remote-host1, scheme=ajp, instance-id=myroute1, path=/test)
    
    /subsystem=undertow/configuration=handler/reverse-proxy=my-handler/host=host2:add(outbound-socket-binding=remote-host2, scheme=ajp, instance-id=myroute2, path=/test)
  4. リバースプロキシーの場所を追加するには、以下を指定します。

    /subsystem=undertow/server=default-server/host=default-host/location=\/test:add(handler=my-handler)

lb.example.com:8080/app にアクセスすると、server1.example.com および server2.example.com からプロキシーされた内容が表示されるようになります。