아파치 로그 로테이트 설정은 어떻게 하나요?
💡 요약 정리
- 아파치 로그 로테이트란 일정한 조건(용량, 시간 등)에 따라 로그 파일을 회전(rotating)시키는 설정입니다.
- 아파치 자체 rotatelogs 프로그램을 사용하여 로그 파일을 2048MB 단위로 분할할 수 있습니다.
- httpd.conf 또는 httpd-vhost.conf 파일에서 CustomLog 설정을 수정해야 합니다.
- 설정 후 아파치를 재시작하여 적용합니다.
1. 설치환경 및 개요
- CentOS 5.x (64bit)
- Apache 2.2.23
- 소스 컴파일 설치 위치:
/home/apache
로그 로테이트란?
- 아파치는 기본적으로
access_log파일과error_log파일을 생성합니다. - 전통적인 logrotate 패키지 이외에도, 아파치에서는 자체 제공하는 rotatelogs 프로그램을 이용해 로그를 회전시킬 수 있습니다.
2. httpd.conf 또는 httpd-vhost.conf 파일 수정
로그 파일을 2048MB 단위로 회전하도록 설정하려면, 다음과 같이 로그 설정을 수정합니다.
- 기존 Custom 로그는 주석 처리합니다.
- rotatelogs 파일 위치는
/home/apache/bin/rotatelogs입니다.
[root@cafe24 bin]# vi /home/apache/conf/extra/httpd-vhosts.conf
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/home/apache/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
#CustomLog "logs/dummy-host.example.com-access_log" common
CustomLog "home/apache/bin/rotatelogs logs/dummy-host.example.com-access_log.%m%d-%H%M%S 2048M" common
</VirtualHost>
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
3. 설정 적용을 위한 아파치 재시작
설정을 완료한 후, 다음 명령어로 아파치를 재시작합니다.
[root@cafe24 bin]# /home/apache/bin/apachectl restart
4. 로그 확인
아파치가 정상적으로 구동 중인지 확인하려면 다음 명령어를 사용할 수 있습니다.
[root@cafe24 bin]# netstat -nlpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2112/httpd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1266/sshd
[root@cafe24 bin]#