Apache mod_status 모듈은 어떻게 활용하나요?
💡 Apache mod_status 모듈은 아파치 프로세스 상태에 대한 정보를 실시간으로 제공하는 확장 모듈입니다. 서버 가동 시간, 현재 처리 중인 요청 수, 트래픽 통계, 각 워커 프로세스의 상태 등을 웹 브라우저를 통해 확인할 수 있어 서버 모니터링과 성능 분석에 유용합니다.
환경 정보
이 가이드는 다음 환경을 기준으로 작성되었습니다:
- OS: CentOS 5.x (64bit)
- Apache 버전: Apache 2.2.23
- 설치 경로: /home/APM/apache
mod_status 모듈 확인
먼저 Apache에 mod_status 모듈이 설치되어 있는지 확인합니다.
vi /home/APM/apache/conf/httpd.conf
httpd.conf 파일에서 모듈 확인:
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so # mod_status 모듈
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule asis_module modules/mod_asis.so
LoadModule info_module modules/mod_info.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule imagemap_module modules/mod_imagemap.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module modules/libphp5.so
LoadModule jk_module modules/mod_jk.so
LoadModule status_module modules/mod_status.so 라인이 주석 처리되지 않고 활성화되어 있어야 합니다.
mod_status 설정
httpd.conf 파일 하단에 다음 설정을 추가하고 Apache 서버를 재시작합니다.
vi /home/APM/apache/conf/httpd.conf
설정 추가:
# apache status setting
<Location /server-status>
SetHandler server-status
Order deny,allow
Allow from all
</Location>
ExtendedStatus On
설정 옵션 설명:
| 옵션 | 설명 |
|---|---|
<Location /server-status> | /server-status URL 경로에서 상태 정보 제공 |
SetHandler server-status | mod_status 핸들러 지정 |
Order deny,allow | 접근 제어 순서 설정 |
Allow from all | 모든 호스트에서 접근 허용 (보안상 주의) |
ExtendedStatus On | 확장 상태 정보 활성화 (상세 통계 제공) |
특정 IP만 허용하기 (권장):
보안을 위해 특정 IP에서만 접근하도록 제한할 수 있습니다.
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 192.168.1.100
Allow from 10.0.0.0/24
</Location>
ExtendedStatus On
Apache 재시작
설정을 적용하려면 Apache를 재시작합니다.
/home/APM/apache/bin/apachectl restart
또는 graceful 재시작 (기존 연결 유지):
/home/APM/apache/bin/apachectl graceful
mod_status 접속 및 확인
웹 브라우저에서 다음 URL로 접속합니다:
http://서버IP/server-status
출력 예시:
Apache Server Status for 1.234.20.101
Server Version: Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17 mod_jk/1.2.31
Server Built: Jan 21 2013 09:29:48
Current Time: Tuesday, 26-Feb-2013 10:39:36 KST
Restart Time: Tuesday, 26-Feb-2013 10:39:34 KST
Parent Server Generation: 11
Server uptime: 1 second
Total accesses: 0 - Total Traffic: 0 kB
CPU Usage: u0 s0 cu0 cs0
0 requests/sec - 0 B/second -
1 requests currently being processed, 4 idle workers
상태 정보 항목 설명
| 항목 | 설명 |
|---|---|
| Server Version | Apache 버전 및 컴파일된 모듈 정보 |
| Server Built | Apache 빌드 날짜 |
| Current Time | 현재 서버 시간 |
| Restart Time | 마지막 재시작 시간 |
| Server uptime | 서버 가동 시간 (uptime) |
| Total accesses | 서버 재시작 이후 총 요청 수 |
| Total Traffic | 서버 재시작 이후 총 트래픽 (MB/GB) |
| CPU Usage | CPU 사용률 (user, system, children user, children system) |
| requests/sec | 초당 처리 요청 수 (평균) |
| B/second | 초당 전송 바이트 수 (평균 대역폭) |
| requests currently being processed | 현재 처리 중인 요청 수 |
| idle workers | 대기 중인 유휴 워커 프로세스 수 |
자동 새로 고침 기능
URL 파라미터로 refresh를 추가하면 지정한 초 단위로 페이지가 자동 갱신됩니다.
http://서버IP/server-status?refresh=2
위 예시는 2초마다 자동으로 페이지를 새로고침합니다.
활용 사례:
- 실시간 트래픽 모니터링
- 부하 테스트 중 서버 상태 관찰
- DDoS 공격 의심 시 요청 패턴 분석
상태 기호 및 의미
mod_status 그래프에서 각 워커 프로세스의 상태는 다음 기호로 표시됩니다:
| 기호 | 의미 | 설명 |
|---|---|---|
| _ | Waiting for Connection | 접속을 기다리는 중 (유휴 상태) |
| S | Starting up | 기동 중 (서버 시작 중) |
| R | Reading Request | 요청을 읽고 있음 (클라이언트로부터 데이터 수신 중) |
| W | Sending Reply | 응답을 보내고 있음 (클라이언트에게 데이터 전송 중) |
| K | Keepalive | Keep-alive 요청을 위해 대기 중 |
| D | DNS Lookup | DNS 질의 중 (호스트 이름 조회) |
| C | Closing connection | 접속을 끊는 중 |
| L | Logging | 로그를 쓰는 중 |
| G | Gracefully finishing | 종료 처리 중 (graceful 재시작 시) |
| I | Idle cleanup of worker | Idle worker 정리 중 |
| . | Open slot with no current process | 프로세스 부재인 빈 슬롯 (사용 가능 슬롯) |
상태 그래프 예시
_W__KK____R_______________________________________________________________
위 그래프에서:
- _: 유휴 상태 워커
- W: 응답 전송 중
- K: Keep-alive 대기
- R: 요청 읽는 중
이를 통해 현재 1개의 워커가 응답 전송 중, 2개가 Keep-alive 대기, 1개가 요청 처리 중임을 알 수 있습니다.
ExtendedStatus 활성화 시 추가 정보
ExtendedStatus On 설정 시 다음과 같은 상세 정보가 추가로 제공됩니다:
추가 정보 항목:
- 각 워커 프로세스의 PID (Process ID)
- 클라이언트 IP 주소
- 처리 중인 요청의 URL
- 요청 처리 시간 (milliseconds)
- 각 워커의 CPU 사용량
- 요청의 HTTP 메서드 (GET, POST 등)
출력 예시:
Srv PID Acc M CPU SS Req Conn Child Slot Client VHost Request
0-0 12345 0/15/15 W 0.05 12 0 0.0 0.00 0.05 192.168.1.2 example.com GET /index.php HTTP/1.1
1-0 12346 0/10/10 _ 0.02 5 1 0.0 0.00 0.02 - - -
성능 분석 및 모니터링
1. 워커 프로세스 부족 확인
idle workers가 0 또는 매우 적은 경우 MaxClients 설정을 증가시켜야 합니다.
# httpd.conf
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256 # 증가
MaxRequestsPerChild 4000
</IfModule>
2. Keep-Alive 연결 과다 확인
상태 기 호 K가 지나치게 많으면 Keep-Alive 타임아웃을 줄여야 합니다.
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5 # 15초 → 5초로 감소
3. 슬로우 요청 탐지
ExtendedStatus On 상태에서 특정 요청의 처리 시간이 비정상적으로 길면 해당 스크립트나 쿼리를 최적화해야 합니다.
4. 트래픽 급증 확인
requests/sec과 B/second 값이 급증하면 DDoS 공격이나 트래픽 스파이크를 의심할 수 있습니다.
명령줄에서 상태 확인
curl이나 wget으로 명령줄에서 상태를 확인할 수 있습니다.
# 간단한 상태 확인
curl http://localhost/server-status
# 자동 갱신 모드
watch -n 2 "curl -s http://localhost/server-status | grep 'requests currently being processed'"
# 특정 항목만 추출
curl -s http://localhost/server-status | grep -E "requests/sec|idle workers"
보안 고려사항
1. 접근 제어 필수
Allow from all은 보안상 위험합니다. 반드시 특정 IP만 허용하세요.
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 192.168.1.100 # 관리자 IP
Allow from 127.0.0.1 # localhost
</Location>
2. VirtualHost별 설정
특정 가상 호스트에서만 mod_status를 활성화할 수 있습니다.
<VirtualHost *:80>
ServerName admin.example.com
<Location /server-status>
SetHandler server-status
Order deny,allow
Allow from 192.168.1.0/24
</Location>
</VirtualHost>
3. 인증 추가
Basic 인증을 추가하여 접근을 제한할 수 있습니다.
<Location /server-status>
SetHandler server-status
AuthType Basic
AuthName "Apache Status"
AuthUserFile /home/APM/apache/conf/.htpasswd
Require valid-user
</Location>
htpasswd 파일 생성:
/home/APM/apache/bin/htpasswd -c /home/APM/apache/conf/.htpasswd admin
# 패스워드 입력
모니터링 자동화
1. Nagios 플러그인
Nagios에서 mod_status를 모니터링할 수 있습니다.
# check_http 플러그인 사용
./check_http -H localhost -u /server-status?auto -w 100 -c 200
2. Zabbix 모니터링
Zabbix에서 web.page.get 아이템으로 mod_status 데이터를 수집할 수 있습니다.
3. 커스텀 스크립트
#!/bin/bash
# /usr/local/bin/check_apache_status.sh
IDLE_WORKERS=$(curl -s http://localhost/server-status?auto | grep "IdleWorkers" | awk '{print $2}')
if [ $IDLE_WORKERS -lt 5 ]; then
echo "WARNING: Only $IDLE_WORKERS idle workers available"
# 알림 전송 또는 로그 기록
fi
문제 해결
문제 1: mod_status 페이지가 표시되지 않음
# 모듈 로드 확인
/home/APM/apache/bin/httpd -M | grep status_module
# 출력: status_module (shared) 또는 (static)
# 설정 구문 오류 확인
/home/APM/apache/bin/apachectl configtest
# Apache 재시작
/home/APM/apache/bin/apachectl restart
문제 2: 403 Forbidden 오류
접근 제어 설정을 확인하세요.
# Allow 설정에 현재 접속 IP 추가
<Location /server-status>
SetHandler server-status
Order deny,allow
Allow from 192.168.1.100 # 현재 IP 추가
</Location>
문제 3: ExtendedStatus 정보가 표시되지 않음
# httpd.conf에 명시적으로 추가
ExtendedStatus On
# Apache 재시작
/home/APM/apache/bin/apachectl restart
문제 4: 성능 저하
ExtendedStatus On은 약간의 성능 오버헤드가 있습니다. 평상시에는 Off로 두고 필요할 때만 On으로 설정하세요.
machine-readable 형식
?auto 파라미터를 추가하면 스크립트에서 파싱하기 쉬운 형식으로 출력됩니다.
curl http://localhost/server-status?auto
출력 예시:
Total Accesses: 1234
Total kBytes: 5678
CPULoad: .123456
Uptime: 123456
ReqPerSec: 10.1234
BytesPerSec: 45678.9
BytesPerReq: 4567.89
BusyWorkers: 5
IdleWorkers: 10
Scoreboard: _W__KK____R_______________________________________________________________
이 형식은 모니터링 스크립트나 그래프 도구에서 활용하기 좋습니다.