22.8. Apache mod_proxy HTTP Connector
Apache mod_proxy 是一个 HTTP 连接器,支持通过 AJP、HTTP 和 HTTPS 协议的连接。mod_proxy 可以在负载均衡或非负载均衡配置中进行配置,它支持粘性会话的概念。
mod_proxy 模块要求 JBoss EAP 在 undertow
子系统中配置了 HTTP、HTTPS 或 AJP 侦听器,具体取决于您计划使用的协议。
mod_cluster 是比 mod_proxy 更高级的负载均衡器,是推荐的 HTTP 连接器。mod_cluster 提供 mod_proxy 的所有功能,以及其他功能。与 JBoss EAP mod_cluster HTTP 连接器不同,Apache mod_proxy HTTP 连接器不知道服务器或服务器组上部署的状态,也无法适应它相应地发送工作的位置。
如需更多信息,请参阅 Apache mod_proxy 文档。
22.8.1. 在 Apache HTTP 服务器中配置 mod_proxy
安装 JBoss Core Services Apache HTTP 服务器或使用 JBoss Web 服务器时,mod_proxy 模块已包含在内,默认加载。
自版本 3.1.0 起,Apache HTTP 服务器不再与 JBoss Web Server 一起分发。
请参阅以下适当的部分,以配置基本 负载平衡 或非 负载平衡 代理。这些步骤假定您已导航到 Apache HTTP 服务器的 httpd/
目录,这会根据您的平台而有所不同。如需更多信息,请参阅 JBoss Core Services Apache HTTP Server 安装指南中的 为您的平台安装说明。这些步骤还假定 JBoss EAP undertow
子系统中已配置了必要的 HTTP 侦听器。
红帽客户还可以使用红帽客户门户上的 Load Balancer 配置工具,快速为 mod_proxy 和其他连接器生成最佳配置模板。请注意,您必须登录才能访问此工具。
添加非负载均衡代理
在 conf/httpd.conf
文件中直接添加以下配置,在您可能具有的任何其他 & lt;VirtualHost
> 指令下。将值替换为适合您的设置的值。
<VirtualHost *:80> # Your domain name ServerName YOUR_DOMAIN_NAME ProxyPreserveHost On # The IP and port of JBoss # These represent the default values, if your httpd is on the same host # as your JBoss managed domain or server ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ # The location of the HTML files, and access control information DocumentRoot /var/www <Directory /var/www> Options -Indexes Order allow,deny Allow from all </Directory> </VirtualHost>
添加负载均衡代理
默认的 Apache HTTP 服务器配置禁用了 mod_proxy_balancer.so
模块,因为它与 mod_cluster 不兼容。要完成此任务,您需要加载此模块并禁用 mod_cluster 模块。
要将 mod_proxy 用作负载平衡器,并将工作发送到多个 JBoss EAP 实例,请将以下配置添加到 conf/httpd.conf
文件中。示例 IP 地址是虚构的。将它们替换为适合您环境的相应值。
<Proxy balancer://mycluster> Order deny,allow Allow from all # Add each JBoss Enterprise Application Server by IP address and port. # If the route values are unique like this, one node will not fail over to the other. BalancerMember http://192.168.1.1:8080 route=node1 BalancerMember http://192.168.1.2:8180 route=node2 </Proxy> <VirtualHost *:80> # Your domain name ServerName YOUR_DOMAIN_NAME ProxyPreserveHost On ProxyPass / balancer://mycluster/ # The location of the HTML files, and access control information DocumentRoot /var/www <Directory /var/www> Options -Indexes Order allow,deny Allow from all </Directory> </VirtualHost>
上面的示例都使用 HTTP 协议进行通信。如果您加载适当的 mod_proxy 模块,您可以使用 AJP 或 HTTPS 协议。详情请查看 Apache mod_proxy 文档。
启用粘性会话
粘性会话 意味着,如果客户端请求最初进入特定的 JBoss EAP worker,则将来的所有请求都将发送到同一工作程序,除非它不可用。这几乎总是推荐的行为。
要为 mod_proxy 启用粘性会话,请将 stickysession
参数添加到 ProxyPass
语句中。
ProxyPass / balancer://mycluster stickysession=JSESSIONID
您可以为 ProxyPass
语句指定额外的参数,如 lbmethod
和 nofailover
。有关可用参数的更多信息,请参阅 Apache mod_proxy 文档。
22.8.2. 使用 mod_proxy 将 JBoss EAP 配置为 Communicate
JBoss EAP undertow
子系统需要指定一个侦听器来接受来自的请求,并将回复发回到外部 Web 服务器。根据您要使用的协议,您可能需要配置监听程序。
JBoss EAP 默认配置中配置 HTTP 侦听器。如果您使用默认高可用性配置之一(ha 或 full-ha),也会预先配置一个 AJP 侦听器。
具体步骤请参阅 接受来自外部 Web 服务器的请求。