我有两个HAProxy虚拟机和两个 Apache 虚拟机(流浪机器),如下所示。
192.168.50.11 HAPROXY VM1
192.168.50.12 HAPROXY VM2
192.168.50.21 APACHE VM1
192.168.50.22 APACHE VM2
我遇到的问题是 Apacheaccess.log
文件每秒都在增长,因为即使没有来自任何客户端的请求,两个 HAProxy 服务器都在 ping 两个 Apache 服务器。我需要停止记录不必要的日志,如下所示。我在两个 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 不记录匹配的请求: