跨多个 Web 服务器进行日志记录
我想知道人们如何处理跨多个网络服务器的日志记录。例如,假设有 2 个网络服务器,用户会话期间的一些事件由其中一个提供服务,另一些则由另一个提供服务。您将如何将会话中的事件连贯地记录在一个地方(例如不会产生单点故障)?假设我们使用:ASP.Net MVC、log4net。
或者我是否以错误的方式看待这个问题 - 我应该单独记录然后稍后合并?
,
更新
谢谢
请同时假设负载均衡器不会保证会话固定在一台服务器上。
I would like to know how people dealing with logging across multiple web servers. E.g. Assume there are 2 webservers and some events during the users session are serviced from one, some from the other. How would you go about logging events from the session coherently in one place (without e.g.creating single points of failure)? Assuming we are using: ASP.Net MVC, log4net.
Or am I looking at this the wrong way - should I log seperately and then merge later?
Thanks,
S
UPDATE
Please also assume that the load balancers will not guarantee that a session is stuck to one server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您肯定希望您的 Web 服务器在本地而不是通过网络进行日志记录。您不希望潜在的网络中断阻止日志记录操作,也不希望网络操作产生日志记录的开销。您应该设置日志轮换并且所有网络服务器时钟都已同步。当日志轮转将日志文件滚动到新文件时,将每个 Web 服务器中的完整日志文件发送到可以合并它们的公共目标。我不是 .net 人员,但您应该能够找到软件来合并 IIS 日志(或您正在使用的任何 Web 服务器)。然后分析合并的日志。除非您需要实时日志分析,否则此策略是最佳的。你?可能不会。它对故障的恢复能力相当强(假设您有冗余磁盘),因为如果服务器出现故障,您只需重新启动它并重新处理任何中断的日志传送、日志合并或日志分析操作。
You definitely want your web servers to log locally rather than over a network. You don't want potential network outages to prevent logging operations and you don't want the overhead of a network operation for logging. You should have log rotation set up and all your web servers clock's synced. When log rotation rolls your log files over to a new file, have the completed log files from each web server shipped to a common destination where they can be merged. I'm not a .net guy but you should be able to find software out there to merge IIS logs (or whatever web server you're using). Then you analyze the merged logs. This strategy is optimal except in the case that you need real-time log analysis. Do you? Probably not. It's fairly resilient to failures (assuming you have redundant disks) because if a server goes down, you can just reboot it and reprocess any log ship, log merge or log analysis operations that were interrupted.
一个有趣的解决方案替代方案:
有 2 个日志文件附加程序
本地计算机中的第一个
如果出现网络故障,您将保留此日志。
第二次远程登录到 unix syslog 服务(当然
非常一致的网络连接)
我很久以前就使用过类似的方法,而且效果非常好,有
有很多用于分析 UNIX 日志的好工具。
An interesting solution alternative:
Have 2 log files appenders
First one in the local machine
In case of network failure you'll keep this log.
Second log to a unix syslog service remotely (of course
a very consistent network connection)
I used a similar approach long time ago, and it work really well, there are
a lot of nice tools for analyzing unix logs.
通常,负载平衡会在会话启动后将用户锁定到一台服务器。这样您就不必处理分布在多个服务器上的特定用户的日志。
Normally your load balancing would lock the user to one server after the session is started. Then you wouldn't have to deal with logs for a specific user being spread across multiple servers.
您可以尝试的一件事是将日志文件放在所有 Web 服务器都可以访问的位置,并将 log4net 配置为写入该文件。然而,当多个进程尝试写入同一个文件时,这可能会出现问题。我读过有关 NLog 的内容,它在这种情况下可能效果更好。
另外,log4net FAQ 有一个问题和可能的解决方案< /a> 对于这个确切的问题
One thing you could try is to have the log file in a location that is accessible by all web servers and have log4net configured to write to it. This may be problematic, however, with multiple processes trying to write to the same file. I have read about NLog which may work better in this scenario.
Also, the log4net FAQ has a question and possible solution to this exact problem