如果您希望通过 modcluster/static 负载平衡配置将 wildfly 用作负载平衡器,则无需在集群/域中包含服务器(它将充当负载平衡器)。您可以单独调用负载平衡器服务器。 Wildfly10 发行版已经有一个示例文件——standalone-load-balancer.xml(在里面——\docs\examples\configs),可以直接使用。
此文件具有使用 wildfly 10.1 作为负载平衡器所需的最低配置。
一旦服务器使用该文件启动,它将自动发现参与集群的工作节点(前提是多播地址和端口在网络中工作且可访问)。
另外请注意,所有工作节点都应该有不同的节点名,否则如果某些节点位于同一台机器上,并且如果它们没有使用不同的节点名调用,那么它们可能会被负载平衡器服务器拒绝。
以下是调用具有特定节点名称的wildfly服务器的命令---
standalone.bat -Djboss.node.name=<specify the node name here>
基本设置如下--
[1] 使用配置调用两个单独的节点(wildfly 实例)-standalone-ha.xml/standalone-full-ha.xml 和一些 web 应用程序(例如 cluster-demo.war)。请注意,Web 应用的部署描述符中必须有标签,否则调用两个工作节点后集群将无法建立。
[2] 第一步成功后,用户可以看到消息 - 在工作节点的控制台日志中收到新的集群视图。
[3] 负载均衡器配置 --
[3.1] 动态负载均衡器(使用 modcluser 配置)--------
使用配置调用 wildfly 的第三个实例 -standalone-load-balancer.xml
如果负载均衡器检测到所有工作节点,那么用户将在负载均衡器服务器的控制台日志中看到日志消息 - 注册节点 - 节点名称。
[3.2]静态负载均衡器配置-----
cli---
/subsystem=undertow/configuration=handler/reverse-proxy=my-handler1:add()
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=remote-host111/:add(host=localhost, port=9080)
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=remote-host222/:add(host=localhost, port=10080)
/subsystem=undertow/configuration=handler/reverse-proxy=my-handler1/host=host11:add(outbound-socket-binding=remote-host111, scheme=http, instance-id=cluster-demoroute, path= /集群演示)
/subsystem=undertow/configuration=handler/reverse-proxy=my-handler1/host=host22:add(outbound-socket-binding=remote-host222, scheme=http, instance-id=cluster-demoroute, path=/cluster-演示)
/subsystem=undertow/server=default-server/host=default-host/location=/cluster-demo:add(handler=my-handler1)
配置替换----------
[A] 在subsystem-undertow/handlers 标签内添加下面的反向代理标签--
<reverse-proxy name="my-handler1">
<host name="host11" outbound-socket-binding="remote-host111" path="/cluster-demo" instance-id="cluster-demoroute"/>
<host name="host22" outbound-socket-binding="remote-host222" path="/cluster-demo" instance-id="cluster-demoroute"/>
</reverse-proxy>
[B] 在子系统内添加位置标签 - undertow/server=default-server/default-host
<location name="/cluster-demo" handler="my-handler1"/>
[C] 在socket-binding-group标签下面添加
<outbound-socket-binding name="remote-host111">
<remote-destination host="localhost" port="9080"/>
</outbound-socket-binding>
<outbound-socket-binding name="remote-host222">
<remote-destination host="localhost" port="10080"/>
</outbound-socket-binding>