AWStats是一个免费、功能强大、特性丰富的日志分析工具,它能分析由WEB、STREAMING、FTP、MAIL等服务生成的日志,并生成先进的统计图表。AWStats作为CGI或从命令行运行,在数个图形网页中显示你日志中包含的所有可能信息。它利用一部分档案资料就能经常很快地处理大量日志档案。它能分析的日志文件来自从各大服务器工具,如 Apache日志文件 (NCSA combined/XLF/ELF log format or common/CLF log format)、WebStar、IIS (W3C日志格式)及许多其他Web、Proxy(代理服务器)、Wap、流服务器、邮件服务器和一些FTP服务器。
- 安装 Awstats
Awstats 是由perl语言编写的,所以要首先准备好awstats的运行环境。
yum install –y perl*
2.下载awstats工具。
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.安装awstats
(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 ---执行该命令
安装过程:
----- 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.com
Press ENTER to finish...
解释:
awstats生成的目录
安装目录 /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.tiandaoedu.com.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://tiandaoedu.com/"
检索页面信息
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.tiandaoedu.com --单个站点刷新数据
接下来生成报告的详细子页面,需要在命令行下通过output参数指定报告的名字,命令如下:
perl awstats.pl -config=mysite -output=alldomains -staticlinks > awstats.mysite.alldomains.html
在生成html文件后生成一个PDF文件,报告的输出目录必须包括图标目录。
本文示例:
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=www.tiandaoedu.com -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.tiandaoedu.com -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生成图片
二、安装和配置 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( // site1 网站域名(注意不能乱填)
"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.tiandaoedu.com",
"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 /zzxtbl "/usr/local/jawstats"
<Directory "/usr/local/jawstats">
Options Indexes MultiViews
Order allow,deny
Allow from all
</Directory>
网站访问 http://192.168.250.190/zzxtbl