Server Erweiterung · 8 min read · Dec 02, 2025
Erweiterung des Perfect Servers - Debian Squeeze [ISPConfig 3] - Seite 4
9. Jederzeit Statistiken mit awstats
In diesem Abschnitt können Sie eine Modifikation anwenden, die es Ihnen ermöglicht, die awstats jederzeit zu aktualisieren, oder (durch Verwendung von cron) in häufigeren Zeitintervallen. Bevor wir fortfahren, müssen wir das Standardprotokollformat für awstats ändern. In Debian Squeeze ist das Standardformat 4, aber wir benötigen das 1. Sie können entweder die Datei /etc/awstats/awstats.conf oder die Datei /etc/awstats/awstats.conf.local bearbeiten. Ich bevorzuge die zweite, da sie es mir ermöglicht, mit Updates Schritt zu halten:
nano /etc/awstats/awstats.conf.localund fügen Sie die Zeile hinzu: LogFormat=1
Danach sollte die Datei folgendermaßen aussehen:
# Sie können Konfigurationsanweisungen hier überschreiben.
# Dies ist besonders nützlich für Benutzer mit mehreren Konfigurationen für
# verschiedene virtuelle Server, die gemeinsame Parameter wiederverwenden möchten.
# Außerdem wird diese Datei nicht mit jeder neuen upstream-Version aktualisiert.
LogFormat=1Jetzt müssen wir den Standard-Tagescron von ISPConfig kopieren und bearbeiten … tatsächlich müssen wir ihn SEHR VIEL bearbeiten (neuer Dateiname: mycron.php). Grundsätzlich müssen wir viele Zeilen abschneiden und nur einige von ihnen behalten. Machen Sie:
cp /usr/local/ispconfig/server/cron_daily.php /root/scripts/mycron.php
chmod 700 /root/scripts/mycron.php
nano /root/scripts/mycron.php
und fügen Sie alle folgenden Zeilen ein:
uses('ini_parser,file,services,getconf');
#######################################################################################################
// Erstellen Sie awstats-Statistiken
#######################################################################################################
$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE stats_type = 'awstats' AND server_id = ".$conf['server_id'];
$records = $app->db->queryAllRecords($sql);
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
foreach($records as $rec) {
$logfile = escapeshellcmd($rec['document_root'].'/log/access.log');
$domain = escapeshellcmd($rec['domain']);
$statsdir = escapeshellcmd($rec['document_root'].'/web/stats');
$awstats_pl = $web_config['awstats_pl'];
$awstats_buildstaticpages_pl = $web_config['awstats_buildstaticpages_pl'];
$awstats_conf_dir = $web_config['awstats_conf_dir'];
$awstats_website_conf_file = $web_config['awstats_conf_dir'].'/awstats.'.$domain.'.conf';
if(is_file($awstats_website_conf_file)) unlink($awstats_website_conf_file);
if(!is_file($awstats_website_conf_file)) {
$awstats_conf_file_content = 'Include "'.$awstats_conf_dir.'/awstats.conf"
LogFile="/var/log/ispconfig/httpd/'.$domain.'/access.log"
SiteDomain="'.$domain.'"
HostAliases="www.'.$domain.' localhost 127.0.0.1"';
file_put_contents($awstats_website_conf_file,$awstats_conf_file_content);
}
if(!@is_dir($statsdir)) mkdir($statsdir);
// awstats_buildstaticpages.pl -update -config=mydomain.com -lang=en -dir=/var/www/domain.com/web/stats -awstatsprog=/path/to/awstats.pl
$command = "$awstats_buildstaticpages_pl -update -config='$domain' -lang=en -dir='$statsdir' -awstatsprog='$awstats_pl'";
if($awstats_pl != '' && $awstats_buildstaticpages_pl != '' && fileowner($awstats_pl) == 0 && fileowner($awstats_buildstaticpages_pl) == 0) {
exec($command);
rename($rec['document_root'].'/web/stats/awstats.'.$domain.'.html',$rec['document_root'].'/web/stats/index.html');
$app->log('Erstellte awstats-Statistiken mit dem Befehl: '.$command,LOGLEVEL_DEBUG);
} else {
$app->log("Keine awstats-Statistiken erstellt. Entweder $awstats_pl oder $awstats_buildstaticpages_pl gehört nicht dem root-Benutzer.",LOGLEVEL_WARN);
}
}
die("fertig.
");
?>Dieses Skript ist ein Ausschnitt der Standard-Cron-Datei von ISPConfig und gilt bis ISPConfig 3.0.3. Es wurde von Till Brehm erstellt, und wir haben es bearbeitet, sodass das Update-Verfahren KEINE System- (oder Protokoll-) Datei ändert, wann immer wir es aufrufen. Einfach ausgedrückt, liest das Skript die access.log-Datei jeder Domain und führt KEINE Rotation oder Modifikation durch, außer dass es die HTML-Dateien für awstats reproduziert. Beachten Sie, dass der Standard-Cron-Job von ISPConfig wie gewohnt um 00:30 Uhr ausgeführt wird und einfach die Stats-Datenbank ergänzt und die HTML-Dateien neu erstellt.
Im obigen Skript können Sie die Sprache, die von awstats erzeugt wird, ändern, indem Sie einfach die Buchstaben nach “lang=” durch die Buchstaben ersetzen, die Ihr Land repräsentieren.
Für ISPConfig 3.0.4 verwenden Sie bitte den folgenden Code:
uses('ini_parser,file,services,getconf');
#######################################################################################################
// Erstellen Sie awstats-Statistiken
#######################################################################################################
$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE stats_type = 'awstats' AND server_id = ".$conf['server_id'];
$records = $app->db->queryAllRecords($sql);
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
foreach($records as $rec) {
$logfile = escapeshellcmd($rec['document_root'].'/log/access.log');
$domain = escapeshellcmd($rec['domain']);
$statsdir = escapeshellcmd($rec['document_root'].'/web/stats');
$awstats_pl = $web_config['awstats_pl'];
$awstats_buildstaticpages_pl = $web_config['awstats_buildstaticpages_pl'];
$awstats_conf_dir = $web_config['awstats_conf_dir'];
$awstats_website_conf_file = $web_config['awstats_conf_dir'].'/awstats.'.$domain.'.conf';
if(is_file($awstats_website_conf_file)) unlink($awstats_website_conf_file);
$sql = "SELECT domain FROM web_domain WHERE (type = 'alias' OR AND type = 'subdomain') server_id = ".$conf['server_id'];
$aliases = $app->db->queryAllRecords($sql);
$aliasdomain = '';
if(is_array($aliases)) {
foreach ($aliases as $alias) {
$aliasdomain.= ' '.$alias['domain']. ' www.'.$alias['domain'];
}
}
if(!is_file($awstats_website_conf_file)) {
$awstats_conf_file_content = 'Include "'.$awstats_conf_dir.'/awstats.conf"
LogFile="/var/log/ispconfig/httpd/'.$domain.'/access.log"
SiteDomain="'.$domain.'"
HostAliases="www.'.$domain.' localhost 127.0.0.1"'.$aliasdomain;
file_put_contents($awstats_website_conf_file,$awstats_conf_file_content);
}
if(!@is_dir($statsdir)) mkdir($statsdir);
####################################################################################
######################### STATISTIKEN NEU ERSTELLEN ###########################################
$redo = 0; // setzen Sie dies auf 1, wenn Sie Statistiken für einen bestimmten Monat neu erstellen möchten
$REMONTH = 11; // wählen Sie den Monat
$REYEAR = 2011; // wählen Sie das Jahr
$LANG = 'gr'; // setzen Sie Ihre Sprache
// Nach dem Setzen der oben genannten, führen Sie dieses Skript erneut aus
// z.B.
// php /path/to
####################################################################################
####################################################################################
if ( $redo == 1 ) {
$awmonth = $REMONTH;
$awyear = $REYEAR;
$statsdirold = $statsdir."/".$awyear."-".$awmonth."/";
if (!is_dir($statsdirold)) {
mkdir($statsdirold);
}
$command = "$awstats_buildstaticpages_pl -month='$awmonth' -year='$awyear' -update -config='$domain' -lang='$LANG' -dir='$statsdirold' -awstatsprog='$awstats_pl'";
if($awstats_pl != '' && $awstats_buildstaticpages_pl != '' && fileowner($awstats_pl) == 0 && fileowner($awstats_buildstaticpages_pl) == 0) {
exec($command);
rename($statsdirold.'awstats.'.$domain.'.html',$statsdirold.'awsindex.html');
$app->log('Erstellte awstats-Statistiken mit dem Befehl: '.$command,LOGLEVEL_DEBUG);
} else {
$app->log("Keine awstats-Statistiken erstellt. Entweder $awstats_pl oder $awstats_buildstaticpages_pl gehört nicht dem root-Benutzer.",LOGLEVEL_WARN);
}
}
else {
if (date("d") == 1) {
$awmonth = date("n")-1;
$awyear = date("Y");
if (date("n") == 0) {
$awyear = date("Y")-1;
$awmonth = "12";
}
$statsdirold = $statsdir."/".$awyear."-".$awmonth."/";
if (!is_dir($statsdirold)) {
mkdir($statsdirold);
$command = "$awstats_buildstaticpages_pl -month='$awmonth' -year='$awyear' -update -config='$domain' -lang='$LANG' -dir='$statsdirold' -awstatsprog='$awstats_pl'";
if($awstats_pl != '' && $awstats_buildstaticpages_pl != '' && fileowner($awstats_pl) == 0 && fileowner($awstats_buildstaticpages_pl) == 0) {
exec($command);
rename($statsdirold.'awstats.'.$domain.'.html',$statsdirold.'awsindex.html');
$app->log('Erstellte awstats-Statistiken mit dem Befehl: '.$command,LOGLEVEL_DEBUG);
} else {
$app->log("Keine awstats-Statistiken erstellt. Entweder $awstats_pl oder $awstats_buildstaticpages_pl gehört nicht dem root-Benutzer.",LOGLEVEL_WARN);
}
}
}
// ispconfig überschreibt am zweiten Tag des Monats die zuvor von diesem Skript erstellten Statistiken
// um die Standardausführung von ispconfig am 2. Tag des Monats zu überschreiben, müssen wir den folgenden Code ausführen
if (date("d") == 2) {
$awmonth = date("n")-1;
$awyear = date("Y");
if (date("n") == 0) {
$awyear = date("Y")-1;
$awmonth = "12";
}
$statsdirold = $statsdir."/".$awyear."-".$awmonth."/";
$command = "$awstats_buildstaticpages_pl -month='$awmonth' -year='$awyear' -update -config='$domain' -lang='$LANG' -dir='$statsdirold' -awstatsprog='$awstats_pl'";
if($awstats_pl != '' && $awstats_buildstaticpages_pl != '' && fileowner($awstats_pl) == 0 && fileowner($awstats_buildstaticpages_pl) == 0) {
exec($command);
rename($statsdirold.'awstats.'.$domain.'.html',$statsdirold.'awsindex.html');
$app->log('Erstellte awstats-Statistiken mit dem Befehl: '.$command,LOGLEVEL_DEBUG);
} else {
$app->log("Keine awstats-Statistiken erstellt. Entweder $awstats_pl oder $awstats_buildstaticpages_pl gehört nicht dem root-Benutzer.",LOGLEVEL_WARN);
}
}
// Ende der Überschreibung
// Leider wird das oben genannte viele Male ausgeführt (so oft, wie Sie dieses Skript über cron ausführen)
$awmonth = date("n");
$awyear = date("Y");
$command = "$awstats_buildstaticpages_pl -month='$awmonth' -year='$awyear' -update -config='$domain' -lang='$LANG' -dir='$statsdir' -awstatsprog='$awstats_pl'";
if($awstats_pl != '' && $awstats_buildstaticpages_pl != '' && fileowner($awstats_pl) == 0 && fileowner($awstats_buildstaticpages_pl) == 0) {
exec($command);
if(is_file($rec['document_root'].'/web/stats/index.html')) unlink($rec['document_root'].'/web/stats/index.html');
rename($rec['document_root'].'/web/stats/awstats.'.$domain.'.html',$rec['document_root'].'/web/stats/awsindex.html');
if(!is_file($rec['document_root'].'/web/stats/index.php')) copy("/usr/local/ispconfig/server/conf/awstats_index.php.master",$rec['document_root'].'/web/stats/index.php');
$app->log('Erstellte awstats-Statistiken mit dem Befehl: '.$command,LOGLEVEL_DEBUG);
} else {
$app->log("Keine awstats-Statistiken erstellt. Entweder $awstats_pl oder $awstats_buildstaticpages_pl gehört nicht dem root-Benutzer.",LOGLEVEL_WARN);
}
} // Ende redo
} // Ende foreach
die("fertig.
");
?>
Beachten Sie (in Version > =3.0.4), dass Sie am ersten Tag jedes Monats keine Statistiken sehen werden (wie mit dem normalen Skript). Wenn Sie die aktualisierten Statistiken nach der ersten Ausführung am ersten Tag des Monats sehen möchten, müssen Sie diesen Beitrag lesen: https://www.howtoforge.com/forums/showthread.php?p=270816#post270816
Um das Skript alle 4 Stunden auszuführen, erstellen Sie zunächst die Datei /root/scripts/mycron.sh, machen Sie sie ausführbar und fügen Sie sie dann zur Cronjob-Liste hinzu:
touch /root/scripts/mycron.sh
chmod 700 /root/scripts/mycron.sh
nano /root/scripts/mycron.sh
und fügen Sie Folgendes ein:
#!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin
/usr/bin/php /root/scripts/mycron.phpFügen Sie den Cronjob hinzu:
crontab -eFügen Sie die folgende Zeile hinzu, speichern Sie und beenden Sie:
45 0,4,8,12,16,20 * * * /root/scripts/mycron.shSie können auch jederzeit die Erstellung der Statistiken initiieren durch:
/root/scripts/mycron.shSie können Statistiken von vorherigen Monaten neu erstellen (solange Daten in /var/lib/awstats oder /var/cache/awstats vorhanden sind). Lesen Sie die Kommentare im Skript, setzen Sie redo=1 und führen Sie das Skript aus. Mehr dazu unter https://www.howtoforge.com/forums/showthread.php?t=51731
10. MySQL-Tuning
Laden Sie tuning-primer.sh und mysqltuner.pl herunter. Diese helfen Ihnen, die Konfigurationsdatei von MySQL zu verbessern.
cd /root/scripts
wget http://www.day32.com/MySQL/tuning-primer.sh
wget http://mysqltuner.com/mysqltuner.pl
chmod 700 tuning-primer.sh mysqltuner.pl
Um sie auszuführen:
perl /root/scripts/mysqltuner.pl
/root/scripts/tuning-primer.sh
Die Skripte stellen einige einfache Fragen (Benutzer/Passwort) und zeigen in roter Farbe ihre Vorschläge für kritische Einstellungen an. Sie können ihre Vorschläge verwenden, um die Leistung des MySQL-Servers zu steigern.
Erhalte neue Beiträge in deinem Posteingang.
Kein Spam. Jederzeit abmelden.