Monday, February 19, 2007

awstats ดู Log mail บน Mail Server

วันนี้มาพูดถึงวิธีการดู Logmail บน Mail server กันโดยใชโปรกแกรม awstats วิธีการทำก็ตามเว็บไซต์นี้เลยครับ
1. http://www.thaiadmin.org/board/index.php?topic=48756.msg211233#msg211233
2. การตั้งเวลาใน crontab http://www.ubuntuclub.com/html/index.php?option=com_content&task=view&id=466&Itemid=55

ซึ่งจะต้องมีการแก้ไขนิดหน่อย ดังนี้

897 wget http://jaist.dl.sourceforge.net/sourceforge/awstats/awstats-6.5-1.noarch.rpm
899 rpm -ivh awstats-6.5-1.noarch.rpm
905 vi /etc/awstats/awstats.crisgo.conf *****create file*****
908 ls
909 w
910 vi /usr/local/bin/awstats.updates *****create file*****
911 ls
912 chmod ug+x /usr/local/bin/awstats.updates
913 mkdir /home/crisgo/awstats
914 /usr/local/bin/awstats.updates
915 cd /home/crisgo/awstats
920 cd /usr/local/awstats/wwwroot/
922 cd icon/
924 cd clock/
926 date
927 cd /home/crisgo/awstats
929 ls
930 cd /usr/local/awstats/wwwroot/
931 cp -a icon /home/crisgo/awstats
932 cd icon/
933 cd
934 cd /home/crisgo/awstats
935 ls
938 cd icon/
939 ls
940 ls -la
941 cd other/
945 chown .apache *
946 chmod -R 755 *
947 chown -R .apache *
948 ls -la


1. ต้องสร้างโฟลเดอร์ awstats ในที่ที่เราเก็บเว็บไซต์ไว้ ในกรณีที่เราเก็บเว็บไซต์ไว้ที่ที่ไม่ใช่ /var/www/html/ ซึ่งผมเก็บไว้ที่ /home/crisgo/ ซึ่งโฟลเดอร์ดังกล่าวมันจะเก็บหน้าเว็บที่ใช้แสดงผล ที่เราต้องการดู ดังนี้

#vi /usr/local/bin/awstats.updates -> ใส่ค่าดังนี้
##########################################################
#!/bin/bash

cat /var/log/maillog.4 >> /var/tmp/awstats.tmp
cat /var/log/maillog.3 >> /var/tmp/awstats.tmp
cat /var/log/maillog.2 >> /var/tmp/awstats.tmp
cat /var/log/maillog.1 >> /var/tmp/awstats.tmp
cat /var/log/maillog >> /var/tmp/awstats.tmp

rm -f /home/crisgo/awstats/*

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=crisgo -update
perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=crisgo -output -staticlink
s > /home/crisgo/awstats/index.html
perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=crisgo -output=allhosts -s
taticlinks > /home/crisgo/awstats/awstats.crisgo.allhosts.html
perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=crisgo -output=allemails -
staticlinks > /home/crisgo/awstats/awstats.crisgo.allemails.html
perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=crisgo -output=allemailr -
staticlinks > /home/crisgo/awstats/awstats.crisgo.allemailr.html
perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=crisgo -output=lastemailr
-staticlinks > /home/crisgo/awstats/awstats.crisgo.lastemailr.html
perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=crisgo -output=lastemails -
staticlinks > /home/crisgo/awstats/awstats.crisgo.lastemails.html
perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=crisgo -output=unknownip -
staticlinks > /home/crisgo/awstats/awstats.crisgo.unknownip.html
rm -f /var/tmp/awstats.tmp
#############################################################

2. สร้างไฟล์ awstats.crisgo.conf ดังนี้

#vi /etc/awstats/awstats.crisgo.conf -> ใส่ค่าดังนี้
##################################################################################

LogFile="perl /usr/local/awstats/tools/maillogconvert.pl standard < /var/tmp/awstats.tmp |"
LogType=M
LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd"
LevelForBrowsersDetection=0
LevelForOSDetection=0
LevelForRefererAnalyze=0
LevelForRobotsDetection=0
LevelForWormsDetection=0
LevelForSearchEnginesDetection=0
LevelForFileTypesDetection=0
ShowMenu=1
ShowSummary=HB
ShowMonthStats=HB
ShowDaysOfMonthStats=HB
ShowDaysOfWeekStats=HB
ShowHoursStats=HB
ShowDomainsStats=0
ShowHostsStats=HBL
ShowAuthenticatedUsers=0
ShowRobotsStats=0
ShowEMailSenders=HBML
ShowEMailReceivers=HBML
ShowSessionsStats=0
ShowPagesStats=0
ShowFileTypesStats=0
ShowFileSizesStats=0
ShowBrowsersStats=0
ShowOSStats=0
ShowOriginStats=0
ShowKeyphrasesStats=0
ShowKeywordsStats=0
ShowMiscStats=0
ShowHTTPErrorsStats=0
ShowSMTPErrorsStats=1
SiteDomain="www.crisgo.com"
###########################################################################

3. สร้างไฟล์ Crontab

#crontab -e
0 * * * * /usr/local/bin/awstats.updates
###########################################################################

พอทำเสร็จก็ไม่ต้อง start service อะไร เพราะ /usr/local/bin/awstats.updates คำสั่งตรงนี้มันทำงานที่ crontab อยู่แล้ว วิธีเรียกใช้ก็ www.crisgo.com/awstats เป็นอันว่าดูได้เลย มันจะทำงานทุก 1 ชม. ของทุกวัน ทุกสัปดาห์ แล้วยังส่งเมลมาแจ้งด้วย

นอกจากนี้หากต้องการดู tail -f /var/log/maillog สามารถดูได้จาก webmin -> http://www.crisgo.com:10000/syslog/index.cgi

No comments: