通过使用RadWare AppDirector可以解决此问题,并且(出于完整性考虑)也可以通过使用Apache mod_security(根据您在以下注释中的出色发现)来解决。
对于AppDirector解决方案,我相信可以创建两个映射到同一后端服务器的服务器场。这些服务器场可以应用不同的条件和操作条件。一个服务器场将是“默认”服务器场,另一个服务器场将响应您定义为“会话”的URI :。后者将限制它在负载均衡器中接受的会话数量。
从现在开始,我出于以下两个原因将您的“会话”一词替换为“已登录”:
- 它避免了歧义,因为它明确定义了用户已通过身份验证的期望状态。
- 《 AppDirector用户指南》和GUI重新定义了“连接”一词,其所有实际含义均与“会话”相同,请参见下文。这增加了我们试图避免的混乱。
如果“已登录”服务器场已达到所选的连接限制,也可能会显示一个抱歉的页面。
在进行操作之前,我必须明确声明我没有AppDirector产品的操作经验,但是每天都要管理一个竞争性稍差的负载均衡器。我使用的产品可以立即解决此问题。我已经通过《 AppDirector用户指南》找到了信息,并且可以找到哪些在线文档,这表明对于AppDirector也是一样。但是,尽管概念相似,但术语却不同。我只是在措辞方面做一个罗马式的举动,希望能做到正确,而又不会太笨拙。
最大的障碍是获得一本手册,除非一个活跃的客户,否则该手册将不可用。通过一些谷歌搜索,有可能找到一个我希望不会过时的旧版本,我还找到了一些知识库文章,以及以下链接:Radware AppDirector –配置:基本应用程序。
这是一个解决方案草案,主要通过《用户指南》进行解释:
客户端进入负载平衡器是通过VIP完成的,该VIP用于连接“默认”会话和“已登录的会话”。这可以通过《用户指南》第99页中的L4策略来实现:
"When AppDirector receives the first packet of a session destined to a
Virtual IP address, it searches for a Layer 4 Policy that matches the
Layer 4 Protocol, Destination port, Source IP, etc. Then, based on this
information, AppDirector selects the farm allocated to this service and
the best server for the task from that farm, and forwards the packet to
that server.
L4策略可以与L7策略绑定,后者用于选择合适的服务器场。因此,在《用户指南》第104页中描述了L7策略过程:
"The Layer 7 content aware decision making mechanism allows you to have
a single point of entry to the site, and provides differentiated service
for different user groups.
A Layer 7 decision is made using a mechanism called Delayed Binding.
When Delayed Binding is used, AppDirector first performs a TCP handshake
with the client to receive the HTTP request. AppDirector parses the HTTP
request’s data, usually HTTP headers, and performs the load balancing
decision. Only after that, does AppDirector select a farm and a server.
Lastly, AppDirector initiates a TCP handshake with the server and
forwards the traffic to it
[...]
When Layer 7 Policies are used, farm selection is based on matching the
request data with a list of Layer 7 Policies defining the Layer 7
parameters differentiating the service. The process of server selection
within the farm can also be content-based, using a third Layer 7
parameter."
第106页描述了可用于定义L7行为的方法,您可以从中选择一种合适的方法来选择路由到“已登录”服务器场而不是“默认”服务器场:
"Methods are the basic building blocks for Layer 7 service selection.
They define content by which traffic is differentiated. You can use
the same Method to select one or more services. The following Method
Types are available:
- URL: Looks for a specified host name and/or path in the HTTP request.
- File Type: Looks for a specified File Type in the HTTP request.
- Header Field: Looks for a specified Header Field in the HTTP request.
- Cookie: Looks for a specified Cookie in the HTTP request.
- Regular Expression: Looks for a regular expression anywhere in the
HTTP request. AppDirector supports Posix 1002.3 regular expressions;
the string can be up to 80 characters.
- Text: Looks for a text string anywhere in the HTTP request."
从“ 基本应用程序”链接中可以看到,例如可以创建一个L7策略,以评估URI模式以路由到不同服务器场。可以将组成的URI模式'^ / login?= true'和'^ / loggedin'路由到您的“已登录”服务器场。组成的模式'^ / logout'(和所有其他URI:s)可以类似地路由到“默认”服务器场。
服务器场由《用户指南》第121页定义,因此:“ AppDirector服务器场是一组提供相同服务的网络服务器。可以在多个服务器场中使用提供多种服务的服务器。
通过将后端服务器的定义分为两层,进一步区分了服务器:代表服务器IP地址的“物理服务器”对象层和代表一个或多个物理服务器上运行的服务的“农场服务器”对象层。 。
根据“ AppDirector用户指南”,除了对每个物理服务器对象之外,还可以针对该场定义的每个Farm Server对象(以及通过其他方式)对场进行会话限制。第137页的其他地方对此进行了描述:
"The Connection Limit is the maximum number of users that can be directed
to a server for a service provided by the farm. The number of users allowed
depends on the Sessions mode selected because it determines the number of
active entries in the Client Table for sessions destined to the specific server.
When the Entry Per Session or Server Per Session modes are selected, the number
of active entries destined to the same server is higher than in the Regular
mode (see Regular, page 153).
When the Regular mode is selected, all requests from a single client IP destined
to the same server are reflected by a single entry in the Client Table (see
Client Table Views, page 164).
The default value for the Connection Limit parameter is 0. When it is configured
to 0, it is disabled for this server and there is no user number limit."
第153页中定义了客户端表及其“常规模式”:
"The Layer 3 Client Table is always used when Entry Per Session is used.
AppDirector uses the Layer 3 Client Table to ensure Layer 3 persistency.
This table contains information about the server selected for each client
(Source IP address) in each farm, and it allows AppDirector to select a
server for a new session.
[...]
In the Regular mode, AppDirector maintains Layer 3 persistency. In this mode,
each entry is identified by the following parameters:
• Layer 4 Policy VIP Address
• Client IP Address
• Destination TCP/UDP Port Used from the Client to the Server"
在“ 基本应用程序”页面上的服务器定义窗口的屏幕快照中,在带宽限制框旁边可以看到服务器连接限制框。
因此,这取决于配置,但出于此答案的目的,通过客户端表定义的“连接”和由您定义的“会话”本质上是同一回事。可以对服务器场中的每个服务器对象强加这种限制。
由于AppDirector区分物理服务器和场服务器,因此可以定义两个映射到您的Apache物理服务器对象的场服务器,其中一个具有较低的连接限制。
但是,Apache还需要应答来自两个场服务器对象的呼叫,例如通过在两个单独的端口或ip地址上进行调用-每个(场/场服务器)组合都使用一个。问题就变成了,您是否能够定义两个应用程序服务器入口点?也就是说,您是否可以使Apache前端应用程序(/ vhost?)能够在两个端口或IP地址(每个服务器场一个)上进行应答?这是经过一些猜测的工作,因为我不想花太多时间在手册上,但是我相信当您实际查看AppDirector GUI和Apache时,您可以相当优雅地解决此问题。
设置连接限制有些奇怪。从物理服务器的连接限制第140页:
"Connection Limit
Maximum number of Client Table entries that can run simultaneously on
the physical server. This depends on the farm’s Sessions mode (see
Sessions Modes, page 150). When the limit is reached, new requests are
no longer directed to this server. All open sessions are continued.
When the Connection Limit parameter is configured to 0 (default), this
mechanism is disabled for this physical server and there is no user
number limit.
Note: When configuring the physical server, ensure that the Connection
Limit in the farm servers with the same Server Name is lower than or
equal to the Connection Limit in the physical server. Total number of
active sessions that run simultaneously on the farm servers must not
be higher than the Connection Limit value defined on the physical server."
因此,您需要为不受限制的“默认”服务器场服务器定义一个很高的连接限制(与通过用户库可能达到的最大数目有很大的余量),并将“已登录”服务器场服务器的连接限制设置为低到你所需要的。物理服务器定义将需要将两者之和作为其连接限制,作为激活所需会话限制的前提。
您的问题中也有此要求:
After the specified session limit has been reached, the next user should be
directed to a custom error page.
在《用户指南》第134页中,这被称为“无HTTP服务页”:
When all servers belonging to a farm cannot be used for a specific
session, AppDirector can reply to a Web request (destined to port 80)
with a simple Web page, indicating that the service is currently not
available. Servers that cannot be used for a session include servers
in Not In Service or in No New Sessions mode. No HTTP Service Page is
configured for each farm. Each Web page is limited to 1K of HTML code.
对于监视部分,我还没有进行深入的研究,但是我认为这是:
track the current number of sessions for monitoring purposes
AppDirector似乎具有MIB。像通常那样找到正确的OID可能很麻烦,但是您可以将其隐藏到所选的工具中。
whitelist the monitoring server (which is issuing queries to the webapp
periodically) and exempt it from the limit.
这可能需要一些创造性思维。假设AppDirector不包含此功能的模板,该如何操作:
- 会话限制不会影响“已登录”服务器场之外的URI。因此,监视一下,无论如何它都是相同的后端服务器。
- 请改用AppDirector运行状况检查,这些检查可能不会计入您施加的会话限制。找到一种通过以下方式将警报传递到监视服务器的方法:-)
- 设置第三个服务器场,通过它通过运行状况检查。杂乱无章,但行得通。