apache日志分析-awstats

1、事先安装好Apache perl


2、安装awstats的命令(将awstats安装在/opt/awstats目录)
mkdir /var/lib/
wget http://prdownloads.sourceforge.net/awstats/awstats-6.95.tar.gz
tar zxvf awstats-6.95.tar.gz
mv awstats-6.95 /usr/local/awstats
cd /usr/local/awstats/tools/
perl awstats_configure.pl


3、Perl脚本awstats_configure.pl安装过程

[root@mail tools]# perl awstats_configure.pl 

----- AWStats awstats_configure 1.0 (build 1.8) (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
  Found Web server Apache config file '/usr/local/apache/conf/httpd.conf'

-----> Check and complete web server config file '/usr/local/apache/conf/httpd.conf'
Warning: You Apache config file contains directives to write 'common' log files
This means that some features can't work (os, browsers and keywords detection).
Do you want me to setup Apache to write 'combined' log files [y/N] ? y  使用combined格式的访问日志
  Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'
  Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"'
  Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"'
  Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"'
  Add '<Directory>' directive
  AWStats directives added to Apache config file.

-----> 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  创建一个awstats的配置文件

-----> 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:  输入配置文件名称
> 192.168.1.1

-----> 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):  输入配置文件的路径
> /usr/local/awstats

-----> Create config file '/usr/local/awstats/awstats.192.168.1.1.conf'
 Config file /usr/local/awstats/awstats.192.168.1.1.conf created.

-----> Restart Web server with '/sbin/service httpd restart'
httpd: unrecognized service

-----> 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=192.168.1.1
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: /usr/local/awstats/awstats.192.168.1.1.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for '192.168.1.1' with command:
> perl awstats.pl -update -config=192.168.1.1
You can also read your statistics for '192.168.1.1' with URL:
> http://localhost/awstats/awstats.pl?config=192.168.1.1

Press ENTER to finish...



4、修改awstats.sina.conf配置
vi /etc/awstats/awstats.sina.conf

按?,在之后输入要搜索的内容LogFile="
然后按Ins键,找到LogFile="/var/log/httpd/access_log"
改为要分析的Apache日志路径与文件名。

(1)多日志合并分析(例:两台服务器2月20日的日志30.20100220.log与31.20100220.log)
LogFile="/opt/awstats/tools/logresolvemerge.pl /var/apachelogs/30.20100220.log /var/apachelogs/31.20100220.log|"
LogFile="/opt/awstats/tools/logresolvemerge.pl /var/apachelogs/*.0206.vblog.log|"

(2)分析使用gzip压缩过的日志文件
LogFile="gzip -d </var/log/apache/access.log.gz|"

5、配置awstats数据目录
mkdir -p /var/lib/awstats
6、更新分析报告
perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=192.168.1.1 -update

如果出现以下错误提示,很大可能是Apache的Log文件中存在以前CustomLog /yourlogpath/yourlogfile common生成的日志,删除掉这些行的日志即可:
This means each line in your web server log file need to have "combined log format" like this:
111.22.33.44 - - [10/Jan/2001:02:14:14 +0200] "GET / HTTP/1.1" 200 1234 "http://www.fromserver.com/from.htm" "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"


7、查看分析报告
http://localhost/awstats/awstats.pl?config=192.168.1.1

这里的192.168.1.1对应/usr/local/awstats/awstats.192.168.1.1.conf 中的192.168.1.1

你可能感兴趣的:(apache,职场,休闲)