서버 관리 · 7 min read · Jan 27, 2026

여러 개의 Apache 액세스 로그를 하나의 전체 액세스 로그로 병합하기

여러 개의 Apache 액세스 로그를 하나의 전체 액세스 로그로 병합하기

버전 1.0
저자: Falko Timme

웹 애플리케이션이 Apache 노드 클러스터에서 실행된다고 가정해 보겠습니다. 각 노드는 자체 Apache 액세스 로그를 생성하며, 이를 통해 Webalizer 또는 AWStats와 같은 도구로 페이지 뷰 통계를 생성할 수 있습니다. 명백히 각 Apache 노드에 대한 페이지 뷰 통계를 원하지 않고, 전체 페이지 뷰 통계를 원합니다. 이를 달성하기 위해 각 노드의 액세스 로그를 하나의 전체 액세스 로그로 병합해야 하며, 이를 Webalizer 또는 AWStats에 제공할 수 있습니다. logresolvemerge.pl이라는 Perl 스크립트가 있으며 (AWStats 패키지의 일부), 이를 통해 작업을 수행할 수 있습니다.

이것이 귀하에게 작동할 것이라는 보장은 하지 않습니다!

1 사전 참고

이것은 Debian 시스템에서 테스트했지만, 패키지 설치를 제외하고는 다른 모든 배포판에서 절차는 동일합니다. 배포판의 패키지 관리자를 사용하여 (예: apt, yum, yast, urpmi) 패키지를 설치하십시오.

단일 호스트를 사용하고 있다고 가정합니다 (일반적으로 통계를 생성하기 위해 Webalizer 또는 AWStats를 실행하는 호스트입니다) Apache 노드에서 액세스 로그를 수집합니다 (Apache 노드에서 로그를 수집하는 호스트로 전송하는 방법은 다루지 않습니다 - 예를 들어, 이 튜토리얼에서 보여준 것처럼 rsync를 사용할 수 있습니다: Mirror Your Web Site With rsync) - 여기서는 Apache 노드의 액세스 로그를 저장하기 위해 /var/log/webcluster 디렉토리를 사용하고 있습니다.

2 logresolvemerge.pl 설치하기

앞서 말했듯이, logresolvemerge.pl은 AWStats 패키지의 일부이므로 지금 설치합니다 (사용하고 싶지 않더라도 - Webalizer를 여전히 사용할 수 있습니다):

apt-get install awstats

logresolvemerge.pl은 이제 /usr/share/doc/awstats/examples 디렉토리에 위치합니다. 이를 /usr/local/bin으로 이동하여 PATH에 추가합시다:

mv /usr/share/doc/awstats/examples/logresolvemerge.pl /usr/local/bin 

(만약 logresolvemerge.pl을 찾을 수 없다면, 다음과 같이 검색할 수 있습니다:

updatedb
locate logresolvemerge.pl

그런 다음 /usr/local/bin으로 이동하십시오.)

3 logresolvemerge.pl 사용하기

/var/log/webcluster에 두 개의 액세스 로그가 있다고 가정해 보겠습니다: /var/log/webcluster/access_log_server1 및 /var/log/webcluster/access_log_server2.

여기서는 logresolvemerge.pl이 어떻게 작동하는지 보여주기 위해 두 개의 샘플 액세스 로그를 사용하고 있습니다. 두 액세스 로그 모두 데모 목적으로 동일한 데이터를 포함하고 있지만, 요청 날짜는 server1과 server2에서 1초 차이가 납니다. logresolvemerge.pl로 두 로그를 병합한 후, 전체 액세스 로그는 Webalizer와 AWStats가 올바르게 처리할 수 있도록 요청을 시간 순서대로 포함해야 합니다.

/var/log/webcluster/access_log_server1은 다음과 같습니다:

cat /var/log/webcluster/access_log_server1
192.6.178.101 - - [17/Oct/2007:18:50:27 +0200] "GET /themes/htf_glass/images/header_tab6.png HTTP/1.0" 200 7434 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
72.149.148.248 - - [17/Oct/2007:18:50:29 +0200] "GET /misc/menu-leaf.png HTTP/1.1" 200 108 "https://www.howtoforge.com/the_perfect_desktop_mandriva_2008.0" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
24.8.231.74 - - [17/Oct/2007:18:50:31 +0200] "GET /forums/showthread.php?t=15338 HTTP/1.0" 200 59342 "https://www.howtoforge.com/forums/search.php?searchid=624841" "Wget/1.10.2"
24.127.251.14 - - [17/Oct/2007:18:50:33 +0200] "POST /mailgust/index.php HTTP/1.1" 200 1662 "https://www.howtoforge.com/mailgust/index.php?method=login_form&list=maillistuser" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.30)"
72.149.148.248 - - [17/Oct/2007:18:50:35 +0200] "GET /images/print.gif HTTP/1.1" 200 217 "https://www.howtoforge.com/the_perfect_desktop_mandriva_2008.0" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
192.6.178.101 - - [17/Oct/2007:18:50:37 +0200] "GET /themes/htf_glass/images/howtoforge_logo_trans.gif HTTP/1.0" 200 184 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
76.22.105.74 - - [17/Oct/2007:18:50:39 +0200] "GET /themes/htf_glass/images/search_small.gif HTTP/1.1" 200 1367 "https://www.howtoforge.com/the_perfect_desktop_mandriva_2008.0" "Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko) (Debian)"
192.6.178.101 - - [17/Oct/2007:18:50:41 +0200] "GET /themes/htf_glass/images/join_small.gif HTTP/1.0" 200 1212 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
192.6.178.101 - - [17/Oct/2007:18:50:43 +0200] "GET /forums/clientscript/vbulletin_md5.js HTTP/1.0" 200 9661 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
24.127.251.14 - - [17/Oct/2007:18:50:45 +0200] "GET /mailgust/i/menushadow.gif HTTP/1.1" 200 59 "https://www.howtoforge.com/mailgust/index.php" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.30)"

/var/log/webcluster/access_log_server2는 다음과 같습니다:

cat /var/log/webcluster/access_log_server2
192.6.178.101 - - [17/Oct/2007:18:50:28 +0200] "GET /themes/htf_glass/images/header_tab6.png HTTP/1.0" 200 7434 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
72.149.148.248 - - [17/Oct/2007:18:50:30 +0200] "GET /misc/menu-leaf.png HTTP/1.1" 200 108 "https://www.howtoforge.com/the_perfect_desktop_mandriva_2008.0" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
24.8.231.74 - - [17/Oct/2007:18:50:32 +0200] "GET /forums/showthread.php?t=15338 HTTP/1.0" 200 59342 "https://www.howtoforge.com/forums/search.php?searchid=624841" "Wget/1.10.2"
24.127.251.14 - - [17/Oct/2007:18:50:34 +0200] "POST /mailgust/index.php HTTP/1.1" 200 1662 "https://www.howtoforge.com/mailgust/index.php?method=login_form&list=maillistuser" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.30)"
72.149.148.248 - - [17/Oct/2007:18:50:36 +0200] "GET /images/print.gif HTTP/1.1" 200 217 "https://www.howtoforge.com/the_perfect_desktop_mandriva_2008.0" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
192.6.178.101 - - [17/Oct/2007:18:50:38 +0200] "GET /themes/htf_glass/images/howtoforge_logo_trans.gif HTTP/1.0" 200 184 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
76.22.105.74 - - [17/Oct/2007:18:50:40 +0200] "GET /themes/htf_glass/images/search_small.gif HTTP/1.1" 200 1367 "https://www.howtoforge.com/the_perfect_desktop_mandriva_2008.0" "Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko) (Debian)"
192.6.178.101 - - [17/Oct/2007:18:50:42 +0200] "GET /themes/htf_glass/images/join_small.gif HTTP/1.0" 200 1212 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
192.6.178.101 - - [17/Oct/2007:18:50:44 +0200] "GET /forums/clientscript/vbulletin_md5.js HTTP/1.0" 200 9661 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
24.127.251.14 - - [17/Oct/2007:18:50:46 +0200] "GET /mailgust/i/menushadow.gif HTTP/1.1" 200 59 "https://www.howtoforge.com/mailgust/index.php" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.30)"

두 액세스 로그를 전체 액세스 로그 /var/log/webcluster/access_log_overall로 병합하려면 다음을 실행합니다:

logresolvemerge.pl /var/log/webcluster/access_log_server* > /var/log/webcluster/access_log_overall

다음과 같은 오류 메시지가 표시되면:

server1:~# logresolvemerge.pl /var/log/webcluster/access_log_server* > /var/log/webcluster/access_log_overall
-bash: /usr/local/bin/logresolvemerge.pl: /usr/bin/perl^M: bad interpreter: No such file or directory
server1:~#

이는 logresolvemerge.pl에 Windows 줄바꿈이 포함되어 있음을 의미합니다. 이를 수정하기 위해, Debian의 sysutils 패키지의 일부인 도구 dos2unix를 사용하여 Unix 줄바꿈으로 변환할 수 있습니다. 따라서 지금 sysutils 패키지를 설치합니다:

apt-get install sysutils

그 후, logresolvemerge.pl 스크립트를 수정합니다:

dos2unix /usr/local/bin/logresolvemerge.pl /usr/local/bin/logresolvemerge.pl

이제 다음을 실행할 수 있습니다:

logresolvemerge.pl /var/log/webcluster/access_log_server* > /var/log/webcluster/access_log_overall

다시 실행하면 이번에는 오류가 없어야 합니다.

(와일드카드를 사용하고 싶지 않다면, 각 액세스 로그를 지정하여 logresolvemerge.pl을 다음과 같이 사용할 수 있습니다:

logresolvemerge.pl /var/log/webcluster/access_log_server1 /var/log/webcluster/access_log_server2 > /var/log/webcluster/access_log_overall

)

이제 전체 액세스 로그 /var/log/webcluster/access_log_overall이 있어야 하며, 여기에는 /var/log/webcluster/access_log_server1 및 /var/log/webcluster/access_log_server2의 요청이 시간 순서대로 포함되어야 합니다:

cat /var/log/webcluster/access_log_overall 
192.6.178.101 - - [17/Oct/2007:18:50:27 +0200] "GET /themes/htf_glass/images/header_tab6.png HTTP/1.0" 200 7434 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
192.6.178.101 - - [17/Oct/2007:18:50:28 +0200] "GET /themes/htf_glass/images/header_tab6.png HTTP/1.0" 200 7434 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
72.149.148.248 - - [17/Oct/2007:18:50:29 +0200] "GET /misc/menu-leaf.png HTTP/1.1" 200 108 "https://www.howtoforge.com/the_perfect_desktop_mandriva_2008.0" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
72.149.148.248 - - [17/Oct/2007:18:50:30 +0200] "GET /misc/menu-leaf.png HTTP/1.1" 200 108 "https://www.howtoforge.com/the_perfect_desktop_mandriva_2008.0" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
24.8.231.74 - - [17/Oct/2007:18:50:31 +0200] "GET /forums/showthread.php?t=15338 HTTP/1.0" 200 59342 "https://www.howtoforge.com/forums/search.php?searchid=624841" "Wget/1.10.2"
24.8.231.74 - - [17/Oct/2007:18:50:32 +0200] "GET /forums/showthread.php?t=15338 HTTP/1.0" 200 59342 "https://www.howtoforge.com/forums/search.php?searchid=624841" "Wget/1.10.2"
24.127.251.14 - - [17/Oct/2007:18:50:33 +0200] "POST /mailgust/index.php HTTP/1.1" 200 1662 "https://www.howtoforge.com/mailgust/index.php?method=login_form&list=maillistuser" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.30)"
24.127.251.14 - - [17/Oct/2007:18:50:34 +0200] "POST /mailgust/index.php HTTP/1.1" 200 1662 "https://www.howtoforge.com/mailgust/index.php?method=login_form&list=maillistuser" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.30)"
72.149.148.248 - - [17/Oct/2007:18:50:35 +0200] "GET /images/print.gif HTTP/1.1" 200 217 "https://www.howtoforge.com/the_perfect_desktop_mandriva_2008.0" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
72.149.148.248 - - [17/Oct/2007:18:50:36 +0200] "GET /images/print.gif HTTP/1.1" 200 217 "https://www.howtoforge.com/the_perfect_desktop_mandriva_2008.0" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
192.6.178.101 - - [17/Oct/2007:18:50:37 +0200] "GET /themes/htf_glass/images/howtoforge_logo_trans.gif HTTP/1.0" 200 184 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
192.6.178.101 - - [17/Oct/2007:18:50:38 +0200] "GET /themes/htf_glass/images/howtoforge_logo_trans.gif HTTP/1.0" 200 184 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
76.22.105.74 - - [17/Oct/2007:18:50:39 +0200] "GET /themes/htf_glass/images/search_small.gif HTTP/1.1" 200 1367 "https://www.howtoforge.com/the_perfect_desktop_mandriva_2008.0" "Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko) (Debian)"
76.22.105.74 - - [17/Oct/2007:18:50:40 +0200] "GET /themes/htf_glass/images/search_small.gif HTTP/1.1" 200 1367 "https://www.howtoforge.com/the_perfect_desktop_mandriva_2008.0" "Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko) (Debian)"
192.6.178.101 - - [17/Oct/2007:18:50:41 +0200] "GET /themes/htf_glass/images/join_small.gif HTTP/1.0" 200 1212 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
192.6.178.101 - - [17/Oct/2007:18:50:42 +0200] "GET /themes/htf_glass/images/join_small.gif HTTP/1.0" 200 1212 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
192.6.178.101 - - [17/Oct/2007:18:50:43 +0200] "GET /forums/clientscript/vbulletin_md5.js HTTP/1.0" 200 9661 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
192.6.178.101 - - [17/Oct/2007:18:50:44 +0200] "GET /forums/clientscript/vbulletin_md5.js HTTP/1.0" 200 9661 "https://www.howtoforge.com/data_recovery_with_testdisk" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)"
24.127.251.14 - - [17/Oct/2007:18:50:45 +0200] "GET /mailgust/i/menushadow.gif HTTP/1.1" 200 59 "https://www.howtoforge.com/mailgust/index.php" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.30)"
24.127.251.14 - - [17/Oct/2007:18:50:46 +0200] "GET /mailgust/i/menushadow.gif HTTP/1.1" 200 59 "https://www.howtoforge.com/mailgust/index.php" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.30)"

4 logresolvemerge.pl에 대한 크론 작업 생성하기

물론, 매일 logresolvemerge.pl을 수동으로 실행하고 싶지는 않을 것입니다. 따라서 지금 크론 작업을 생성합니다:

crontab -e

매일 밤 4:00에 logresolvemerge.pl을 실행하고 싶다면, 크론 작업은 다음과 같을 수 있습니다 (시간을 필요에 맞게 조정하십시오):

| 0 4 * * * /usr/local/bin/logresolvemerge.pl /var/log/webcluster/access_log_server* > /var/log/webcluster/access_log_overall |

5 링크

Share: X/Twitter LinkedIn

새 게시물을 받은 편지함에서 받기

스팸은 없습니다. 언제든지 구독 해지 가능합니다.