简体   繁体   English

AWS ELB的背后:如何从“ netstat”中获取真实IP?

[英]Behind AWS ELB : How to grab the Real IP from “netstat”?

I'm using AWS Elastic Load Balancing (ELB) in front of 2 Linux Web Servers. 我在2个Linux Web服务器之前使用AWS Elastic Load Balancing (ELB) But (based on my requirement) i need to know the Real IPs from the Web Servers' perspective, especially when i use netstat . 但是(根据我的要求)我需要从Web服务器的角度了解真实IP,尤其是当我使用netstat

I need to know the number of incoming connections from each IPs (from NETSTAT) , as in real time. 我需要实时了解每个IP(来自NETSTAT)的传入连接数。 So basically in Linux (without ELB in front) , below netstat command perfectly works: 因此,基本上在Linux (前面没有ELB)中netstat命令下面的命令可以正常工作:

netstat -tn 2>/dev/null | grep :80

But now i can only see the internal IP(s) of the ELB ; 但是现在我只能看到ELB的内部IP which is making the whole thing quite difficult. 这使整个事情变得非常困难。

What is the solution for this please? 请问对此有什么解决方案? Thanks. 谢谢。

您可以从ELB访问日志中获取客户端源IP,并将EMR与Hive一起使用以计算来自同一IP的客户端请求进入的次数。

If you prefer a more "manual" ways: you could use tcpdump or ngrep and search for "x-forwarded-for" header on your web servers. 如果您更喜欢“手动”方式:您可以使用tcpdump或ngrep并在Web服务器上搜索“ x-forwarded-for”标头。

If you want a proper way: set some logging in your application, log the clients requests with the x-forwarded-for header. 如果您想要一种正确的方法:在您的应用程序中设置一些日志记录,请使用x-forwarded-for标头记录客户端请求。

Whatever method you choose, you could then install cloudwatch logs agent on your machines to monitor the logs generated. 无论选择哪种方法,都可以在计算机上安装cloudwatch logs代理以监视生成的日志。 This agent takes care of log rotation, sending your logs to AWS as a stream (through kinesis behind the scene), and you can then create log metrics to monitor whatever you like in your logs, eg the number of connections in real time, and even configure alarms based on this if you like. 该代理负责日志轮换,将日志作为流(通过后台运动)发送到AWS,然后您可以创建日志指标来监视日志中所需的内容,例如实时连接数,以及如果愿意,甚至可以基于此配置警报。 You can then create dashboards with your metrics and have a nice monitoring panel including your custom log metrics. 然后,您可以使用指标创建仪表板,并拥有一个不错的监控面板,其中包括您的自定义日志指标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM