AWStats 是一个免费的强大而有个性的工具,带来先进的网络,流量,FTP或邮件服务器统计图. 本日志分析器做为CGI或从命令行在数个图形网页中显示你日志中包含的全部可能信息. 它利用一部分档案资料就能常常很快地处理大量日志档案, 它能分析日志文件来自从各大服务器工具 ,如 Apache日志档案 s (NCSA combined/XLF/ELF log format or common/CLF log format), WebStar, IIS (W3C的日志格式)及许多其余网站,Proxy(代理服务器)、Wap、流量服务器、邮件服务器和一些 FTP服务器 .php
Awstats是一款基于Perl的WEB日志分析工具,而JAWStats是一款基于PHP的统计套件,旨在为Awstats提供更为精美图形界面。 JAWStats 是一个用来统计网站日志的工具,在 AWStats 的基础上生成更加清晰的关于网站访问数据的图表、表格。 它能够统计您站点的以下信息: 1>.访问量,访问次数,页面浏览量,点击数,数据流量等 2>.精确到每个月、每日、每小时的数据 3>.访问者国家 4>.访问者IP 5>.Robots/Spiders的统计 6>.访客持续时间 7>.对不一样Files type 的统计信息 8>.Pages-URL的统计 9>.访客操做系统浏览器等信息 10>.其它信息(搜索关键字等等)
小节总结:css
awstats修改日志文件路径: LogFile="/usr/local/awstats/tools/logresolvemerge.pl /home/tool/access.20100817.11*.log |" 此为用awstats脚本自动合并分析全部/home/tool/access.20100817.11*.log日志 若是日志使用tar -zcvf 压缩,logresolvemerge.pl会自动调用zcat 也能够同时列出多个日志文件,如如下格式: LogFile="/usr/local/awstats/tools/logresolvemerge.pl 1.log 2.log |" 合并日志也可用如下方式: cat a.log b.log c.log | sort -m -t " " –k 4 > log 将三个日志以空格为分隔符,对第四列进行排序,结果保存在log /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=
1.安装 Awstats html
http://blog.csdn.net/wnss8888/article/details/3502756linux
Awstats 是由perl语言编写的,因此要首先准备好awstats的运行环境。 yum install –y perl*
2.下载awstats工具。web
wget http://www.awstats.org/files/awstats-7.4.tar.gz 解压: tar xvf awstats-7.1.tar.gz mv awstats-7.1 /usr/local/awstats
3.安装awstatsshell
(1)安装数据库
chown apache.apache –R /var/lib/awstats chmod 755 /usr/local/awstats chown -R apache plugins/ --受权 chown -R apache awstats cd /usr/local/awstats/tools/
#向导工具,生成网站配置文件 perl awstats_configure.pl ---执行该命令
安装过程: 1>.输入 none 而后回车 2>.输入 y 确认建立配置文件 3>.输入配置文件名称,通常输入域名。 4>.配置文件使用默认路径 /etc/awstats 5>.按回车继续 6>.按回车完成配置文件的建立
----- 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): >none 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 -----> 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: >linuxidc.com -----> 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): > -----> Create config file '/etc/awstats/awstats.linuxidc.com.conf' Config file /etc/awstats/awstats.linuxidc.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=linuxidc.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... A SIMPLE config file has been created: /etc/awstats/awstats.linuxidc.com.conf You should have a look inside to check and change manually main parameters. You can then manually update your statistics for 'linuxidc.com' with command: > perl awstats.pl -update -config=linuxidc.com You can also build static report pages for 'linuxidc.com' with command: > perl awstats.pl -output=pagetype -config=zzxtbl.pub Press ENTER to finish...
解释:apache
awstats生成的目录api
安装目录 /usr/local/awstats/ 配置文件/etc/awstats/ 数据文件/var/lib/awstats/
(2)配置http的启动awstats虚拟目录浏览器
vi /etc/httpd/conf/httpd.conf
将CustomLog logs/access_log common改成 CustomLog logs/access_log combined 在文件的最后面增长了 # Directives to allow use of AWStats as a CGI Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/" Alias /awstatscss "/usr/local/awstats/wwwroot/css/" Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/" ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/" # This is to permit URL access to scripts/files in AWStats directory. <Directory "/usr/local/awstats/wwwroot"> Options None AllowOverride None Order allow,deny Allow from all </Directory>
4.添加awstats插件和地理区域
(1)下载GeoIPLite Country地址库(须要定时更新)
wget http://www.maxmind.com/download/geoip/api/c/GeoIP-1.4.8.tar.gz tar xvf GeoIP-1.4.8.tar.gz cd GeoIP-1.4.8 ./configure make && make install
(2)安装相关Perl模块
使用perl的CPAN模块进行安装 perl -MCPAN -e "install Encode" perl -MCPAN -e "install URI::Escape" perl -MCPAN -e "install Storable" perl -MCPAN -e "install Geo::IP" perl -MCPAN -e "install Net::XWhois"
也能够一次执行5个命令
perl -MCPAN -e "install Encode, URI::Escape,Storable,Geo::IP,Net::XWhois"
(3)安装qqhostinfo插件
qqhistinfo.pm, qqwry.rar, QQWry.Dat 放到/usr/local/awstats/wwwroot/cgi-bin/plugins/下面 cd /usr/local/awstats/wwwroot/cgi-bin/plugins chmod 777 . –R
(4)下载GeoIPLite City地址库(须要定时更新)
http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum2.zip http://www.cpan.org/authors/id/B/BR/BRICAS/Geo-IPfree-1.143630.tar.gz http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz
(5)free安装
http://www.cpan.org/authors/id/B/BR/BRICAS/ tar zxvf Geo-IPfree-1.143630.tar.gz cd Geo-IPfree-1.143630 perl Makefile.PL make && make install
5.配置awstats分析http服务器日志修改/etc/awstats/awstats.www.zzxtbl.top.conf
日志格式和存放目录 将LogFile="/var/log/httpd/mylog.log" 改成LogFile="/var/log/httpd/localhost_access_log.2012-08-29.txt" LogFile="/var/log/httpd/localhost_access_log. YYY-0%MM-0%DD-0.txt"均可以。 若是有多个日志文件须要分析(好比作了负载均衡),能够这样: LogFile = "/pathtotools/logresolvemerge.pl *.log |"
修改日志格匹配(tomcat日志格式)
LogFormat = 1 LogFormat="%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot" 这两行是注释的,1表示是web日志,下面是httpd的日志格式 LogFormat ="%host %other %logname %time1 %methodurl %code" 这是我修改后的匹配tomcat的日志格式
修改解释格式扩展名
NotPageList="css js class gif jpg jpeg png bmp ico rss xml swf"
"css js class gif jpg jpeg png bmp ico rss xml swf zip arj rar gz z bz2 wav mp3 wma mpg avi"
设置页面自动刷新
将AllowToUpdateStatsFromBrowser=0改成AllowToUpdateStatsFromBrowser=1便可
设置网站的主页面的配置文件
DirData="/var/lib/awstats" DirCgi="/awstats" DirIcons="/awstatsicons"
设置网站主页面和连接url
Logo="awstats_logo6.png" LogoLink="http://www.zzxtbl.top/"
检索页面信息
LoadPlugin="tooltips" 在html报告中增长一些提示信息 LoadPlugin="decodeutfkeys" 处理搜索引擎UTF8编码的关键字
国家和地址ip解释
LoadPlugin="geoip GEOIP_STANDARD /opt/GeoIP.dat" LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /opt/GeoLiteCity.dat" LoadPlugin="geoip_org_maxmind GEOIP_STANDARD /opt/GeoIPASNum.dat" #LoadPlugin="geoip_isp_maxmind GEOIP_STANDARD /pathto/GeoIPISP.dat" #LoadPlugin="geoip_org_maxmind GEOIP_STANDARD /pathto/GeoIPOrg.dat" #LoadPlugin="geoip_region_maxmind GEOIP_STANDARD /pathto/GeoIPRegion.dat" LoadPlugin="qqhostinfo" 显示真实ip LoadPlugin="graphapplet /awstatsclasses" LoadPlugin="hostinfo" #LoadPlugin="geoipfree" LadPlugin="graphgooglechartapi" 开启地图模式 LIMITFLUSH=5000000 减轻磁盘的缓冲压力
6.启动httpd服务和刷新数据库
service httdp restart ---启动apche服务 /usr/local/awstats/tools/awstats_updateall.pl now --全局刷新生成数据 /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.zzxtbl.top --单个站点刷新数据
接下来生成报告的详细子页面,须要在命令行下经过output参数指定报告的名字,命令以下:
perl awstats.pl -config=mysite -output=alldomains -staticlinks > awstats.mysite.alldomains.html
在生成html文件后生成一个PDF文件,报告的输出目录必须包括图标目录。
本文示例:
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=www.zzxtbl.top -update -lang=cn -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -dir=/usr/local/awstats/wwwroot -diricons=icons /usr/local/awstats/tools/awstats_buildstaticpages.pl -config=www.zzxtbl.top -update -lang=cn -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -buildpdf=/usr/local/awstats/wwwroot/
(1)计划任务crontab -e 5点:30执行
50 3 * * * /usr/local/awstats/tools/awstats_updateall.pl now
7.tomcat日志解析
Tomcat的默认日志格式类型与apache同样,都是common,然而awstats分析的是combined类型的。如上所知,个人tomcat类型就是common型的,因此要改成combined型的。 从新定义tomcat日志格式:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t"%r" %s %b %{Referer}i %{User-Agent}i" />
JAWstats生成图片
2、安装和配置 JAWStats
JAWStats 是基于 Awstats 统计数据的,但其界面更为强悍,有了JAWStats 你甚至能够抛弃第三方统计了。
2.1. 下载与安装
wget http://static.jawstats.com/src/jawstats-0.7beta.tar.gz mkdir /var/www/stats/ tar -zxf jawstats-0.7beta.tar.gz -C /var/www/stats/ cd /var/www/stats/ cp config.dist.php config.php
2.2. 修改配置文件
官方配置说明见:http://www.jawstats.com/documentation
jawstats 是支持多站点的,每一个 $aConfig 对应一个站点,并能够自由切换
<?php // core config parameters $sDefaultLanguage = "zh-cn"; //设置默认语言 $sConfigDefaultView = "thismonth.all"; //默认按月显示 $bConfigChangeSites = false; //是否能够更换站点 $bConfigUpdateSites = false; //是否能够更新统计数据 $sUpdateSiteFilename = "xml_update.php"; // individual site configuration $aConfig["fb"] = array( //网站域名(注意不能乱填) "statspath" => "/var/lib/awstats/", //awstats 统计数据目录 "updatepath" => "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl/", //用于更新统计数据 "siteurl" => "http://test.org", //点击首页标题后会前往这个地址 "sitename" => "test.org", //首页标题 "theme" => "default", "fadespeed" => 250, "password" => "my-1st-password", //更新统计数据须要输入这个密码 "includes" => "", "language" => "zh-cn" ); ?> <?php // core config parameters $sDefaultLanguage = "zh-cn"; $sConfigDefaultView = "thismonth.all"; $bConfigChangeSites = false; $bConfigUpdateSites = false; $sUpdateSiteFilename = "xml_update.php"; // individual site configuration $aConfig["site1"] = array( "statspath" => "/var/lib/awstats/", "updatepath" => "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl/", "siteurl" => "http://www.zzxtbl.top", "theme" => "default", "fadespeed" => 250, "password" => "my-1st-password", "includes" => "" ); ?>
2.3. 安装中文语言包
首先下载 jawstats 多国语言包,解压缩后上传替换 lang 目录。 wget http://www.jawstats.com/src/languagepack.zip 须要注意的是,你要修改 translations.php 文件的编码为UTF-8,否则全乱码了。 另外修改汉化文件,也是translations.php,不能只修改zh-cn.js文件。
2.4.在http服务器的httpd.conf添加虚拟目录
Alias /tiandao "/usr/local/jawstats" <Directory "/usr/local/jawstats"> Options Indexes MultiViews Order allow,deny Allow from all </Directory> 配置虚拟目录用户认证访问 Alias /tongji "/usr/local/jawstats" <Directory "/usr/local/jawstats"> Options Indexes MultiViews AuthType Basic AuthName "Please Login" AuthUserFile /etc/httpd/.passwd Require valid-user </Directory>
3.日志经过ftp下载合并的shell
#!/bin/bash date=` date +%Y%m%d` yue=` date +%Y%m` one=/opt/zzx/coutlogs/1/$yue two=/opt/zzx/coutlogs/2/$yue NewLog=/opt/zzx/count logs=tiandao.log-$date if [ ! -d "$one" ]||[ ! -d "$two" ] ; then mkdir -p "$one" "$two" else if [ ! -f "$one/$logs.gz" ]||[ ! -f "$two/$logstd.gz" ] ; then ftp -n <<! open 1192.168.10.12 user zzx Z@123456 binary cd /1 lcd $one prompt off mget bj.log-$date.gz bell cd /2 lcd $two mget bj.log-$date.gz close bye ! else gunzip -c $one/zzx.log-$date.gz >$one/$logs gunzip -c $two/zzx.log-$date.gz >$two/$logs touch /opt/zzx/count/zzx.log-$date for log in zzx.log-$date do sort -m -t " " -k 4 -o $NewLog/$log $one/$log $two/$log done fi fi /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.zzxtbl.top.com rm -f $NewLog/bj.log-$date rm -f $one/bj.log-$date rm -f $two/bj.log-$date
3.1计划任务crontab -e 5点:30执行
vi /etc/crontab 0 5 * * * * root /opt/ftpmput.sh