防止ApacheloggingHAProxy请求

我有两个HAProxy虚拟机和两个Apache虚拟机(stream浪机)如下。

192.168.50.11 HAPROXY VM1 192.168.50.12 HAPROXY VM2 192.168.50.21 APACHE VM1 192.168.50.22 APACHE VM2 

我遇到的问题是Apache access.log文件每秒都在增长,因为即使没有来自任何客户端的请求,两个HAProxy服务器都会ping这两个Apache服务器。 我需要停止logging不必要的日志,如下所示。 我有两个HAProxy服务器上运行的Keepalived服务。

 $sudo tail -f /var/log/apache2/access.log 192.168.50.11 - - [09/Jul/2016:12:46:49 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-" 192.168.50.11 - - [09/Jul/2016:12:46:51 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-" 192.168.50.12 - - [09/Jul/2016:12:46:51 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-" 192.168.50.11 - - [09/Jul/2016:12:46:51 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-" 192.168.50.11 - - [09/Jul/2016:12:46:53 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-" 192.168.50.12 - - [09/Jul/2016:12:46:53 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-" 192.168.50.11 - - [09/Jul/2016:12:46:53 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-" 192.168.50.11 - - [09/Jul/2016:12:46:55 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-" 192.168.50.12 - - [09/Jul/2016:12:46:55 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-" 192.168.50.11 - - [09/Jul/2016:12:46:55 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-" ....... ....... 

这些不是来自任何人的实际要求。

haproxy.cfg

 global log /dev/log local0 log 127.0.0.1 local1 notice user haproxy group haproxy maxconn 2000 daemon defaults log global mode http option httplog option dontlognull retries 3 timeout connect 5000 timeout client 50000 timeout server 50000 frontend http-in bind 192.168.50.10:80 default_backend webservers backend webservers balance roundrobin stats enable stats auth admin:admin stats uri /haproxy?stats option httpchk option forwardfor option http-server-close server webserver1 192.168.50.21:80 check server webserver2 192.168.50.22:80 check 

诀窍是使用SetEnvIf指令为某些请求设置环境标志 ,然后指示Apache不logging与之匹配的请求:

 SetEnvIf Request_URI \.gif do-not-log-this-request SetEnvIf Remote_Addr "192\.168\.50\.11" do-not-log-this-request SetEnvIf Request_Method OPTIONS do-not-log-this-request CustomLog logs/access_log common env=!do-not-log-this-request