由于负载均衡会转发客户端的请求到web服务器,所以web服务往往记录的是负载均衡的IP,现在可以通过下面的配置,让apache记录真实客户端IP
#LogFormat “\”%{X-Forwarded-For}i\”%l %t \"%r\" %>s %b \"%{Referer}i\"\"%{User-Agent}i\"" combined
#LogFormat "%h %l %u %t \"%r\" %>s%b \"%{Referer}i\" \"%{User-Agent}i\"" combined
#LogFormat “\”%{X-Forwarded-For}i\” %l %t \"%r\" %>s %b\"%{Referer}i\" \"%{User-Agent}i\"" combined
cut -d " " -f1 www.sr1.com_access_log | sort |uniq -c|sort-rn -k1
结果:
4799 192.168.254.251
1335 192.168.254.250
2 192.168.254.191
由于负载均衡的健康检查会造成apache的访问日志备大量写入,使得访问量无法统计,使用下面的方法可以让apache不再记录负载均衡的健康检查日志
SetEnvIfRequest_URI "^/checkstatus.html" dontlog
ErrorLog"logs/error_log"
LogLevel warn
CustomLog"logs/access_log" combined env=!dontlog
<VirtualHost*:80>
DocumentRoot"/usr/local/httpd-2.2.9/htdocs/sr1/"
ServerName www.sr1.com
ServerAlias www.sr1.com
SetEnvIf Request_URI "^/checkstatus.html " dontlog
ErrorLog"logs/www.sr1.com_error_log"
CustomLog"logs/www.sr1.com_access_log" haproxy env=!dontlog
</VirtualHost>
本文出自 “Study-Everyday” 博客,请务必保留此出处http://studys.blog.51cto.com/9736817/1591441
原文地址:http://studys.blog.51cto.com/9736817/1591441