Apache Logs · 8 min read · Jan 27, 2026

Fusionner plusieurs journaux d'accès Apache en un seul journal d'accès global

Fusionner plusieurs journaux d’accès Apache en un seul journal d’accès global

Version 1.0
Auteur : Falko Timme

Supposons que vous ayez une application web qui fonctionne sur un cluster de nœuds Apache. Chaque nœud génère son propre journal d’accès Apache à partir duquel vous pouvez générer des statistiques de vues de pages avec des outils tels que Webalizer ou AWStats. Évidemment, vous ne voulez pas avoir de statistiques de vues de pages pour chaque nœud Apache, mais des statistiques de vues de pages globales. Pour y parvenir, nous devons fusionner les journaux d’accès de chaque nœud en un seul journal d’accès global que nous pourrons ensuite alimenter dans Webalizer ou AWStats. Il existe un script Perl appelé logresolvemerge.pl (partie du package AWStats) qui peut faire cela pour nous.

Je ne donne aucune garantie que cela fonctionnera pour vous !

1 Remarque préliminaire

J’ai testé cela sur un système Debian, mais la procédure est la même sur toutes les autres distributions, sauf pour l’installation des packages. Utilisez le gestionnaire de packages de votre distribution (par exemple, apt, yum, yast, urpmi) pour installer les packages.

Je suppose que vous utilisez un seul hôte (typiquement, c’est l’hôte où vous exécutez Webalizer ou AWStats pour générer les statistiques) pour collecter les journaux d’accès des nœuds Apache (je ne couvre pas comment transférer les journaux d’accès des nœuds Apache vers l’hôte où nous collectons les journaux - vous pourriez le faire avec rsync, par exemple, comme montré dans ce tutoriel : Miroir votre site web avec rsync) - j’utilise le répertoire /var/log/webcluster ici pour stocker les journaux d’accès des nœuds Apache.

2 Installation de logresolvemerge.pl

Comme je l’ai dit précédemment, logresolvemerge.pl fait partie du package AWStats, donc nous l’installons maintenant (même si vous ne voulez pas l’utiliser - vous pouvez toujours utiliser Webalizer si vous le souhaitez) :

apt-get install awstats

logresolvemerge.pl est maintenant situé dans le répertoire /usr/share/doc/awstats/examples. Déplaçons-le vers /usr/local/bin afin qu’il soit dans notre PATH :

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

(Si vous ne trouvez pas votre logresolvemerge.pl, vous pouvez le rechercher comme ceci :

updatedb
locate logresolvemerge.pl

et ensuite le déplacer vers /usr/local/bin.)

3 Utilisation de logresolvemerge.pl

Supposons que nous ayons deux journaux d’accès dans /var/log/webcluster, /var/log/webcluster/access_log_server1 et /var/log/webcluster/access_log_server2.

J’utilise ici deux journaux d’accès d’exemple pour démontrer comment logresolvemerge.pl fonctionne. Les deux journaux d’accès contiennent les mêmes données à des fins de démonstration, mais les dates des requêtes diffèrent d’une seconde sur server1 et server2. Après avoir fusionné les deux journaux avec logresolvemerge.pl, le journal d’accès global devrait contenir les requêtes dans l’ordre chronologique afin que Webalizer et AWStats puissent les traiter correctement.

/var/log/webcluster/access_log_server1 ressemble à ceci :

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 ressemble à ceci :

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)"

Pour fusionner les deux journaux d’accès en le journal d’accès global /var/log/webcluster/access_log_overall, nous exécutons :

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

Si vous obtenez un message d’erreur comme ceci :

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: mauvais interpréteur : Aucun fichier ou répertoire de ce type
server1:~#

cela signifie que logresolvemerge.pl contient des sauts de ligne Windows. Pour corriger cela, nous pouvons les convertir en sauts de ligne Unix avec l’outil dos2unix qui fait partie du package sysutils sur Debian. Par conséquent, nous installons maintenant le package sysutils :

apt-get install sysutils

Ensuite, nous corrigeons le script logresolvemerge.pl :

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

Maintenant, vous pouvez exécuter

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

à nouveau, et cette fois il ne devrait y avoir aucune erreur.

(Si vous ne voulez pas utiliser de caractères génériques, mais spécifier chaque journal d’accès, vous pouvez utiliser logresolvemerge.pl comme ceci avec le même résultat :

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

)

Maintenant, vous devriez avoir un journal d’accès global, /var/log/webcluster/access_log_overall, qui devrait contenir les requêtes de /var/log/webcluster/access_log_server1 et /var/log/webcluster/access_log_server2 dans l’ordre chronologique :

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 Création d’un job cron pour logresolvemerge.pl

Bien sûr, vous ne voulez pas exécuter logresolvemerge.pl manuellement chaque jour ; par conséquent, nous créons un job cron dès maintenant :

crontab -e

Si vous souhaitez exécuter logresolvemerge.pl chaque nuit à 4h00, votre job cron pourrait ressembler à ceci (ajustez l’heure selon vos besoins) :

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

5 Liens

Share: X/Twitter LinkedIn

Recevez de nouveaux articles dans votre boîte de réception.

Aucun spam. Désabonnez-vous à tout moment.