由于负载均衡会转发客户端的请求到web服务器,所以web服务往往记录的是负载均衡的IP,现在可以通过下面的配置,让apache记录真实客户端IP 语法#LogFormat “\”%{X-Forwarded-For}i\”%l %t \"%r\" %>s %b \"%{Referer}i\"\"%{User-Agent}i\"" combined
普通日志和记录客户端IP的apache日志比较#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的访问日志备大量写入,使得访问量无法统计,使用下面的方法可以让apache不再记录负载均衡的健康检查日志
配置(checkstatus.html):SetEnvIfRequest_URI "^/checkstatus.html" dontlog ErrorLog"logs/error_log" LogLevel warn CustomLog"logs/access_log" combined env=!dontlog 虚拟主机不记录健康检查日志(checkstatus.html):<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>
|