haproxy配置日志及自定义日志

发布时间:2020-05-02 17:48:22 作者:weilovepan520
来源:网络 阅读:5038

日志级别:

    emerg 0 系统不可用
    alert 1 必须马上采取行动的事件
    crit 2 关键的事件
    err 3 错误事件
    warning 4 警告事件
    notice 5 普通但重要的事件
    info 6 有用的信息
    debug 7 调试信息

配置记录日志:

    在默认情况haproxy是不记录日志的;

    通过配置haproxy.cfg使其记录日志

    haproxy.cfg:开启haproxy日志记录

        log 127.0.0.1 local2
    /etc/rsyslog.conf:利用rsyslog接收日志:

        去掉这两行的注释:
            $ModLoad imudp    
            $UDPServerRun 514
        新增这一行:
            local2.* /var/log/haproxy.log

    重启rsyslog,查看udp的514端口是否开启:

        #/etc/init.d/rsyslog restart

        #netstat -tunpl

配置haproxy记录更详细的日志:

    默认的日志可读性很差,我们需要显示更多的信息,但默认的都捕获不到,只能自定义需要显示的内容了

    capture request header Host len 64
    capture request header User-Agent len 128
    capture request header X-Forwarded-For len 100
    capture request header Referer len 200
    capture response header Server len 40
    capture response header Server-ID len 40
    log-format %ci:%cp\ %si:%sp\ %B\ %U\ %ST\ %r\ %b\ %f\ %bi\ %hrl\ %hsl\

    重启haproxy即可

捕获请求头参考官网:http://cbonte.github.io/haproxy-dconv/1.7/configuration.html#8.8

自定义日志格式参考官网:http://cbonte.github.io/haproxy-dconv/1.7/configuration.html#8.2.4

推荐阅读:
  1. Haproxy + keepalived 负载均衡日志定制
  2. Nginx日志自定义记录以及启用日志缓冲区详解

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

日志 haproxy rox

上一篇:现代中小企业IT基础平台建设 - 完整案例实战(09_附录C)

下一篇:Python入门篇

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》