0

我正在使用 JBoss EAP 6.2 和 Apache 2.2.25-no-ssl 来进行应用程序的负载平衡和集群部署。

我想关闭会话复制并打开粘性会话

但是在做了各种配置之后,我注意到我的负载均衡器没有将基于 session-id 的用户请求粘贴到一个特定的节点,而是将请求转发到另一个节点。

以下是我的集群配置。

集群节点数 = 2

Apache 负载均衡器 = Apache 2.2.25-no-ssl

应用服务器 = JBoss EAP 6.2.0

Apache 负载均衡器配置

worker.properties

# Define list of workers that will be used
# for mapping requests
worker.list=loadbalancer,status

# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=8009
worker.node1.host=172.20.150.33
worker.node1.type=ajp13
worker.node1.ping_mode=A
worker.node1.lbfactor=1 

# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8209
worker.node2.host=172.20.150.33
worker.node2.type=ajp13
worker.node2.ping_mode=A
worker.node2.lbfactor=1

# Load-balancing behavior
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=1

# Status worker for managing load balancer
worker.status.type=status

uriworkermap.properties

# Simple worker configuration file

# Mount the Servlet context to the ajp13 worker
/*=loadbalancer

mod-jk.conf

# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
JkWorkersFile conf/workers.properties

# Where to put jk logs
JkLogFile logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel debug 

# Select the log format
JkLogStampFormat  "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicates to send SSK KEY SIZE
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"

# Mount your applications
# The default setting only sends Java application data to mod_jk.
# Use the commented-out line to send all URLs through mod_jk.
# JkMount /* loadbalancer
JkMount /* loadbalancer

# Add shared memory.
# This directive is present with 1.2.10 and
# later versions of mod_jk, and is needed for
# for load balancing to work properly
JkShmFile logs/jk.shm 

# You can use external file for mount points.
# It will be checked for updates each 60 seconds.
# The format of the file is: /url=worker
# /examples/*=loadbalancer
JkMountFile conf/uriworkermap.properties

# Add jkstatus for managing runtime data
<Location /jkstatus/>
JkMount status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>

mod-jk.conf 加载在 httpd.conf 文件中,Apache 在端口 80 上运行。

在 JBoss EAP 中,在同一台机器上创建独立文件夹的两个名为node1node2的副本,如下图所示

在此处输入图像描述

启动服务器的命令:

节点1

standalone.bat -c standalone-ha.xml -b 172.20.150.33 -u 230.0.10.0 -Djboss.server.base.dir=../node1 -Djboss.node.name=node1 -Dlogging.configuration=file:/${JBOSS_HOME}/node1/configuration/logging.properties

节点2

standalone.bat -c standalone-ha.xml -b 172.20.150.33 -u 230.0.10.0 -Djboss.server.base.dir=../node2 -Djboss.node.name=node2 -Dlogging.configuration=file:/${JBOSS_HOME}/node2/configuration/logging.properties -Djboss.socket.binding.port-offset=200

我尝试使用 Session Replication On(通过添加 web.xml),但仍然存在同样的问题。

以下是我的 JSESSIONID 观察结果。

应第一次要求

JSESSIONID = SY1d0wVTmX2b-czp50whdmCW.61423f3f-b623-3da4-bd2f-69ba448af636 where 61423f3f-b623-3da4-bd2f-69ba448af636 is JVM-ROUTE for node2.

在第二次请求

JSESSIONID = QMTCTAzt2u-ANTidqZdBIzxO.f742b8d4-46f7-3914-86bb-1044d0a1bfce where f742b8d4-46f7-3914-86bb-1044d0a1bfce is a JVM-ROUTE for node1.

似乎即使 jvm-route 附加到主会话 id ,负载均衡器(apache mod-jk)仍然向其他节点发送请求,而不是坚持建立会话的节点。

请帮忙。

4

1 回答 1

0

对于这种场景,您需要实现这种架构。我们使用相同的架构来托管Wildfly

注意:请不要忘记在负载均衡器(LB)和 Apache mod_jk 上启用会话粘性/连接持久性。

在这个架构中:

为了

   WEB1 -> App1 is Active APP NODE
   WEB2 -> APP2 is Active APP NODE

因此,如果请求/连接出现在 LB 上,它将被重定向到 WEB1。由于在 LB 上启用了会话粘性/连接持久性,来自同一客户端的所有请求都仅重定向到 WEB1。

这是我的Apache 负载均衡器配置

worker.properties 对于 node1

# Define list of workers that will be used
# for mapping requests
# The configuration directives are valid
# for the mod_jk version 1.2.18 and later
#
worker.list=loadbalancer,status

# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=8009
worker.node1.host=10.62.147.58
worker.node1.type=ajp13
worker.node1.lbfactor=1
#worker.node1.socket_timeout=600
#worker.node1.ping_timeout=1000
worker.node1.ping_mode=A
#worker.node1.connection_pool_timeout=600
worker.node1.redirect=node2


# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8009
worker.node2.host=10.62.147.59
worker.node2.type=ajp13
worker.node2.lbfactor=1
#worker.node2.socket_timeout=600
#worker.node2.ping_timeout=1000
worker.node2.ping_mode=A
#worker.node2.connection_pool_timeout=600
worker.node2.activation=disabled

# Load-balancing behavior
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=1
worker.loadbalancer.retry_interval=30
worker.loadbalancer.recover_time=20
#worker.loadbalancer.sticky_session_force=1

# Status worker for managing load balancer
worker.status.type=status

节点2的workers.properties

# Define list of workers that will be used
# for mapping requests
# The configuration directives are valid
# for the mod_jk version 1.2.18 and later
#
worker.list=loadbalancer,status

# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=8009
worker.node1.host=10.62.147.58
worker.node1.type=ajp13
worker.node1.lbfactor=1
#worker.node1.socket_timeout=600
#worker.node1.ping_timeout=1000
worker.node1.ping_mode=A
#worker.node1.connection_pool_timeout=600
worker.node1.activation=disabled


# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8009
worker.node2.host=10.62.147.59
worker.node2.type=ajp13
worker.node2.lbfactor=1
#worker.node2.socket_timeout=600
#worker.node2.ping_timeout=1000
worker.node2.ping_mode=A
#worker.node2.connection_pool_timeout=600
worker.node2.redirect=node1

# Load-balancing behavior
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=1
worker.loadbalancer.retry_interval=30
worker.loadbalancer.recover_time=20
#worker.loadbalancer.sticky_session_force=1

# Status worker for managing load balancer
worker.status.type=status

mod-jk.conf

# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
JkWorkersFile conf/workers.properties

# Where to put jk logs
JkLogFile logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicates to send SSK KEY SIZE
# Notes:
# 1) Changed from +ForwardURICompat.
# 2) For mod_rewrite compatibility, use +ForwardURIProxy (default since 1.2.24)
# See http://tomcat.apache.org/security-jk.html
JkOptions +ForwardKeySize +ForwardURICompatUnparsed -ForwardDirectories +ForwardURIProxy +ForwardURICompat


# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"

# Mount your applications
#JkMount /__application__/* loadbalancer
# Let Apache serve the images
#JkUnMount /__application__/images/* loadbalancer

# You can use external file for mount points.
# It will be checked for updates each 60 seconds.
# The format of the file is: /url=worker
# /examples/*=loadbalancer
JkMountFile conf/uriworkermap.properties

# Add shared memory.
# This directive is present with 1.2.10 and
# later versions of mod_jk, and is needed for
# for load balancing to work properly
# Note: Replaced JkShmFile logs/jk.shm due to SELinux issues. Refer to
# https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=225452
JkShmFile run/jk.shm

JkMount /* loadbalancer
# Add jkstatus for managing runtime data
<Location /jkstatus>
JkMount status
Order deny,allow
Deny from none
Allow from All
</Location>
于 2015-03-25T12:11:28.740 回答