ตัวอย่างสร้างแสดงผลของ web server ดังนี้
sudo cp /etc/awstats/awstats.conf /etc/awstats/awstats.mydomain.conf
แก้ไข/ปรับปรุงแฟ้ม /etc/awstats/awstats.mydomain.conf ให้มีค่าตัวแปรประมาณว่า
LogFile="/var/log/apache2/access.log"
LogFormat=4
SiteDomain="your.domain"
HostAliases="localhost 127.0.0.1"
สร้างแฟ้ม /etc/apache2/conf.d/awstats ให้มีข้อมูลว่า
Alias /awstatsclasses "/usr/share/awstats/lib/"
Alias /awstats-icon/ "/usr/share/awstats/icon/"
Alias /awstatscss "/usr/share/doc/awstats/examples/css"
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ScriptAlias /awstats/ /usr/lib/cgi-bin/
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
สั่งให้เริ่มประมวลผลสถิติข้อมูลด้วยคำสั่ง sudo /usr/lib/cgi-bin/awstats.pl -config=mydomain -update
จะได้ข้อความแสดงผลประมาณว่า
Create/Update database for config "/etc/awstats/awstats.mydomain.conf" by AWStats version 6.7 (build 1.892)
From data in log file "/var/log/apache2/access.log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 1223
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 1223 new qualified records.
แสดงว่า awstats ทำงานได้แล้ว
ดูผลงานบนเวบได้ที่ http://your.domain/awstats/awstats.pl?config=mydomain
ต่อไปสั่งให้ระบบประมวลผลสถิติอัตโนมัติ
แก้ไขแฟ้ม /etc/cron.d/awstats ให้เป็นประมาณว่า
*/10 * * * * root /usr/lib/cgi-bin/awstats.pl -config=mydomain -update > /dev/null
แล้วสังให้ cron ทำงานใหม่ด้วยคำสั่ง sudo /etc/init.d/cron reload
------------------------------------------------------------------------------------------------------------------
เพิ่มเติม by wisit 4-11-57
สำหรับ ubuntu 12.04 , 14.04 ติดตั้งตามนี้ https://help.ubuntu.com/community/AWStats
ต้องการติดตั้งแบบรวดเร็ว script สำหรับ install awstats download scripts ได้ที่ ftp://ftp.psu.ac.th/pub/psu12-sritrang/download/scripts-pom/installawstats.sh
วิธีการใช้งาน
เปลี่ยนสิทธิ์เป็น root
sudo su -
download script
แล้ว run script
bash installawstats.sh
รอจนเสร็จ
ดูผลงานได้ที่ http://xx.xx.xx.xx/awstats/awstats.pl (xx.xx.xx.xx = ip server ที่ติดตั้ง awstats)
เพิ่มข้อความใน crontab -e ดังนี้ 0 * * * * /usr/lib/cgi-bin/awstats.pl -config=xx.xx.xx.xx -update > /dev/nullขอบคุณครับ
รายละเอียด script
#pom 4-11-57
sudo apt-get install awstats -y
MYIP=$(ifconfig eth0|grep -w "inet"|awk '{print $2}'|cut -d':' -f 2)
FILE1=/etc/awstats/awstats.${MYIP}.conf
sudo cp /etc/awstats/awstats.conf $FILE1
sudo sed -i '/SiteDomain=/ c SiteDomain="'${MYIP}'"' $FILE1
sudo sed -i '/HostAliases=/ c HostAliases="localhost 127.0.0.1 '${MYIP}'"'
sudo /usr/lib/cgi-bin/awstats.pl -config=${MYIP} -update
sudo a2enmod cgi
FILE2=/etc/apache2/sites-available/000-default.conf #14.04
FILE3=/etc/apache2/sites-available/default #12.04
sudo cp ${FILE2} ${HOME}
sudo cp ${FILE3} ${HOME}
FILE4=myfile.txt
sudo cat > ${FILE4} <<EOF
Alias /awstatsclasses "/usr/share/awstats/lib/"
Alias /awstats-icon "/usr/share/awstats/icon/"
Alias /awstatscss "/usr/share/doc/awstats/examples/css"
ScriptAlias /awstats/ /usr/lib/cgi-bin/
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
EOF
for i in ${FILE2} ${FILE3}
do
line1=$(grep -n '/VirtualHost' $i | cut -d\: -f1)
line2=$(expr $line1 - 1)
sed -i $line2' r '${FILE4} $i
done
sudo service apache2 restart
echo "----------------------------"
echo "add to crontab => 0 * * * * /usr/lib/cgi-bin/awstats.pl -config=${MYIP} -update > /dev/null"
echo "----------------------------"