24.4. 将 JBoss EAP 配置为前端负载平衡器
您可以配置 JBoss EAP 和 undertow
子系统,充当前端负载平衡器,以代理到后端 JBoss EAP 服务器的请求。由于 Undertow 使用异步 IO,负责连接的 IO 线程是唯一与请求相关的线程。同样的线程也用于连接后端服务器。
您可以使用以下协议:
-
通过纯文本(
http)的
HTTP,支持 HTTP/1 和 HTTP/2(h2c
) -
通过安全连接(
https
)的 HTTP,支持 HTTP/1 和 HTTP/2(h2)
-
AJP(
ajp
)
您可以定义静态负载平衡器并在配置中指定后端主机,或者使用 mod_cluster 前端动态更新主机。
有关将 Undertow 配置为使用 HTTP/2 的说明,请参阅配置 HTTP/2。
24.4.1. 使用 mod_cluster 将 Undertow 配置为负载平衡器
您可以使用内置的 mod_cluster 前端负载平衡器来负载平衡其他 JBoss EAP 实例。
此流程假定您在受管域中运行,并且已配置了以下配置:
将充当负载平衡器的 JBoss EAP 服务器。
此服务器使用
load-balancer
配置文件,它绑定到load-balancer-sockets
套接字绑定组。注意load-balancer
配置集已预先配置了套接字绑定 mod-cluster Undertow 过滤器,并在默认主机中引用过滤器以将此服务器用作前端负载平衡器。
两台 JBoss EAP 服务器,用作后端服务器。
-
这些服务器在集群中运行,并使用
ha
配置文件,它绑定到ha-sockets
套接字绑定组。
-
这些服务器在集群中运行,并使用
- 将负载平衡部署到后端服务器的 distributable 应用。
配置 mod_cluster Front-end Load Balancer
下列步骤对受管域中的服务器进行负载平衡,但可以调整它们以应用到一组单机服务器。务必更新管理 CLI 命令值以适合您的环境。
设置 mod_cluster 公告安全密钥。
添加广播安全密钥可让负载平衡器和服务器在发现期间进行身份验证。
使用以下管理 CLI 命令,设置 mod_cluster 公告安全密钥:
/profile=ha/subsystem=modcluster/proxy=default:write-attribute(name=advertise-security-key, value=mypassword)
更新 mod_cluster 负载平衡器的安全密钥。
使用以下管理 CLI 命令,为 mod_cluster 过滤器设置安全密钥:
/profile=load-balancer/subsystem=undertow/configuration=filter/mod-cluster=load-balancer:write-attribute(name=security-key,value=mypassword)
建议由 mod_cluster 使用的管理和公告套接字绑定仅公开给内部网络,而非公共 IP 地址。
负载平衡器 JBoss EAP 服务器现在可以对两个后端 JBoss EAP 服务器进行负载平衡。
多个 mod_cluster 配置
mod_cluster
子系统支持多个命名代理配置,允许使用反向代理在非默认 下注册服务器
。此外,这允许单个应用服务器节点注册到不同的代理服务器组。
以下示例将 ajp-listener
、server 和主机添加到 undertow
服务器。它还添加新的 mod_cluster
配置,以使用广播机制注册主机。
/socket-binding-group=standard-sockets/socket-binding=ajp-other:add(port=8010) /subsystem=undertow/server=other-server:add /subsystem=undertow/server=other-server/ajp-listener=ajp-other:add(socket-binding=ajp-other) /subsystem=undertow/server=other-server/host=other-host:add(default-web-module=root-other.war) /subsystem=undertow/server=other-server/host=other-host /location=other:add(handler=welcome-content) /subsystem=undertow/server=other-server/host=other-host:write-attribute(name=alias,value=[localhost])) /socket-binding-group=standard-sockets/socket-binding=modcluster-other:add(multicast-address=224.0.1.106,multicast-port=23364) /subsystem=modcluster/proxy=other:add(advertise-socket=modcluster-other,balancer=other-balancer,connector=ajp-other) reload