22.4. 将 JBoss EAP 配置为 Front-end Load Balancer


您可以配置 JBoss EAP 和 undertow 子系统,以充当前端负载平衡器,以代理对后端 JBoss EAP 服务器的请求。由于 Undertow 使用异步 IO,因此负责连接的 IO 线程是参与请求的唯一线程。相同的线程也用于与后端服务器发出的连接。

您可以使用以下协议:

您可以定义 静态负载均衡器 并在配置中指定后端主机,或使用 mod_cluster 前端 动态更新主机。

22.4.1. 使用 mod_cluster 将 Undertow 配置为负载平衡器

您可以使用内置的 mod_cluster 前端负载平衡器来负载平衡其他 JBoss EAP 实例。

此流程假设您在受管域中运行,并已配置了以下配置:

  • 将充当负载平衡器的 JBoss EAP 服务器。

    • 此服务器使用 default 配置文件,它绑定到 standard-sockets 套接字绑定组。
  • 两个 JBoss EAP 服务器,它们将充当后端服务器。

    • 这些服务器在集群中运行,并使用 ha 配置文件,它绑定到 ha-sockets 套接字绑定组。
  • distributable 应用,以负载平衡部署到后端服务器。
配置 mod_cluster Front-end Load Balancer

以下步骤对受管域中的服务器进行负载平衡,但可以调整它们以应用到一组单机服务器。务必更新管理 CLI 命令值以适合您的环境。

  1. 设置 mod_cluster 公告安全密钥。

    添加广播安全密钥可让负载均衡器和服务器在发现过程中进行身份验证。

    使用以下管理 CLI 命令,设置 mod_cluster 公告安全密钥。

    /profile=ha/subsystem=modcluster/mod-cluster-config=configuration:write-attribute(name=advertise-security-key, value=mypassword)
  2. 使用 mod_cluster 的多播地址和端口创建套接字绑定。

    您需要为 mod_cluster 创建套接字配置,用于发现并与要负载平衡的服务器进行通信。

    使用以下管理 CLI 命令,添加 modcluster 套接字绑定,并配置了适当的多播地址和端口。

    /socket-binding-group=standard-sockets/socket-binding=modcluster:add(multicast-port=23364, multicast-address=224.0.1.105)
  3. 包含 mod_cluster 负载平衡器。

    设置广播安全密钥和套接字绑定后,您需要将 mod_cluster 过滤器添加到 JBoss EAP 的负载均衡器实例的 Undertow。

    使用以下管理 CLI 命令,添加 mod_cluster 过滤器。

    /profile=default/subsystem=undertow/configuration=filter/mod-cluster=modcluster:add(management-socket-binding=http, advertise-socket-binding=modcluster, security-key=mypassword)

    使用以下管理 CLI 命令,将 mod_cluster 过滤器绑定到默认主机。

    /profile=default/subsystem=undertow/server=default-server/host=default-host/filter-ref=modcluster:add
重要

建议由 mod_cluster 使用的管理和公告套接字绑定仅公开给内部网络,而不是公共 IP 地址。

负载平衡器 JBoss EAP 服务器现在可以对两个后端 JBoss EAP 服务器进行负载平衡。

22.4.2. 将 Undertow 配置为静态负载平衡器

若要使用 Undertow 配置静态负载平衡器,您需要在 undertow 子系统中配置代理处理程序。要在 Undertow 中配置代理处理器,您需要在将充当静态负载平衡器的 JBoss EAP 实例上执行以下操作:

  1. 添加反向代理处理器
  2. 为每个远程主机定义出站套接字绑定
  3. 将每个远程主机添加到反向代理处理程序
  4. 添加反向代理位置

以下示例演示了如何将 JBoss EAP 实例配置为静态负载平衡器。JBoss EAP 实例位于 lb.example.com,它将在两个额外服务器之间进行负载平衡: 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=myroute, path=/test)
    
    /subsystem=undertow/configuration=handler/reverse-proxy=my-handler/host=host2:add(outbound-socket-binding=remote-host2, scheme=ajp, instance-id=myroute, path=/test)
  4. 添加反向代理位置:

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

在访问 lb.example.com:8080/app 时,您现在会看到从 server1.example.comserver2.example.com 代理的内容。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.