前提
- 首先安裝了httpd,并且httpd的日志格式為
combined
- 做日志切割時,
yum方式與源碼方式
1, yum 安裝與配置
- 安裝
添加epel源
yum install awstats
- 修改httpd配置,確保mod_cgi以被加載.
vim /etc/httpd/conf.d/awstats.conf
Alias /awstats/icon/ /var/www/awstats/icon/
ScriptAlias /awstats/ /var/www/awstats/
<Directory "/var/www/awstats/">
DirectoryIndex awstats.pl
Options ExecCGI
order deny,allow
deny from all
allow from 127.0.0.1
allow from 192.168.1.0/24
</Directory>
- 創(chuàng)建要統(tǒng)計的網(wǎng)站的配置文件,以主域名方式命令
# cp /etc/awstats/awstats.localhost.localdomain.conf /etc/awstats/awstats.tecadmin.net.conf
# vim /etc/awstats/awstats.tecadmin.net.conf
- 修改相應(yīng)的配置文件里的相應(yīng)配置.
# httpd access log的位置,及文件名
LogFile="/var/log/httpd/tecadmin.net-access_log"
# 設(shè)置要統(tǒng)計的網(wǎng)站的域名
SiteDomain="tecadmin.net"
# 這個網(wǎng)站的其他域名
HostAliases="tecadmin.net www.tecadmin.net"
還有一些其他的配置比如跳過統(tǒng)計某些IP地址.
- 生成數(shù)據(jù),
/usr/bin/perl /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=tecadmin.net -update
添加crontab定時生成數(shù)據(jù).
0 2 * * * /usr/bin/perl /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=tecadmin.net -update
- 訪問方式
http://svr1.tecadmin.net/awstats/awstats.pl?config=tecadmin.net
源碼安裝
(1) 下載
[root@node6 src]# wget http://jaist.dl.sourceforge.net/project/awstats/AWStats/7.2/awstats-7.2.tar.gz
[root@node6 src]# tar xf awstats-7.2.tar.gz
[root@node6 src]# mv awstats-7.2 /usr/local/awstats
[root@node6 src]# cd /usr/local/awstats
[root@node6 awstats]# ls
docs README.TXT tools wwwroot
注,由于wget下載下來的包中權(quán)限是非root的宏邮,所以這里要修改權(quán)限泽示,否則稍后*.pl將無法運行。
(2) 授權(quán)
[root@node6 awstats]# chown -R root.root /usr/local/awstats
[root@node6 awstats]# ll
總用量 20
drwx------. 4 root root 4096 7月 10 04:01 docs
-rw-------. 1 root root 6790 7月 10 03:50 README.TXT
drwx------. 5 root root 4096 7月 10 04:01 tools
drwx------. 7 root root 4096 7月 10 04:01 wwwroot
[root@node6 awstats]# chmod +x /usr/local/awstats/tools/*.pl
[root@node6 awstats]# cd tools/
[root@node6 tools]# ls
awstats_buildstaticpages.pl awstats_exportlib.pl geoip_generator.pl logresolvemerge.pl nginx webmin
awstats_configure.pl awstats_updateall.pl httpd_conf maillogconvert.pl urlaliasbuilder.pl xslt
[root@node6 tools]# chmod +x /usr/local/awstats/wwwroot/cgi-bin/*.pl
[root@node6 tools]# cd ..
[root@node6 awstats]# cd wwwroot/cgi-bin/
[root@node6 cgi-bin]# ls
awdownloadcsv.pl awredir.pl awstats.model.conf awstats.pl lang lib plugins
(3) 配置要統(tǒng)計網(wǎng)站
我們要執(zhí)行/usr/local/awstats/tools下的awstats_configure.pl配置向?qū)郯保脕砩蒩wstats的配置文件械筛,awstats配置文件的命名規(guī)則是awstats.website.conf。
[root@node6 ~]# cd /usr/local/awstats/tools/
[root@node6 tools]# ./awstats_configure.pl
此時會出現(xiàn)如下提示飒炎,
----- AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).
-----> 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):
> /usr/local/apache2/conf/httpd.conf #這里讓你輸入apache配置文件的目錄埋哟,我這里的apache是源碼安裝的,所以我的路徑是/usr/local/apache2/conf/httpd.conf
Your web server config file(s) could not be found.
You will need to setup your web server manually to declare AWStats
script as a CGI, if you want to build reports dynamically.
See AWStats setup documentation (file docs/index.html)
-----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
File awstats.model.conf updated.
-----> 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 #詢問是否創(chuàng)建一個新的配置文件郎汪,這里填y即可赤赊。
-----> 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:
> www.test.com #這里讓填寫你的網(wǎng)站域名,虛擬主機名或者隨便一個配置名煞赢。
-----> 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):
> #這里要填寫你配置文件存放路徑抛计,我們使用它默認的路徑/etc/awstats,所以直接回車即可耕驰。
-----> Create config file '/etc/awstats/awstats.www.test.com.conf'
Config file /etc/awstats/awstats.www.test.com.conf created.
-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.test.com
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue... #提示不能自動加入crontab定時任務(wù)爷辱,需要稍后自己添加,我們按回車繼續(xù)即可朦肘。
A SIMPLE config file has been created: /etc/awstats/awstats.www.test.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.test.com' with command:
> perl awstats.pl -update -config=www.test.com
You can also build static report pages for 'www.test.com' with command:
> perl awstats.pl -output=pagetype -config=www.test.com
Press ENTER to finish... #提示配置文件創(chuàng)建完成和如何更新配置及建立靜態(tài)報告頁饭弓,這里我們回車即可結(jié)束這個配置向?qū)А?
(4).查看并修改一下這個配置文件
[root@node6 tools]# cd /etc/awstats/
[root@node6 awstats]# ls
awstats.www.test.com.conf
[root@node6 awstats]# vim awstats.www.test.com.conf #這個配置文件有很多配置,我們這里只講解重點配置媒抠。
LogFile="/log/www/access_%YYYY-24%MM-24%DD-24.log" #日志文件存放路徑弟断,其中%YYYY-24%MM-24%DD是指年月日模式
DirData="/var/lib/awstats" #創(chuàng)建生成的數(shù)據(jù)路徑
Lang="cn" #默認語言中文
SkipHosts="127.0.0.1 REGEX[^192\.168\.]" #本地及內(nèi)部的訪問不做分析統(tǒng)計
LevelForWormsDetection=2 #日志等級,不對警告日志進行統(tǒng)計
(5).下面我們來修改一下apache配置文件
root@node6 www]# vim /usr/local/apache2/conf/httpd.conf
#CustomLog logs/access_log combined
CustomLog "|/usr/local/sbin/cronolog /log/www/access_%Y%m%d.log" combined
(6).新建apache日志目錄
[root@node6 ~]# mkdir -pv /log/www/
mkdir: 已創(chuàng)建目錄 "/log"
mkdir: 已創(chuàng)建目錄 "/log/www/"
[root@node6 ~]# cd /log/www/
[root@node6 www]# chmod -R 755 /log/www/
[root@node6 www]# chown -R daemon /log/www/
(7).重新啟動apache服務(wù)器
[root@node6 www]# /usr/local/apache2/bin/apachectl restart
(8).創(chuàng)建awstats的數(shù)據(jù)存放目錄`
[root@node6 www]# mkdir -pv /var/lib/awstats
[root@node6 www]# chmod 755 /var/lib/awstats
(9) 加入定時任務(wù).
[root@node6 ~]# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.test.com
Create/Update database for config "/etc/awstats/awstats.www.test.com.conf" by AWStats version 7.2 (build 1.992)
From data in log file "/log/www/access_20131228.log"...
Phase 1 : First bypass old records, searching new record...
Direct access to last remembered record has fallen on another record.
So 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: 155446
Found 8 dropped records,
Found 0 comments,
Found 0 blank records,
Found 1 corrupted records,
Found 0 old records,
Found 155437 new qualified records.
crontab -e
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.test.com
問題總結(jié)
1) 建立多個日志統(tǒng)計的方式:可以多次運行`./awstats_configure.pl`趴生,也可以復(fù)制配置文件進行修改.
2) 修復(fù)中文亂碼問題
確保URI::Escape已安裝
perl -MCPAN -e 'install URI::Escape'
# 源碼安裝
[root@node6 src]# wget http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/URI-1.60.tar.gz
[root@node6 src]# tar xf URI-1.60.tar.gz
[root@node6 src]# cd URI-1.60
[root@node6 src]# perl Makefile.PL
[root@node6 src]# make && make install
打開解碼,解碼UTF8
[root@node6 ~]# vim /etc/awstats/awstats.www.test.com.conf
#LoadPlugin="decodeutfkeys" #1300 行
LoadPlugin="decodeutfkeys"
IP顯示地區(qū)
1. 使用GeoIP的方式
(1).MaxMind目前免費提供了GeoIP和GeoIPCityLite數(shù)據(jù)包:可以定期每個月從以下地址下載
[root@node6 src]# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
[root@node6 src]# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
[root@node6 src]# ls
GeoIP.dat.gz GeoLiteCity.dat.gz
注阀趴,下載下來用gunzip解壓即可。
[root@node6 src]# gunzip GeoIP.dat.gz
[root@node6 src]# gunzip GeoLiteCity.dat.gz
[root@node6 src]# ls
GeoIP.dat GeoLiteCity.dat
(2).新建的目錄苍匆,把兩個文件移入新建的目錄
[root@node6 src]# mkdir /var/geoip
[root@node6 src]# mv GeoIP.dat GeoLiteCity.dat /var/geoip
(3).安裝GeoIP與GeoIP perl庫
[root@node6 src]# yum install –y GeoIP perl-Geo-IP
perl -MCPAN -e "install Geo::IP::PurePerl"
(4).修改awstats配置文件
[root@node6 ~]# vim /etc/awstats/awstats.www.test.com.conf
#LoadPlugin="geoip GEOIP_STANDARD /pathto/GeoIP.dat" #1429行
#LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /pathto/GeoIPCity.dat" #1438行
修改為:
LoadPlugin="geoip GEOIP_STANDARD /var/geoip/GeoIP.dat"
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /var/geoip/GeoLiteCity.dat"
2. 使用QQ純真版IP
(1) 在awstats的wwwroot下的plugin目錄里下載
cd /usr/local/awstats/wwwroot/cgi-bin/plugins
# yum安裝時目錄為:/usr/share/awstats/wwwroot/cgi-bin/plugins 刘急,沒有則建立
wget http://www.haiyun.me/download/qqwry.pl
wget http://www.haiyun.me/download/qqhostinfo.pm
獲取最新的IP信息的方式為:到update.cz88.net中下在windows安裝版,之后在安裝目錄里有qqwry.dat
浸踩,既是最新的數(shù)據(jù)叔汁。
(2)上傳qqwry到awstats的wwwroot下的plugin目錄里.
(3) 修改插件配置
#修改qqwry.pl內(nèi)IP數(shù)據(jù)目錄:
my $ipfile="${DIR}/plugins/qqwry.dat";
(4) 添加插件到awstats
#修改awstats配置加載擴展:
LoadPlugin="qqhostinfo"
3.刪除舊的統(tǒng)計數(shù)據(jù)庫
[root@node6 ~]# rm -rf /var/lib/awstats/*
4.重新生成一下數(shù)據(jù)庫
[root@node6 ~]# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.test.com
參考
http://freeloda.blog.51cto.com/2033581/1346412
http://tecadmin.net/steps-to-configure-awstats-on-centos-and-rhel-system/
http://www.haiyun.me