본문 바로가기

리눅스

[리눅스] HAProxy 로깅(HAProxy Logging)

728x90

HAProxy 로깅(HAProxy Logging)

rsyslog 설정

- rsyslog에 대한 로깅 구성

$ vim /etc/rsyslog.conf
...
#HAproxy
local0.*                                                /var/log/haproxy0.log
local1.*                                                /var/log/haproxy1.log
$ systemctl restart rsyslog

HAProxy 로깅

haproxy.cfg 편집

- log /dev/log local0
- log /dev/log local1 notice

- log global

$ vim /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    #log         127.0.0.1 local2
    log         /dev/log local0
    log         /dev/log local1 notice

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000
    ....

활성화를 위해 /etc/default/haproxy 파일 생성

$ echo "ENABLED=1" > /etc/default/haproxy

haproxy 서비스 재기동

$ systemctl restart haproxy

로그 파일 확인

$ ls -l /var/log | grep haproxy
-rw-------  1 root   root      668 Nov 24 20:42 haproxy0.log
-rw-------  1 root   root      668 Nov 24 20:42 haproxy1.log
$ cat /var/log/haproxy0.log
...
Nov 24 20:42:03 datanode03 haproxy[6107]: Proxy www-lb started.
Nov 24 20:42:03 datanode03 haproxy[6107]: Proxy www-lb started.
Nov 24 20:42:03 datanode03 haproxy[6107]: Proxy kibana5601 started.
Nov 24 20:42:03 datanode03 haproxy[6107]: Proxy elasticsearch9200 started.
Nov 24 20:42:03 datanode03 haproxy[6107]: Proxy stats started.

logrotate로 로그 로테이트

$ vim /etc/logrotate.d/haproxy
#/var/log/haproxy.log {
/var/log/haproxy*.log {
    daily
    rotate 10
    missingok
    notifempty
    compress
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
        /bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}

 

https://www.haproxy.com/blog/introduction-to-haproxy-logging/

 

728x90