자~ 오늘도 펭귄의 허접 서버관리 강좌는 이어집니다.
오늘은 아파치에 쓸데 없는 로그가 남지 않도록 하는 법을 설명드립니다.
아파치 로그가 커지는 것은 대부분이 이미지 파일 관련 로그와 검색엔진 robot 관련 로그 때문입니다.
따라서, 이 두 관련 로그만 남지 않게 처리를 해도 로그 파일의 용량은 꽤 줄어들 수 있습니다.
먼저 아파치의 httpd.conf 를 열어 로그 포맷부터 변경합니다.
#LogLevel warn
LogLevel debug
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
#LogFormat "%h %l %u %t \"%r\" %>s %b" common
#LogFormat "%{Referer}i -> %U" referer
#LogFormat "%{User-agent}i" agent
#
로그 레벨 밑 부분에 LogFormat 항목이 있습니다. 이를 위처럼 모두 주석 처리하고
그 대신 아래와 같이 로그 포맷을 새로 정의해 줍니다.
## 로그 환경변수 재설정 (조형진 수정함 08/08/29)
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{User-Agent}i\"" use_robot
그 다음에는, 검색 엔진 로봇과 관련된 환경변수를 설정해 줍니다.
## 환경변수 설정 (08/08/29 조형진 추가함)
BrowserMatchNoCase "ru-robot" do_not_log is_a_robot
BrowserMatchNoCase "Slurp/si" do_not_log is_a_robot
BrowserMatchNoCase "Mercator" do_not_log is_a_robot
BrowserMatchNoCase "Gulliver" do_not_log is_a_robot
BrowserMatchNoCase "SyncIT/" do_not_log is_a_robot
BrowserMatchNoCase "FAST-WebCrawler" do_not_log is_a_robot
BrowserMatchNoCase "Lycos_Spider" do_not_log is_a_robot
BrowserMatchNoCase "^ia_archive" do_not_log is_a_robot
BrowserMatchNoCase "^tv" do_not_log is_a_robot
BrowserMatchNoCase "Scooter" do_not_log is_a_robot
BrowserMatchNoCase "ZyBorg/" do_not_log is_a_robot
BrowserMatchNoCase "KIT-Fireball" do_not_log is_a_robot
BrowserMatchNoCase "Googlebot/" do_not_log is_a_robot
BrowserMatchNoCase "DIIbot/" do_not_log is_a_robot
BrowserMatchNoCase "teoma_agent3" do_not_log is_a_robot
BrowserMatchNoCase "empas_robot" do_not_log is_a_robot
윗 설정은 BrowserMatchNoCase 옵션으로 각 로봇들을 정의해 주고 이를 do_not_log와 is_a_robot 라는 환경변수로 정의하는 부분이 되겠습니다.
다음에는, 로그 파일인 access_log 에 여태까지 설정한 변수들이 적용되도록 하고
검색 엔진 로봇과 관련된 로그는 robot_log 라는 파일로 따로 저장되도록 하기 위해 아래와 같이 설정하여 줍니다.
#CustomLog /usr/local/apache/logs/access_log common
CustomLog /usr/local/apache/logs/access_log combined env=!do_not_log
CustomLog /usr/local/apache/logs/robot_log use_robot env=is_a_robot
## 이미지 파일을 요청했을 경우 로그에 기록하지 않는다. (08/08/29 조형진 추가함)
#
SetEnvIfNoCase Request_URI "\.(gif|jpg|png|swf|css|js|java)$" do_not_log
현재의 CustomLog 부분에서 access_log 관련된 사항을 주석으로 처리하고, do_not_log라는 환경변수를 로그에 적용시키되
do_not_log를 제외한 부분만 기록하라는 뜻에서 env=!do_not_log (!는 논리 연산의 not과 똑같다는 거, 다들 아시죠? ^^) 옵션을
로그에 적용합니다.
또한 SetENvIfNoCase 를 사용하여 지정된 확장자가 들어가는 로그는 모두 do_nog_log라는 환경변수로 처리하여 로그파일에
남지 않도록 처리해 주는 부분이 되겠습니다.
httpd.conf 파일을 저장한 후, 반드시 아파치 데몬을 restart 해 주어야 변경된 사항이 적용됩니다.
다음에는 logrotate 를 이용한 로그 관리에 대해 설명드리겠습니다.출처: http://nuevacancion.blog.me/120055434520






