原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。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.178linux.com/2022