Apacheログ · 5 min read · Jan 27, 2026
複数のApacheアクセスログを1つの全体アクセスログに統合する
複数のApacheアクセスログを1つの全体アクセスログに統合する
バージョン 1.0
著者: Falko Timme
ウェブアプリケーションがApacheノードのクラスターで動作していると仮定しましょう。各ノードは独自のApacheアクセスログを生成し、WebalizerやAWStatsなどのツールを使用してページビュー統計を生成できます。明らかに、各Apacheノードのページビュー統計を持ちたくはなく、全体のページビュー統計が必要です。これを達成するためには、各ノードのアクセスログを1つの全体アクセスログに統合し、それをWebalizerやAWStatsに供給する必要があります。これを行うためのPerlスクリプトlogresolvemerge.pl(AWStatsパッケージの一部)があります。
これがあなたにとって機能することを保証するものではありません!
1 前提条件
私はこれをDebianシステムでテストしましたが、手順は他のディストリビューションでも同じです(パッケージのインストールを除いて)。ディストリビューションのパッケージマネージャ(例: apt, yum, yast, urpmi)を使用してパッケージをインストールしてください。
私は、Apacheノードからアクセスログを収集するために、単一のホスト(通常、統計を生成するためにWebalizerまたはAWStatsを実行するホスト)を使用していると仮定しています(Apacheノードからログを収集するホストへのアクセスログの転送方法はカバーしません - 例えば、rsyncを使用して行うことができます。このチュートリアルに示されているように: Mirror Your Web Site With rsync) - ここでは、Apacheノードのアクセスログを保存するためにディレクトリ/var/log/webclusterを使用しています。
2 logresolvemerge.plのインストール
前述のように、logresolvemerge.plはAWStatsパッケージの一部なので、今すぐインストールします(使用したくない場合でも - Webalizerを使用することもできます):
apt-get install awstatslogresolvemerge.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に2つのアクセスログ、/var/log/webcluster/access_log_server1と/var/log/webcluster/access_log_server2があると仮定しましょう。
ここでは、logresolvemerge.plがどのように機能するかを示すために2つのサンプルアクセスログを使用しています。両方のアクセスログはデモンストレーションの目的で同じデータを含んでいますが、サーバー1とサーバー2のリクエストの日付は1秒異なります。両方のログをlogresolvemerge.plでマージした後、全体のアクセスログには、WebalizerとAWStatsが正しく処理できるように、リクエストが時系列順に含まれている必要があります。
/var/log/webcluster/access_log_server1は次のようになります:
cat /var/log/webcluster/access_log_server1192.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_server2192.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のためのCronジョブの作成
もちろん、毎日手動でlogresolvemerge.plを実行したくはないので、今すぐCronジョブを作成します:
crontab -e毎晩4:00にlogresolvemerge.plを実行したい場合、あなたのCronジョブは次のようになります(時間は必要に応じて調整してください):
| 0 4 * * * /usr/local/bin/logresolvemerge.pl /var/log/webcluster/access_log_server* > /var/log/webcluster/access_log_overall |
5 リンク
- AWStats: http://awstats.sourceforge.net
- Webalizer: http://www.mrunix.net/webalizer
- Debian: http://www.debian.org
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。