> ## Content Index
> Fetch the complete content index at: https://suitmyself.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# HAPROXY에 rsyslog 셋팅
- URL: https://suitmyself.com/haproxye-rsyslog-sesting/
- Published: 2023-05-05T10:54:23.000Z
- Updated: 2026-09-20T06:17:55.000Z
- Author: Benjamin Kim
- Tags: Server, #Import 2026-09-15 05:58

## 1\. haproxy.cfg 의 수정

```bash
. . .
# 2) configure local2 events to go to the /var/log/haproxy.log
#   file. A line like the following can be added to
#   /etc/sysconfig/syslog
#
#    local2.*                       /var/log/haproxy.log
#
    #log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
. . .

```

`log 127.0.0.1 local2` 해당 내용을 주석 처리하고 다음의 내용을 추가한다.  
`log /dev/log local0`

```bash
. . .
#    local2.*                       /var/log/haproxy.log
#
     #log         127.0.0.1 local2
     log         /dev/log local0

     chroot      /var/lib/haproxy
     pidfile     /var/run/haproxy.pid
. . .

```

## 2\. dev 디렉토리의 생성

`/var/lib/haproxy/dev` 디렉토리를 생성한다.

```bash
sudo mkdir /var/lib/haproxy/dev

```

haproxy를 재시작 한다.

```bash
sudo systemctl restart haproxy.service

```

## 3\. Rsyslog 셋팅

`/etc/rsyslog.d/`폴더에 있는 `haproxy.conf`파일을 수정한다.

```bash
$AddUnixListenSocket /var/lib/haproxy/dev/log

# Send HAProxy messages to a dedicated logfile
:programname, startswith, "haproxy" {
 /var/log/haproxy.log
 stop
}

```

## 4\. logroate 수정

`/etc/logrotate.d/haproxy` 파일을 다음과 같이 작성한다.

```bash
/var/log/haproxy/*log {
   daily
   rotate 90
   create 0644 nobody nobody
   missingok
   notifempty
   compress
   sharedscripts
   postrotate
       /bin/systemctl restart rsyslog.service > /dev/null 2>/dev/null || true
   endscript
}

```

수정완료 후 rsyslog를 재실행한다.

```bash
sudo systemctl restart rsyslog

```

2022년 1월 17일 haproxy.conf

```bash
# Provides UDP syslog reception
# Collect log with UDP
$ModLoad imudp
$UDPServerAddress 127.0.0.1
$UDPServerRun 514
$template Haproxy, "%msg%\n"
#rsyslog 에는 rsyslog 가 메세지를 수신한 시각 및 데몬 이름같은 추가적인 정보가 prepend 되므로, message 만 출력하는 템플릿 지정
# 이를 haproxy-info.log 에만 적용한다.

# Creating separate log files based on the severity

# 모든 haproxy 를 남기려면 다음을 주석해재, 단 access log 가 기록되므로, 양이 많다.
local0.* /var/log/haproxy-traffic.log

# local0.=info 는 haproxy 에서 에러로 처리된 이벤트들만 기록하게 됨 (포맷 적용)
local0.=info /var/log/haproxy-info.log;Haproxy

# local0.notice 는 haproxy 가 재시작되는 경우와 같은 시스템 메세지를 기록하게됨 (포맷 미적용)
local0.notice /var/log/haproxy-admin.log

$AddUnixListenSocket /var/lib/haproxy/dev/log

# Send Haproxy message to a dedicated logfile
:programname, startswith, "haproxy" {
  /var/log/haproxy.log
  stop
  }

```

[https://www.haproxy.com/blog/introduction-to-haproxy-logging/](https://www.haproxy.com/blog/introduction-to-haproxy-logging/?ref=suitmyself.com)