Chinaunix首页 | 论坛 | 博客
  • 博客访问: 669511
  • 博文数量: 220
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1961
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-04 21:54
文章分类

全部博文(220)

文章存档

2018年(1)

2015年(140)

2014年(79)

我的朋友

分类: 网络与安全

2015-01-09 14:15:21

1.首先修改nginx日志格式:
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                '$status $body_bytes_sent "$http_referer" '
                '"$http_user_agent" $http_x_forwarded_for';
 
2.安装awstats:
tar -zxvf awstats-7.0.tar.gz
mv awstats-7.0 /usr/local/awstats
cd /usr/local/
chmod 777 awstats/ -R
chown root:root awstats/ -R
awstats/
tools/awstats_configure.pl
选择:
Check for web server install  这项填none。
Define config file name to create  这项填配置文件名字,一般用域名。
其余默认即可。
 
3.修改建成的配置文件awstats.test.com.conf ,将LogFile=改成自己的日志路径


4.执行:perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=test.com
[root@test1 logs]# perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=test.com
Create/Update database for config "/etc/awstats/awstats.test.com.conf" by AWStats version 7.0 (build 1.969)
From data in log file "/opt/nginx/logs/access.log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 11
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 0 corrupted records,
 Found 0 old records,
 Found 11 new qualified records.
 
5.利用 awstats 的工具将统计的结果生成静态文件

[root@test1 logs]# perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=test.com -lang=cn -dir=/home/awstats -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
Launch update process : "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.zhaopin.com -update -configdir=
Build main page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.zhaopin.com -staticlinks -lang=cn -output
Build alldomains page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=alldomains
Build allhosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=allhosts
Build lasthosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=lasthosts
Build unknownip page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=unknownip
Build allrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=allrobots
Build lastrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=lastrobots
Build session page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=session
Build urldetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=urldetail
Build urlentry page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=urlentry
Build urlexit page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=urlexit
Build osdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=osdetail
Build unknownos page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=unknownos
Build browserdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=browserdetail
Build unknownbrowser page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=unknownbrowser
Build refererse page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=refererse
Build refererpages page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=refererpages
Build keyphrases page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=keyphrases
Build keywords page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=keywords
Build errors404 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=test.com -staticlinks -lang=cn -output=errors404
20 files built.
Main HTML page is 'awstats.test.com.html'.
 
6.nginx的配置:
        location ^~ /awstats/ {
        alias /usr/local/awstats/;
        index  awstats.gametuitui.com.html;
        access_log off;
        error_log off;
        charset gb2312;
        }

        location ^~ /awstatsicons/ {
        alias /usr/local/awstats/wwwroot/icon/;
        access_log off;
        error_log off;
        }
 

        location ~ ^/icon/ {
        root  /usr/local/awstats/wwwroot/;
        access_log off;
        error_log off;
        charset gb2312;
        }
   }
 
7.以下是测试时报错:
[root@test1 awstats]# perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=test.zhaopin.com
Error: AWStats database directory defined in config file by 'DirData' parameter (/var/lib/awstats) does not exist or is not writable.
Setup ('/etc/awstats/awstats.test.zhaopin.com.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).
解决:建一个awstats用于记录数据的目录
[root@test1 awstats]# mkdir /var/lib/awstats

8.如需按天自动分析,写nginx日志的自动分割脚本,并将awstats执行命令放入crontab中。相应修改配置中的LogFile=,改成"/opt/nginx/logs/access.%YYYY-0%MM-0?-0.log"即可。

9.搭建完成,使用访问即可。



解决关键字部分乱码:

修改配置文件awstats.xxx.conf

在配置文件中把decodeutfkeys这个plugin打开就可以了。在配置文件中找到:

 #LoadPlugin="decodeutfkeys"

然后重新生成html

[root@game awstats]# more /usr/local/bin/awstats.sh
perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=xxx.com
perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=xxx.com -lang=cn -dir=/usr/local/awstats  -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl


阅读(507) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~