GrepBoard/매뉴얼
605 편 ·

HAProxy 서버 DOWN — Layer7 wrong status 점검

·시험 환경 Ubuntu 24.04 · HAProxy 2.8.16 · Python 3.12 (시험용 백엔드)·시험 범위 ↓·7 단계

HAProxy 가 서버를 DOWN 으로 찍을 때 남기는 이유 문구를 재현해 뜻을 가르고, 헬스 엔드포인트가 404·301 을 줄 때의 설정과 inter·fall·rise 판정 시간을 확인합니다.

Server app/s1 is DOWN, reason: Layer7 wrong status, code: 404 — 서버는 떠 있는데 HAProxy 가 빼 버린 줄입니다. 설정을 만지기 전에 reason: 뒤 문구부터 읽습니다. 아래 로그는 HAProxy 2.8.16 의 포트 18641 에 백엔드 서버 넷을 붙이고 각각 다르게 망가뜨려 얻은 실제 줄이며, 앞의 +0.3s 는 시작 후 경과 시간이고 긴 줄은 … 로 줄였습니다. 서버가 모두 빠진 뒤의 503 은 이 글, 로그의 SC-- 는 이 글에 있습니다.

[1] DOWN 로그의 reason: 을 읽습니다. s1 은 /health 가 404, s2 는 301, s3 은 포트에 듣는 프로세스가 없고, s4 는 응답이 없는 주소입니다.

output
+  0.3s Server app/s1 is DOWN, reason: Layer7 wrong status, code: 404, info: "Not Found", check duration: 9ms. 3 active and 0 backup servers left. …+  0.8s Server app/s2 is DOWN, reason: Layer7 wrong status, code: 301, info: "Moved Permanently", check duration: 1ms. 2 active and 0 backup servers left. …+  1.2s Server app/s3 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 1 active and 0 backup servers left. …+  3.8s Server app/s4 is DOWN, reason: Layer4 timeout, check duration: 2003ms. 0 active and 0 backup servers left. …+  3.8s backend app has no server available!

[2] 문구를 층으로 가릅니다. Layer4 는 TCP 연결, Layer7 은 HTTP 응답 단계의 실패입니다.

문구뜻볼 곳
Layer4 connection problem연결 거부(Connection refused) 등백엔드가 그 주소·포트에서 듣는지 ss -tlnp
Layer4 timeout연결 응답이 없음주소 · 라우팅 · 방화벽
Layer7 wrong status응답은 왔지만 상태 코드가 기대와 다름code: 값, 4~5단계
Layer7 timeout연결 뒤 timeout check 안에 응답이 없음헬스 핸들러가 느린지

Layer7 timeout 은 5초 뒤에 답하는 /health 에 timeout check 1s 를 걸어 얻었고 check duration: 1001ms 로 찍혔습니다.

[3] 현재 상태는 런타임 API 의 show stat 로 봅니다(global 에 stats socket 필요). 관리 매뉴얼 9.1절 CSV 목록의 status·check_status·check_code 열만 자릅니다.

console
# echo "show stat" | socat stdio /run/haproxy/admin.sock | cut -d, -f1,2,18,37,38
output
# pxname,svname,status,check_status,check_codeapp,s1,DOWN,L7STS,404app,s2,DOWN,L7STS,301app,s3,DOWN,L4CON,app,s4,DOWN,* L4TOUT,

L7STS · L4CON · L4TOUT 는 위 로그의 Layer7 wrong status · Layer4 connection problem · Layer4 timeout 과 짝입니다. 마지막 서버의 * 는 매뉴얼 표에 설명이 없어 뜻을 단정하지 않습니다.

[4] 체크가 보내는 요청을 설정에서 확인하고 같은 요청을 curl 로 보냅니다. option httpchk 만 쓰면 매뉴얼 기준 메서드는 OPTIONS, 경로는 /, 버전은 HTTP/1.0 입니다. 요청을 바꾸는 줄이 http-check send 입니다.

/etc/haproxy/haproxy.cfg
backend app    option httpchk   http-check send meth GET uri /health ver HTTP/1.1 hdr Host example.com   http-check expect status 200    server s1 192.0.2.10:8080 check inter 2s fall 3 rise 2
console
$ curl -si -H 'Host: example.com' http://192.0.2.10:8080/health | head -1HTTP/1.1 404 Not Found

[5] 상태 코드를 맞춥니다. http-check expect 를 생략하면 2xx·3xx 를 모두 통과시킨다고 매뉴얼에 나와 있습니다. 그래서 위 설정의 status 200 이 301 을 Layer7 wrong status 로 만들었습니다. 그 줄만 지우고 s1 은 404, s2 는 301 로 두고 다시 돌리면 s1 만 DOWN 입니다.

output
+  0.1s Server app/s1 is DOWN, reason: Layer7 wrong status, code: 404, info: "Not Found", check duration: 1ms. 1 active and 0 backup servers left. …

301 이 정상이면 http-check expect status 200,301 로 허용하고, 아니면 uri 를 리다이렉트 도착 주소로 바꿉니다. 404 는 기본 규칙으로도 실패이니 앱에 /health 가 있는지 먼저 봅니다.

[6] 판정 속도는 inter(체크 간격, 기본 2000ms) · fall(DOWN 까지 연속 실패, 기본 3) · rise(UP 까지 연속 성공, 기본 2)가 정합니다. 두 서버에 다른 값을 주고 /health 를 200 → 404 → 200 으로 바꿨습니다.

conf
    server slow 192.0.2.10:8080 check inter 2s fall 3 rise 2    server fast 192.0.2.10:8081 check inter 500ms fall 2 rise 1
output
+  5.0s ## mode -> 404+  5.6s Server app/fast is DOWN, reason: Layer7 wrong status, code: 404, …+ 10.1s Server app/slow is DOWN, reason: Layer7 wrong status, code: 404, …+ 15.0s ## mode -> 200+ 15.2s Server app/fast is UP, reason: Layer7 check passed, code: 200, …+ 18.1s Server app/slow is UP, reason: Layer7 check passed, code: 200, …

## mode 줄은 상태를 바꾼 시각을 시험 스크립트가 적은 것입니다. DOWN 까지 fast 는 0.6초, slow 는 5.1초, 복구는 0.2초와 3.1초였습니다. 값을 줄이면 빨리 빼고 빨리 되돌리는 대신 일시적인 실패에도 서버가 들락거립니다.

[7] 설정을 고쳤으면 검사한 뒤 reload 합니다. 서버가 살아나면 is UP 줄이 찍히고, 그 뒤 요청이 다시 그 서버로 갑니다.

console
# haproxy -c -f /etc/haproxy/haproxy.cfgConfiguration file is valid# systemctl reload haproxy
output
+ 14.3s Server app/s1 is UP, reason: Layer7 check passed, code: 200, check duration: 1ms. 1 active and 0 backup servers online. 0 sessions requeued, 0 total in queue.+ 20.0s 203.0.113.7:44076 [19/Oct/2026:12:58:04.869] web app/s1 0/0/0/1/1 200 117 - - ---- 1/1/0/0/0 0/0 "GET / HTTP/1.1"

HAProxy 로그를 브라우저에서 바로 분석 ↗ — 아무것도 올라가지 않습니다.

#haproxy#health-check