原創作品,允許轉載,轉載時請務必以超鏈接形式標明文章 原始出處 、作者信息和本聲明。否則將追究法律責任。http://nolinux.blog.51cto.com/4824967/1316979
訪問次數、獨特訪客人數,訪問時間和上次訪問,使用者認證、最近認證的訪問,每周的高峰時間(頁數,點擊率,每小時和一周的千字節),域名/國家的主機訪客(頁數,點擊率,字節,269域名/國家檢測, geoip 檢測),主機名單,最近訪問和未解析的 IP 地址名單大多數看過的進出頁面,檔案類型,網站壓縮統計表(mod_gzip 或者 mod_deflate),使用的操作系統 (每個操作系統的頁數,點擊率 ,字節, 35 OS detected),使用的瀏覽器,機器人訪問(檢測 319 個機器人),蠕蟲攻擊 (5 個蠕蟲家族),搜索引擎,利用關鍵詞檢索找到你的地址,HTTP 協議錯誤(最近查閱沒有找到的頁面),其他基于 URL 的個性報導,鏈接參數, 涉及綜合行銷領域目的.貴網站被加入"最喜愛的書簽".次數.屏幕大小(需要在索引頁補充一些 HTML 標簽).瀏覽器的支持比例: Java, Flash, RealG2 reader, Quicktime reader, WMA reader, PDF reader.負載平衡服務器比率集群報告.
環境:
CentOS 6.4 x86_64ip:192.168.1.113域名:www.sunsky.com(server和client都通過hosts文件解析)nginx-1.2.9 編譯安裝,路徑/usr/local/nginx,服務開啟狀態日志記錄格式為nginx默認的,切勿更改,否則會造成awstats無法分析日志。log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';awstats-7.2.tar.gz
1 | vim /server/scripts/cut_nginx_log .sh |
#!/bin/shyesterday=`date -d "yesterday" +"%Y%m%d"`before_yesterday=`date -d "-2 day" +"%Y%m%d"`Nginx_Dir="/usr/local/nginx"Nginx_logs="/app/logs"Log_Name="www_access"cd /tmp[ -d $Nginx_Logs ] && cd $Nginx_logs || exit 1[ -f $Log_Name.log ] && /bin/mv $Log_Name.log ${Log_Name}_${yesterday}.log || exit 1if [ $? -eq 0 -a -f $Nginx_Dir/logs/nginx.pid ] then kill -USR1 `cat $Nginx_Dir/logs/nginx.pid`fi[ -f ${Log_Name}_${before_yesterday}.log ] && /usr/bin/gzip ${Log_Name}_${before_yesterday}.log|| exit 1
1 0 * * * /bin/sh /server/scripts/cut_nginx_log.sh >/dev/null 2>&1
/bin/sh /server/scripts/cut_nginx_log .sh > /dev/null 2>&1
首先我們要下載awstats軟件包,并將其放在常規目錄(/usr/local)下
wget http://awstats.sourceforge.net/files/awstats-7.2.tar.gztar zxf awstats-7.2.tar.gzmv awstats-7.2 /usr/local/awstats
由于wget下載下來的包中權限是非root的,所以這里要修改權限,否則稍后*.pl將無法運行
chown -R root.root /usr/local/awstatschmod +x /usr/local/awstats/tools/*.plchmod +x /usr/local/awstats/wwwroot/cgi-bin/*.pl
cd /usr/local/awstats/tools/./awstats_configure.pl
----- AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur -----This tool will help you to configure AWStats to analyze statistics forone web server. You can try to use it to let it do all that is possiblein AWStats setup, however following the step by step manual setupdocumentation (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 installEnter full config file path of your Web server.Example: /etc/httpd/httpd.confExample: /usr/local/apache2/conf/httpd.confExample: c:\Program files\apache group\apache\conf\httpd.confConfig file path ('none' to skip web server setup):> none #這里讓填寫網頁服務器的配置文件路徑,因為我們用的不是apache,所以這里要填noneYour web server config file(s) could not be found.You will need to setup your web server manually to declare AWStatsscript 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/profilefile (required if first install) [y/N] ? y #詢問是否創建一個新的配置文件,這里填y-----> Define config file name to createWhat is the name of your web site or profile analysis ?Example: www.mysite.comExample: demoYour web site, virtual server or profile name:> www.sunsky.com #這里讓填寫你的網站域名,虛擬主機名或者隨便一個配置名-----> Define config file pathIn which directory do you plan to store your config file(s) ?Default: /etc/awstatsDirectory path to store config file(s) (Enter for default):> #這里要填寫你配置文件存放路徑,我們使用它默認的路徑/etc/awstats,所以直接回車即可-----> Create config file '/etc/awstats/awstats.www.sunsky.com.conf' Config file /etc/awstats/awstats.www.sunsky.com.conf created.-----> Add update process inside a schedulerSorry, 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.sunsky.comOr if you have several config files and prefer having only one command:/usr/local/awstats/tools/awstats_updateall.pl nowPress ENTER to continue... #提示不能自動加入crontab定時任務,需要稍后自己添加,我們按回車繼續即可A SIMPLE config file has been created: /etc/awstats/awstats.www.sunsky.com.confYou should have a look inside to check and change manually main parameters.You can then manually update your statistics for 'www.sunsky.com' with command:> perl awstats.pl -update -config=www.sunsky.comYou can also build static report pages for 'www.sunsky.com' with command:> perl awstats.pl -output=pagetype -config=www.sunsky.comPress ENTER to finish... #提示配置文件創建完成和如何更新配置及建立靜態報告頁,這里我們回車即可結束這個配置向導
sed -i 's#LogFile="/var/log/httpd/mylog.log"#LogFile="/app/logs/www_access_%YYYY-24%MM-24%DD-24.log"#g' /etc/awstats/awstats.www.sunsky.com.conf
sed -i 's#DirData="/var/lib/awstats"#DirData="/usr/local/awstats/data"#g' /etc/awstats/awstats.www.sunsky.com.conf
mkdir /usr/local/awstats/data
grep "LogFile=" /etc/awstats/awstats.www.sunsky.com.confgrep "DirData=" /etc/awstats/awstats.www.sunsky.com.conf
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.sunsky.com
Create/Update database for config "/etc/awstats/awstats.www.sunsky.com.conf" by AWStats version 7.2 (build 1.992)From data in log file "/app/logs/www_access.log"...Phase 1 : First bypass old records, searching new record...Searching new records from beginning of log file...Jumped lines in file: 0Parsed lines in file: 0 Found 0 dropped records, Found 0 comments, Found 0 blank records, Found 0 corrupted records, Found 0 old records, Found 0 new qualified records.
vim /server/scripts/awstats.sh
#!/bin/shAwstats_Dir="/usr/local/awstats"[ -d /www/awstats ]||mkdir /www/awstats$Awstats_Dir/wwwroot/cgi-bin/awstats.pl -update -config=www.sunsky.com$Awstats_Dir/tools/awstats_buildstaticpages.pl -update -config=www.sunsky.com -awstatsprog=$Awstats_Dir/wwwroot/cgi-bin/awstats.pl -lang=cn -dir=/www/awstats
/usr/local/awstats/tools/awstats_buildstaticpages.pl Awstats 靜態頁面生成工具-update -config=www.sunsky.com 更新配置項-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl Awstats 日志更新程序路徑-lang=cn 語言為中文-dir= /www/awstats 統計結果輸出目錄
vim /usr/local/nginx/conf/nginx.conf
server { listen 80; server_name www.sunsky.com; location / { root /www/sunsky; index index.html index.htm; access_log /app/logs/www_access.log commonlog;}location ~ ^/awstats/ { root /www/; index awstats.www.sunsky.com.html; #根據自己的網站域名進行更改首頁文件 autoindex on; access_log off; charset gb2312; auth_basic "Restricted"; #有些網站不愿意公開網站流量信息,所以加個認證 auth_basic_user_file /usr/local/nginx/htpasswd.pass; #該文件由apache的加密認證工具htpasswd創建}location ~ ^/icon/ { root /usr/local/awststs/wwwroot; index index.html; access_log off; charset gb2312;} }
htpasswd -c -m /usr/local/nginx/htpasswd.pass sunskyadmin #用戶名為sunskyadmin
1 0 * * * /bin/sh /server/scripts/cut_nginx_log.sh >/dev/null 2>&10 1 * * * /bin/sh /server/scripts/awstats.sh >/dev/null 2>&1
訪問次數、獨特訪客人數,訪問時間和上次訪問,使用者認證、最近認證的訪問,每周的高峰時間(頁數,點擊率,每小時和一周的千字節),域名/國家的主機訪客(頁數,點擊率,字節,269域名/國家檢測, geoip 檢測),主機名單,最近訪問和未解析的 IP 地址名單大多數看過的進出頁面,檔案類型,網站壓縮統計表(mod_gzip 或者 mod_deflate),使用的操作系統 (每個操作系統的頁數,點擊率 ,字節, 35 OS detected),使用的瀏覽器,機器人訪問(檢測 319 個機器人),蠕蟲攻擊 (5 個蠕蟲家族),搜索引擎,利用關鍵詞檢索找到你的地址,HTTP 協議錯誤(最近查閱沒有找到的頁面),其他基于 URL 的個性報導,鏈接參數, 涉及綜合行銷領域目的.貴網站被加入"最喜愛的書簽".次數.屏幕大小(需要在索引頁補充一些 HTML 標簽).瀏覽器的支持比例: Java, Flash, RealG2 reader, Quicktime reader, WMA reader, PDF reader.負載平衡服務器比率集群報告.
環境:
CentOS 6.4 x86_64ip:192.168.1.113域名:www.sunsky.com(server和client都通過hosts文件解析)nginx-1.2.9 編譯安裝,路徑/usr/local/nginx,服務開啟狀態日志記錄格式為nginx默認的,切勿更改,否則會造成awstats無法分析日志。log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';awstats-7.2.tar.gz
vim /server/scripts/cut_nginx_log.sh
#!/bin/shyesterday=`date -d "yesterday" +"%Y%m%d"`before_yesterday=`date -d "-2 day" +"%Y%m%d"`Nginx_Dir="/usr/local/nginx"Nginx_logs="/app/logs"Log_Name="www_access"cd /tmp[ -d $Nginx_Logs ] && cd $Nginx_logs || exit 1[ -f $Log_Name.log ] && /bin/mv $Log_Name.log ${Log_Name}_${yesterday}.log || exit 1if [ $? -eq 0 -a -f $Nginx_Dir/logs/nginx.pid ] then kill -USR1 `cat $Nginx_Dir/logs/nginx.pid`fi[ -f ${Log_Name}_${before_yesterday}.log ] && /usr/bin/gzip ${Log_Name}_${before_yesterday}.log|| exit 1
1 0 * * * /bin/sh /server/scripts/cut_nginx_log.sh >/dev/null 2>&1
/bin/sh /server/scripts/cut_nginx_log.sh >/dev/null 2>&1
首先我們要下載awstats軟件包,并將其放在常規目錄(/usr/local)下
wget http://awstats.sourceforge.net/files/awstats-7.2.tar.gztar zxf awstats-7.2.tar.gzmv awstats-7.2 /usr/local/awstats
由于wget下載下來的包中權限是非root的,所以這里要修改權限,否則稍后*.pl將無法運行
chown -R root.root /usr/local/awstatschmod +x /usr/local/awstats/tools/*.plchmod +x /usr/local/awstats/wwwroot/cgi-bin/*.pl
----- AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur -----This tool will help you to configure AWStats to analyze statistics forone web server. You can try to use it to let it do all that is possiblein AWStats setup, however following the step by step manual setupdocumentation (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 installEnter full config file path of your Web server.Example: /etc/httpd/httpd.confExample: /usr/local/apache2/conf/httpd.confExample: c:\Program files\apache group\apache\conf\httpd.confConfig file path ('none' to skip web server setup):> none #這里讓填寫網頁服務器的配置文件路徑,因為我們用的不是apache,所以這里要填noneYour web server config file(s) could not be found.You will need to setup your web server manually to declare AWStatsscript 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/profilefile (required if first install) [y/N] ? y #詢問是否創建一個新的配置文件,這里填y-----> Define config file name to createWhat is the name of your web site or profile analysis ?Example: www.mysite.comExample: demoYour web site, virtual server or profile name:> www.sunsky.com #這里讓填寫你的網站域名,虛擬主機名或者隨便一個配置名-----> Define config file pathIn which directory do you plan to store your config file(s) ?Default: /etc/awstatsDirectory path to store config file(s) (Enter for default):> #這里要填寫你配置文件存放路徑,我們使用它默認的路徑/etc/awstats,所以直接回車即可-----> Create config file '/etc/awstats/awstats.www.sunsky.com.conf' Config file /etc/awstats/awstats.www.sunsky.com.conf created.-----> Add update process inside a schedulerSorry, 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.sunsky.comOr if you have several config files and prefer having only one command:/usr/local/awstats/tools/awstats_updateall.pl nowPress ENTER to continue... #提示不能自動加入crontab定時任務,需要稍后自己添加,我們按回車繼續即可A SIMPLE config file has been created: /etc/awstats/awstats.www.sunsky.com.confYou should have a look inside to check and change manually main parameters.You can then manually update your statistics for 'www.sunsky.com' with command:> perl awstats.pl -update -config=www.sunsky.comYou can also build static report pages for 'www.sunsky.com' with command:> perl awstats.pl -output=pagetype -config=www.sunsky.comPress ENTER to finish... #提示配置文件創建完成和如何更新配置及建立靜態報告頁,這里我們回車即可結束這個配置向導
sed -i 's#LogFile="/var/log/httpd/mylog.log"#LogFile="/app/logs/www_access_%YYYY-24%MM-24%DD-24.log"#g' /etc/awstats/awstats.www.sunsky.com.conf
sed -i 's#DirData="/var/lib/awstats"#DirData="/usr/local/awstats/data"#g' /etc/awstats/awstats.www.sunsky.com.conf
mkdir /usr/local/awstats/data
以上的兩個替換操作進行完之后一定要用命令查看替換是否成功,以便及早發現紕漏。
grep "LogFile=" /etc/awstats/awstats.www.sunsky.com.confgrep "DirData=" /etc/awstats/awstats.www.sunsky.com.conf
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.sunsky.com
Create/Update database for config "/etc/awstats/awstats.www.sunsky.com.conf" by AWStats version 7.2 (build 1.992)From data in log file "/app/logs/www_access.log"...Phase 1 : First bypass old records, searching new record...Searching new records from beginning of log file...Jumped lines in file: 0Parsed lines in file: 0 Found 0 dropped records, Found 0 comments, Found 0 blank records, Found 0 corrupted records, Found 0 old records, Found 0 new qualified records.
vim /server/scripts/awstats.sh
#!/bin/shAwstats_Dir="/usr/local/awstats"[ -d /www/awstats ]||mkdir /www/awstats$Awstats_Dir/wwwroot/cgi-bin/awstats.pl -update -config=www.sunsky.com$Awstats_Dir/tools/awstats_buildstaticpages.pl -update -config=www.sunsky.com -awstatsprog=$Awstats_Dir/wwwroot/cgi-bin/awstats.pl -lang=cn -dir=/www/awstats
/usr/local/awstats/tools/awstats_buildstaticpages.pl Awstats 靜態頁面生成工具-update -config=www.sunsky.com 更新配置項-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl Awstats 日志更新程序路徑-lang=cn 語言為中文-dir= /www/awstats 統計結果輸出目錄
vim /usr/local/nginx/conf/nginx.conf
server { listen 80; server_name www.sunsky.com; location / { root /www/sunsky; index index.html index.htm; access_log /app/logs/www_access.log commonlog;}location ~ ^/awstats/ { root /www/; index awstats.www.sunsky.com.html; #根據自己的網站域名進行更改首頁文件 autoindex on; access_log off; charset gb2312; auth_basic "Restricted"; #有些網站不愿意公開網站流量信息,所以加個認證 auth_basic_user_file /usr/local/nginx/htpasswd.pass; #該文件由apache的加密認證工具htpasswd創建}location ~ ^/icon/ { root /usr/local/awststs/wwwroot; index index.html; access_log off; charset gb2312;} }
htpasswd -c -m /usr/local/nginx/htpasswd.pass sunskyadmin #用戶名為sunskyadmin
1 0 * * * /bin/sh /server/scripts/cut_nginx_log.sh >/dev/null 2>&10 1 * * * /bin/sh /server/scripts/awstats.sh >/dev/null 2>&1
轉自:http://nolinux.blog.51cto.com/4824967/1316979
原創文章,作者:s19930811,如若轉載,請注明出處:http://www.www58058.com/2022