• haproxy软件的日志输出到指定文件


    默认haproxy的日志是输出到系统syslog中,查看起来不是非常方便,为了更好的管理haproxy的日志,我们在生产环境中一般单独定义出来。需要将haproxy的info及notice日志分别记录到不同的日志文件中。

    需要修改rsyslog配置,为了便于管理。将haproxy相关的配置独立定义到haproxy.conf,并放到/etc/rsyslog.d/下,rsyslog启动时会自动加载此目录下的所有配置文件。

    默认的haproxy的配置文件如下

    1. #---------------------------------------------------------------------
    2. # Example configuration for a possible web application. See the
    3. # full configuration options online.
    4. #
    5. # http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
    6. #
    7. #---------------------------------------------------------------------
    8. #---------------------------------------------------------------------
    9. # Global settings
    10. #---------------------------------------------------------------------
    11. global
    12. # to have these messages end up in /var/log/haproxy.log you will
    13. # need to:
    14. #
    15. # 1) configure syslog to accept network log events. This is done
    16. # by adding the '-r' option to the SYSLOGD_OPTIONS in
    17. # /etc/sysconfig/syslog
    18. #
    19. # 2) configure local2 events to go to the /var/log/haproxy.log
    20. # file. A line like the following can be added to
    21. # /etc/sysconfig/syslog
    22. #
    23. # local2.* /var/log/haproxy.log
    24. #
    25. log 127.0.0.1 local2 info
    26. chroot /var/lib/haproxy
    27. pidfile /var/run/haproxy.pid
    28. maxconn 40000
    29. user haproxy
    30. group haproxy
    31. daemon
    32. # turn on stats unix socket
    33. stats socket /var/lib/haproxy/stats
    34. #---------------------------------------------------------------------
    35. # common defaults that all the 'listen' and 'backend' sections will
    36. # use if not designated in their block
    37. #---------------------------------------------------------------------
    38. defaults
    39. mode http
    40. log global
    41. option httplog
    42. option dontlognull
    43. option http-server-close
    44. option forwardfor except 127.0.0.0/8
    45. option redispatch
    46. retries 3
    47. timeout http-request 10s
    48. timeout queue 1m
    49. timeout connect 10s
    50. timeout client 1m
    51. timeout server 1m
    52. timeout http-keep-alive 10s
    53. timeout check 10s
    54. maxconn 3000
    55. #---------------------------------------------------------------------
    56. # main frontend which proxys to the backends
    57. #---------------------------------------------------------------------
    58. #frontend main *:5000
    59. # acl url_static path_beg -i /static /images /javascript /stylesheets
    60. # acl url_static path_end -i .jpg .gif .png .css .js
    61. #
    62. # use_backend static if url_static
    63. # default_backend app
    64. #---------------------------------------------------------------------
    65. # static backend for serving up images, stylesheets and such
    66. #---------------------------------------------------------------------
    67. #backend static
    68. # balance roundrobin
    69. # server static 127.0.0.1:4331 check
    70. #---------------------------------------------------------------------
    71. # round robin balancing between the various backends
    72. #---------------------------------------------------------------------
    73. #backend app
    74. # balance roundrobin
    75. # server app1 127.0.0.1:5001 check
    76. # server app2 127.0.0.1:5002 check
    77. # server app3 127.0.0.1:5003 check
    78. # server app4 127.0.0.1:5004 check

    其中日志的配置文件有关日志的配置是 log         127.0.0.1 local2 info

    为了便于管理将haproxy相关的配置独立定义到haproxy.conf

    配置方式

    1.编辑“/etc/sysconfig/rsyslog”文件,将如下配置增加 -r 参数:

    SYSLOGD_OPTIONS=""
    改成
    SYSLOGD_OPTIONS="-r"

    2.编辑“/etc/rsyslog.conf”取消红框部分内容的注释,并在“local7.*”前面插入一行:

    local2.*                /var/log/haproxy/haproxy.log

    3.重启服务

    重启 rsyslog

    systemctl restart rsyslog

  • 相关阅读:
    JVM运行流程
    [ruby on rails]rails6.0升级6.1
    linux5-make、库文件(静态库和共享库)
    IOC理解
    水仙花数的判断C语言,+最终代码优化
    【 React 】对React refs的理解?应用场景?
    okhttp关于header修改
    路由器二次开发一步一步把工业路由器变成一个高端的可指定出网、节点和链路的路由器,包含详细过程及快捷脚本(二)
    【Linux】——select详解
    JS中的事件循环eventloop
  • 原文地址:https://blog.csdn.net/rendongxingzhe/article/details/127941288