• Nginx系列(十一)——通过日志进行故障排查


    Debugging and Troubleshooting with Access Logs, Error Logs, and Request Tracing
    故障排查

    Configuring Access Logs
    请求日志配置
    http {
    log_format geoproxy #日志格式命名为geoproxy
    '[$time_local] $remote_addr '
    '$realip_remote_addr $remote_user '
    '$request_method $server_protocol '
    '$scheme $server_name $uri $status '
    '$request_time $body_bytes_sent '
    '$geoip_city_country_code3 $geoip_region '
    '"$geoip_city" $http_x_forwarded_for '
    '$upstream_status $upstream_response_time '
    '"$http_referer" "$http_user_agent"';
    ...
    }
    使用以上格式的日志
    server {
    access_log /var/log/nginx/access.log geoproxy;
    ...
    }


    Configuring Error Logs
    配置错误日志
    error_log /var/log/nginx/error.log warn; #levels的值可以是debug,info,notice,warn,error,
    crit,alert,emerg . 这个功能需要nginx在配置时使用了with-debug选项


    Forwarding to Syslog
    转发系统日志
    使用以下配置
    error_log syslog:server=10.0.1.42 debug;
    access_log syslog:server=10.0.1.42,tag=nginx,severity=info geoproxy;
    syslog的服务器可以是elk等常见的日志集中分析平台


    Request Tracing
    请求跟踪
    log_format trace '$remote_addr - $remote_user [$time_local] '
    '"$request" $status $body_bytes_sent '
    '"$http_referer" "$http_user_agent" '
    '"$http_x_forwarded_for" $request_id';
    upstream backend {
    server 10.0.0.42;
    }
    server {
    listen 80;
    add_header X-Request-ID $request_id; # Return to client。添加一个request_id值到日志中
    location / {
    proxy_pass http://backend;
    proxy_set_header X-Request-ID $request_id; #Pass to app。添加request id 到header中
    access_log /var/log/nginx/access_trace.log trace;
    }
    }

  • 相关阅读:
    [开源]WinForm 控件使用总结
    类型转换一种处理方式
    [算法]斐波那契数列
    [算法]1 − 2 + 3 − 4 + …
    [算法]冒泡排序
    [开源]基于Log4Net简单实现KafkaAppender
    基于Log4Net本地日志服务简单实现
    项目打jar包,怎么把第三放jar包一起打入
    将博客搬至CSDN
    将字段转换为阿拉伯数字
  • 原文地址:https://www.cnblogs.com/biaopei/p/12953544.html
Copyright © 2020-2023  润新知