2010年11月11日 星期四

監控web,mail,ftp的工具 -- awstats

相關套件:
awstats-6.95-1.noarch.rpm     //google "awstats"

相關目錄與檔案:
/usr/local/awstats
/etc/awstats
/usr

安裝:
#rpm -ivh awstats-6.95-1.noarch.rpm
...
----- AWStats 6.95 - Laurent Destailleur -----
AWStats files have been installed in /usr/local/awstats

If first install, follow instructions in documentation
(/usr/local/awstats/docs/index.html) to setup AWStats in 3 steps:
Step 1 : Install and Setup with awstats_configure.pl (or manually)
Step 2 : Build/Update Statistics with awstats.pl
Step 3 : Read Statistics

#rpm -ql awstats | less    //查出安裝那些目錄與檔案
//可得知awstats_configure.pl放在/usr/local/awststs/tools下
#cd /usr/local/awststs/tools
# ./awstats_configure.pl
----- AWStats awstats_configure 1.0 (build 1.8) (c) Laurent Destailleur -----
......

-----> Running OS detected: Linux, BSD or Unix

-----> Check for web server install

Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
>/etc/httpd/conf/httpd.conf       //httpd設定檔放置位置
-----> Check and complete web server config file '/etc/httpd/conf/httpd.conf'
  Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'
  Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"'
  Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"'
  Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"'
  Add '' directive
  AWStats directives added to Apache config file.

-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y        //yes讓他幫忙修改httpd.conf
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> a238.snpy.org            //網站名稱

-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats              
Directory path to store config file(s) (Enter for default):
>             //存放awstats設定檔的位置,enter讓他用default就可以了

-----> Create config file '/etc/awstats/awstats.a238.snpy.org.conf'
Error: Failed to open '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf' for read.
//error是因為這個版本將awstats.model.conf放在/usr/etc/awstats/下,
//將檔案copy到程式要求的位置再重新執行./awstats_configure.pl 即可

#vim /etc/awstats/awstats.a238.snpy.org.conf   //修改成
#LogFile="/var/log/httpd/mylog.log"
LogFile="/var/log/httpd/access_log"      //要分析的httpd log檔正確名稱

#mkdir /vat/lib/awstats
#cd /usr/local/awstats/wwwroot/cgi-bin/
#perl awstats.pl -update -config=a238.snpy.org   //前面設定的網站名稱

監控mail:
#cd /usr/local/awstats/wwwroot/cgi-bin
#cp awstats.model.conf awstats.mail.conf
#vim awstats.mail.conf    //修改以下內容
LogFile="/usr/local/awstats/tools/maillogconvert.pl standard < /var/log/maillog|"
LogType=M     //Log種類
LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd"    //log_format
SiteDomain="a238.snpy.org"      //mail 域名
...
LevelForBrowsersDetection=0         # 0 disables Browsers detection.
                                    # 2 reduces AWStats speed by 2%
                                    # allphones reduces AWStats speed by 5%
LevelForOSDetection=0               # 0 disables OS detection.
                                    # 2 reduces AWStats speed by 3%
LevelForRefererAnalyze=0            # 0 disables Origin detection.
                                    # 2 reduces AWStats speed by 14%
LevelForRobotsDetection=0           # 0 disables Robots detection.
                                    # 2 reduces AWStats speed by 2.5%
LevelForSearchEnginesDetection=0    # 0 disables Search engines detection.
                                    # 2 reduces AWStats speed by 9%
LevelForKeywordsDetection=0         # 0 disables Keyphrases/Keywords detection.
                                    # 2 reduces AWStats speed by 1%
LevelForFileTypesDetection=0        # 0 disables File types detection.
                                    # 2 reduces AWStats speed by 1%
LevelForWormsDetection=0            # 0 disables Worms detection.
                                    # 2 reduces AWStats speed by 15%
...
ShowMonthStats=HB             //以下為顯示的畫面格式
ShowDaysOfMonthStats=HB
ShowDaysOfWeekStats=HB
ShowHoursStats=HB
ShowDomainsStats=0
ShowHostsStats=HBL
ShowAuthenticatedUsers=0
ShowRobotsStats=0
ShowWormsStats=0
ShowEMailSenders=HBML
ShowEMailReceivers=HBML
ShowSessionsStats=0
ShowPagesStats=0
ShowFileTypesStats=0
ShowFileSizesStats=0
ShowOSStats=0
ShowBrowsersStats=0
ShowScreenSizeStats=0
ShowOriginStats=0
ShowKeyphrasesStats=0
ShowKeywordsStats=0
ShowMiscStats=0
ShowHTTPErrorsStats=0
ShowSMTPErrorsStats=1

#/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mail

監控FTP:
#vim /etc/vsftpd/vsftpd.conf     //修改log輸出格式
xferlog_std_format=YES

#cd /usr/local/awstats/wwwroot/cgi-bin
#cp awstats.model.conf awstats.ftp.conf
#vim awstats.ftp.conf
LogFile="/var/log/xferlog"
LogType=F
LogFormat="%time3 %other %host %bytesd %url %other %other %method %other %logname %other %code %other %other"
LogSeparator="\s"
SiteDomain="ftp.a238.snpy.org"
.....
LevelForBrowsersDetection=0         # 0 disables Browsers detection.
                                    # 2 reduces AWStats speed by 2%
                                    # allphones reduces AWStats speed by 5%
LevelForOSDetection=0               # 0 disables OS detection.
                                    # 2 reduces AWStats speed by 3%
LevelForRefererAnalyze=0            # 0 disables Origin detection.
                                    # 2 reduces AWStats speed by 14%
LevelForRobotsDetection=0           # 0 disables Robots detection.
                                    # 2 reduces AWStats speed by 2.5%
LevelForSearchEnginesDetection=0    # 0 disables Search engines detection.
                                    # 2 reduces AWStats speed by 9%
LevelForKeywordsDetection=0         # 0 disables Keyphrases/Keywords detection.
                                    # 2 reduces AWStats speed by 1%
LevelForFileTypesDetection=0        # 0 disables File types detection.
                                    # 2 reduces AWStats speed by 1%
LevelForWormsDetection=0            # 0 disables Worms detection.
                                    # 2 reduces AWStats speed by 15%
....
ShowMenu=1
ShowSummary=UVHB
ShowMonthStats=UVHB
ShowDaysOfMonthStats=HB
ShowDaysOfWeekStats=HB
ShowHoursStats=HB
ShowDomainsStats=HB
ShowHostsStats=PBL
ShowAuthenticatedUsers=HBL
ShowRobotsStats=0
ShowWormsStats=0
ShowEMailSenders=0
ShowEMailReceivers=0
ShowSessionsStats=1
ShowPagesStats=PBEX
ShowFileTypesStats=HB
ShowFileSizesStats=0
ShowOSStats=1
ShowBrowsersStats=0
ShowScreenSizeStats=0
ShowOriginStats=0
ShowKeyphrasesStats=0
ShowKeywordsStats=0
ShowMiscStats=a
ShowHTTPErrorsStats=0
ShowSMTPErrorsStats=0
...
ShowLinksOnUrl=0

#/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=ftp

測試:
用Browser連接 http://localhost/awstat/awstats.pl?config=a238.snpy.org        //web流量監控
用Browser連接 http://localhost/awstat/awstats.pl?config=mail         //mail監控
用Browser連接 http://localhost/awstat/awstats.pl?config=ftp         //ftp監控

排程更新內容:  
#crontab -e
0 0 * * * /usr/local/awstats/tools/awstats_updateall.pl now > /dev/null   
#設定整點更新,訊息丟棄
*由於awstats是解析log檔內容,故更新時間必須比logrotate要短

沒有留言:

張貼留言