我需要一种方法来跟踪和限制networking会话到一个Web应用程序。 “会话”被粗略地定义为浏览所述networking应用的页面的单个用户。 我认为可以翻译成:
<clientIP,vHost>或者<clientIP,serverIP,serverPort>或<cookie,vHost> ,取决于层和可用数据 在达到指定的会话限制之后,下一个用户应该被定向到一个自定义错误页面。 我还需要一种方法来跟踪当前的会话数量,以便进行监控,并能够将监控服务器列入白名单(这将定期向Web应用程序发出查询)并免除限制。
我能与之合作的是:
我宁愿不涉及一个额外的代理服务器,虽然会考虑如果没有其他选项。
所有这一切背后的基本原理是,上述的networking应用程序很容易被超载,并开始拒绝不请求的请求,使工作中的用户(通常)在进程中丢失了input数据。 通过在超负荷条件不太可能的情况下指定限制,我们希望创build一个明确的故障条件,如果负载可能高峰,用户将被告知以后返回。
编辑 :Web应用程序是第一层(呈现层,在Apache vHost中作为CGI代码实现)的三层实现,它非常简单,显然仅限于基本的error handling和请求应用程序服务器之间的负载平衡。 它不会在它运行的Web服务器上施加任何重要的负载 – 这就是为什么我们只是在AppDirector场中以故障转移模式(无负载平衡)运行它,这应该有点简化。
除此之外的一切对我们来说基本上是一个黑盒子 – 在数据层我们有一个MSSQL数据库,但几乎不可能从供应商那里得到关于表结构的任何有意义的信息。 应用程序服务器是封闭的,供应商使用了相当全面的实现框架,但似乎无法回答更简单的与操作相关的问题。
你最终要解决的问题是应用程序的能力 – 这就是你应该解决问题的地方。 您提到的任何组件都与 HTTP应用程序的会话pipe理无关 。
有一些技巧可以在iptables中使用最近的模块,或者以与devise目的相反的方式使用fail2ban – 但是这些都需要对工具和问题域有非常详细的理解。 您可以在这些组件的级别实现访问控制,但由会话数量的应用程序发布状态信息驱动 。
我还需要一种方法来跟踪当前的会话数目以进行监控
现在假设应用程序是一个没有修改/检测范围的黑匣子(这是非常不可能的),你可以通过包含会话cookie从你的apache日志中获取这些信息 – 过滤或拖拽日志来维护活动cookie的列表 – 并且当它们与注销URL一致或者没有被看到TTL时,从列表中移除条目。
这不是你要求的,但是我已经用F5负载均衡器完成了以下工作:
由于网站有时在重负荷(赛马),它帮助。
这个问题可以通过使用RadWare AppDirector来解决,并且(为了完整性)也可以通过使用Apache mod_security来完成,就像你在下面评论中的出色发现一样。
对于AppDirector解决scheme,我相信可以创build两个映射到相同后端服务器的服务器场。 这些农场可以有不同的标准和操作条件。 一个农场将是“默认”,另一个农场将回答您定义为“会话”的URI:s。 后者会在负载均衡器中接受的会话数量受到限制。
我从现在开始用“login”来代替你的“会话”,原因有两个:
如果“已login”服务器场已达到所选连接限制,也可以显示一个抱歉页面。
在了解之前,我必须清楚地说明我没有AppDirector产品的操作经验,但是每天要pipe理一个竞争性稍差的负载均衡器。 我使用的产品可以做到这一点的情况。 我已经通过“AppDirector用户指南”find了相关信息,以及哪些在线文档可用,这表明AppDirector也是如此。 然而,虽然概念是相似的,但术语是不同的。 我只是在措辞方面做一个罗马时代的行为,希望能够把它弄得相当正确,而不是太明显的无知。
最大的障碍是获得一本手册,除非有一个活跃的客户,否则这个手册是不可用的。 通过一些Googlesearch,可以find一个旧版本,我希望不要过时,我还发现了一些知识库文章和链接: Radware AppDirector – Configuration:Basic Application 。
这是一个解决scheme草案,主要通过用户指南进行解释:
客户端到负载均衡器的input是通过用于连接“默认”会话和“login会话”的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政策联系在一起,用来select一个合适的农场。 L7策略过程在用户指南第104页中有描述:
"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."
定义L7行为的方法在第106页有描述,您可以select合适的方法来select路由到您的“login”农场而不是“缺省”农场:
"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."
正如基本应用程序链接中所见,可以创build一个L7策略来评估路由到不同服务器场的URI模式。 构成的URI模式'^ / login?= true'和'^ / loggedin'可以被路由到您的“login”场中。 组成模式“^ /注销”(和所有其他URI:s)可以类似地路由到“默认”农场。
用户指南第121页定义了一个场: “一个AppDirector场是一组提供相同服务的networking服务器[…]一个提供多种服务的服务器可以在多个场中使用。
通过将后端服务器的定义分为两层,进一步区分服务器:表示服务器的IP地址的“物理服务器”对象层和表示在一个或多个物理服务器上运行的服务的“服务器”对象层。
除了每个物理服务器对象之外,还可以根据为服务器场定义的每个服务器场对象(以及通过其他方式)执行“AppDirector用户指南”中的场限制。 这在第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"
在基本应用程序页面的服务器定义窗口的屏幕截图中,服务器连接限制框位于带宽限制框旁边。
所以取决于configuration,但为了这个答案的目的,通过客户表定义的“连接”和由你定义的“会话”基本上是同样的事情。 并且可以对场中的每个服务器对象施加限制。
由于AppDirector区分物理服务器和场服务器,所以可以定义映射到您的Apache物理服务器对象的两个场服务器,一个连接限制较低。
但是,Apache也需要应答来自两个服务器场对象的调用,例如通过在两个单独的端口或IP地址上调用 – 每个(场/服务器)组合使用一个端口或IP地址。 问题就变成了,你能定义两个应用服务器入口点吗? 即你是否可以configuration你的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."
因此,您需要为不受限制的“默认”服务器场服务器定义非常高的连接限制(对于可能通过用户群可能达到的最大数量),并将“已login”服务器场的连接限制设置为低,因为你必须。 物理服务器定义需要将两者的总和作为连接限制,作为激活所需会话限制的先决条件。
你的问题中也有这个要求:
After the specified session limit has been reached, the next user should be directed to a custom error page.
在用户指南中,这被称为“无HTTP服务页面”,第134页:
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。 通常情况下可能很难find正确的OID,但是你也可以将它嗅到你select的工具。
whitelist the monitoring server (which is issuing queries to the webapp periodically) and exempt it from the limit.
这可能需要一些创造性思维。 假设AppDirector不包含这个开箱即用的模板,怎么样:
如果AppDirector不能帮助你,这是另一种需要编码的方法。 我会解决这个问题如下:
对会话数进行graphics化就像绘制iptables链的长度一样简单。 监控服务器可以简单地列入白名单。