负载均衡配置了健康检查,健康检查会一直访问后端的nginx服务器,生成一堆没用的日志,这也会影响后面的日志采集。
要怎么忽略负载均衡的健康检查日志呢?
日志如下:
x.x.x.x - - [28/Jun/2022:14:07:46 +0800] "GET / HTTP/1.1" 200 166 "-" "clb-healthcheck" "-"
x.x.x.x - - [28/Jun/2022:14:07:47 +0800] "GET / HTTP/1.1" 200 166 "-" "clb-healthcheck" "-"
nginx有一个conditional-logging,可以针对某些性的忽略某些日志。具体可以看”附录1、nginx官方开启条件日志“
具体:
1、在nginx.conf创建一个map
# vim /etc/nginx/nginx.conf ##添加以下内容
http {
...
#Disable logging for ELB healthcheck. It creates lots of noise on logging platform
map $http_user_agent $ignore_ua {
default 1;
"clb-healthcheck" 0;
}
...
}
2、在nginx指定server配置条件日志,在access_log添加if=$ignore_ua
# vim /etc/nginx/conf.d/66office.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
access_log /var/log/nginx/access.log combined if=$ignore_ua;
}
附录:
附录1、nginx官方开启条件日志
————————————————
声明:本文由 66办公「66office.com」原创,欢迎转载,转载请保留链接。