awstats来来回回也装了好多遍了,每次都是现装现查,隐约的记得整个配置比较麻烦,中间有几个需要特别注意的地方,又记不得那些需要特殊对待,只能边找资料边回忆,最终还是搞出来了,在此分享给大家。

首先去官网下载最新的安装包。

wget http://jaist.dl.sourceforge.net/project/awstats/AWStats/7.3/awstats-7.3.zip
unzip awstats-7.3.zip
cd awstats-7.3

查看下配置结构

[root@localhost awstats-7.3]# ls
docs README.TXT tools wwwroot
[root@localhost awstats-7.3]# tree -d
.
├── docs
│   ├── images
│   └── scripts
├── tools
│   ├── nginx
│   ├── webmin
│   └── xslt
└── wwwroot
├── cgi-bin
│   ├── lang
│   │   ├── tooltips_f
│   │   ├── tooltips_m
│   │   └── tooltips_w
│   ├── lib
│   └── plugins
│   └── example
├── classes
│   └── src
├── css
├── icon
│   ├── browser
│   ├── clock
│   ├── cpu
│   ├── flags
│   ├── mime
│   ├── os
│   └── other
└── js directories
[root@localhost awstats-7.3]#     

进入tools目录找到awstats_configure.pl 文件并且运行,它是一个向导,可以根据它的指示创建一个配置文件。 

-----> 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 #因为我们这里用的是 Nginx,所以写 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 #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:
#> www.moabc.net #统计网站的域名 例:www.xxx.com
-----> Define config file path
----> 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=www.moabc.net
#回头把该命令填入crontab 按指定时间执行
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.www.moabc.net.conf
#新配置文件所在的路径
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.moabc.net' with command:
> perl awstats.pl -update -config=www.moabc.net
You can also build static report pages for 'www.moabc.net' with command:
> perl awstats.pl -output=pagetype -config=www.moabc.net Press ENTER to finish...
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): #>

回车完成向导,接下来修改 www.xxx.com 的统计配置.

一般情况这个文件的位置是/etc/awstats目录下,文件名为awstats.www.xxx.com.conf。

这里面主要修改几个地方

LogFile="/var/log/httpd/mylog.log"

改为

LogFile="/opt/nginx/logs/access_%YYYY-0%MM-0%DD-0.log

然后保存,后续需要修改的地方咱们一会再说。

接下来就可以生产txt文件了,运行命令

[root@localhost wwwroot]# cd /home/awstats-7.3/wwwroot/cgi-bin/
[root@localhost cgi-bin]# ls
awdownloadcsv.pl awredir.pl awstats-fcgi.php awstats.model.conf awstats.pl lang lib plugins
[root@localhost cgi-bin]# ./awstats.pl -update -config=www.megaunity.com
Create/Update database for config "/etc/awstats/awstats.www.megaunity.com.conf" by AWStats version 7.3 (build 20140126)
From data in log file "/home/log/nginx/access_20140714.log"...
Phase 1 : First bypass old records, searching new record...
Direct access after last parsed record (after line 220965)
Jumped lines in file: 220965
Found 220965 already parsed records.
Parsed 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.
[root@localhost cgi-bin]#


可以看到我是通过awstats.pl文件生产的数据文件,该文件位置在/var/lib/awstats下面。

[root@localhost cgi-bin]# ls /var/lib/awstats/
awstats072014.www.megaunity.com.txt

这个awstats072014.www.xxx.com.txt就是生产的数据库文件,但是咱们怎么能浏览浏览它呢,我通过很多博客的文章来搭建这个nginx环境下使用awstats,但是我浏览的所有博客都是通过awstats安装目录下一个自带的perl文件awstats_buildstaticpages.pl来生成静态页面浏览,每个博客都互相抄袭,都说nginx对perl支持不好。其实“当年”搭建awstats的前辈可能确实遇到了nginx对perl支持不好的问题,但是这么多年过去了,软件一直在不断更新,awstats已经可以像在apache下那样直接浏览url:http://awstats.cs.yilian.cc/cgi-bin/awstats.pl?config=www.xxx.com。

这是什么?打开看一下?

[root@localhost awstats-7.3]# cat tools/nginx/awstats-nginx.conf
server {
listen 127.0.0.1:;
server_name localhost;
access_log /var/log/nginx/localhost.access_log main;
error_log /var/log/nginx/localhost.error_log info;
root /var/www/localhost/htdocs;
index index.html; # Restrict access
#auth_basic "Restricted";
#auth_basic_user_file /etc/awstats/htpasswd; # Static awstats files: HTML files stored in DOCUMENT_ROOT/awstats/
location /awstats/classes/ {
alias /usr/share/awstats/wwwroot/classes/;
} location /awstats/css/ {
alias /usr/share/awstats/wwwroot/css/;
} location /awstats/icon/ {
alias /usr/share/awstats/wwwroot/icon/;
} location /awstats-icon/ {
alias /usr/share/awstats/wwwroot/icon/;
} location /awstats/js/ {
alias /usr/share/awstats/wwwroot/js/;
} # Dynamic stats.
location ~ ^/cgi-bin/(awredir|awstats)\.pl {
gzip off;
fastcgi_pass 127.0.0.1:;
fastcgi_param SCRIPT_FILENAME /usr/share/awstats/wwwroot/cgi-bin/fcgi.php;
fastcgi_param X_SCRIPT_FILENAME /usr/share/awstats/wwwroot$fastcgi_script_name;
fastcgi_param X_SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
}
}
[root@localhost awstats-7.3]# cat tools/nginx/awstats-fcgi.php
<?php
$descriptorspec = array(
=> array('pipe', 'r'), // stdin is a pipe that the child will read from
=> array('pipe', 'w'), // stdout is a pipe that the child will write to
=> array('pipe', 'w') // stderr is a file to write to
); $newenv = $_SERVER;
$newenv['SCRIPT_FILENAME'] = $_SERVER['X_SCRIPT_FILENAME'];
$newenv['SCRIPT_NAME'] = $_SERVER['X_SCRIPT_NAME']; if (is_executable($_SERVER['X_SCRIPT_FILENAME'])) {
$process = proc_open($_SERVER['X_SCRIPT_FILENAME'], $descriptorspec, $pipes, NULL, $newenv); if (is_resource($process)) {
fclose($pipes[]);
$head = fgets($pipes[]); while (strcmp($head, "\n")) {
header($head);
$head = fgets($pipes[]);
} fpassthru($pipes[]);
fclose($pipes[]);
fclose($pipes[]); $return_value = proc_close($process);
} else {
header('Status: 500 Internal Server Error');
echo('Internal Server Error');
}
} else {
header('Status: 404 Page Not Found');
echo('Page Not Found');
}

我看到了一个php文件和一个nginx配置文件,不用说,很明显是模板。我想如果不支持为什么要给模板呢。我打开了配置文件看了一下,发现awstats把fcgi给了9000端口,这不就是php-fpm么?我突然觉的,是不是nginx不能像apache那样直接处理perl但是他能处理php啊,这个php文件就应该就是实现了awstats.pl一样的功能。

修改了fastcgi_param SCRIPT_FILENAME上下两行的awstats-fcgi.php的位置,并把它拷贝到cgi-bin/目录下,配置文件复制到相应的nginx配置文件目录下。重载nginx,访问下试试。

你会发现可以通过http://awstats.cs.yilian.cc/cgi-bin/awstats.pl?config=www.xxx.com这种形式正常访问了对不对。

配置文件的调整

以往我们都是通过awstats_configure.pl想到去创建配置文件,殊不知我们可以通过模板文件去拷贝然后使用include来引出模板配置文件,如我的配置文件如下

[root@localhost awstats]# ls
awstats.www.xxx.com.conf awstats.www.xxx.com.conf awstats.xxx.cc.conf common.conf

common.conf就是我的模板文件。

[root@localhost awstats]# cat awstats.www.xxx.com.conf
Include "common.conf"
LogFile="/home/log/nginx/access_%YYYY-0%MM-0%DD-24.log"
SiteDomain="www.xxx.com"
DirData="/var/lib/awstats"
[root@localhost awstats]#

这样方便管理 每个配置文件也不大。

修改模板配置,是awstats中文乱码恢复。

通过网上的文章介绍需要修改配置文件选项:#LoadPlugin="decodeutfkeys",打开该选项取消注释。

但是会发生报错:

Error: Plugin load for plugin 'decodeutfkeys' failed with return code: Error: Can't locate URI/Escape.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl . /usr/share/awstats/lib /usr/share/awstats/plugins) at (eval 3) line 1.
Setup ('/etc/awstats/awstats.bbsnuaa.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).
wget http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/URI-1.36.tar.gz

解压缩文件
tar zxvf URI-1.36.tar.gz 进入解压缩后目录
cd URI-1.36 然后 perl Makefile.PL
make
make install

报错继续,然后使用另一种方法

安装URI/Escape模块

一种是通过perl shell网络安装:

[root@localhost cgi-bin]# perl -MCPAN -e 'install Encode'
Can't locate CPAN.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).
BEGIN failed--compilation aborted.

缺少CPNA,然后下载CPNA

wget http://www.cpan.org/authors/id/A/AN/ANDK/CPAN-1.9600.tar.gz

tar -zxvf CPAN-1.9600.tar.gz

cd CPAN-1.9600

perl Makefile.PL

[root@localhost URI-1.60]# perl Makefile.PL
Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 2.

还是报错,前前后后发现这个perl太费劲了,少了好多东西,没办法只好一个个安装。

yum install perl-Time-HiRes

最后执行以下三部恢复。

perl -MCPAN -e 'install Encode'
perl -MCPAN -e 'install URI::Escape'

root@server ~]# perl -MCPAN -e shell

>install URI::Escape
解决乱码问题。

安装QQ纯真地址库

通过车东的博客学习到了安装QQ地址库的方法,但是安装过程相当惨烈啊。

安装如下:

把 qqhostinfo.pm,QQWry.dat,qqwry.pl三个文件拷贝到/home/awstats-7.3/wwwroot/cgi-bin/plugins下面
然后修改qqwry.pl文件,把里面的路径修改正确。
my $ipfile="${DIR}/plugins/qqwry.dat"
注意${DIR}指定路径是什么,对应了的安装路径。
然后再执行 vim defualt.conf(之前的模板配置文件)
添加:LoadPlugin="qqhostinfo"

到此QQ地址库算是安装完成了。

安装国家地理插件

 因为我之前安装过,所以我就之前现在配置文件添加了插件信息。
所以我还是直接修改模板配置文件default.conf添加插件信息
LoadPlugin="geoip GEOIP_STANDARD /home/awstats-7.3/wwwroot/cgi-bin/GeoIP.dat"
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /home/awstats-7.3/wwwroot/cgi-bin/GeoLiteCity.dat"
这里我参考了http://blog.csdn.net/kumu_linux/article/details/8146958的博客
需要的安装包如下:
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
然后把两个文件移入/home/awstats-7.3/wwwroot/cgi-bin目录中gunzip解压即可。

GeoIP安装步骤如下:

先下载GeoIP C库:

去https://www.maxmind.com/download/geoip/api/c/下载GeoIP-1.4.8.tar.gz

# tar xf GeoIP-1.4.8.tar.gz

cd进入解压目录,执行如下操作安装

# ./configure ; make && make install 

接下来下载GeoIP perl库:

去https://www.maxmind.com/download/geoip/api/perl/下载Geo-IP-1.40.tar.gz

# tar xf Geo-IP-1.40.tar.gz

cd 进入解压目录,执行如下操作安装

perl Makefile.PL LIBS='-L/usr/local/lib' 

//这里必需使用这种方法安装,笔者尝试把/usr/local/lib加入/etc/ld.so.conf.d/geoip.conf并执行ldconfig,单独执行perl Makefile.PL还是发现不了GeoIP的C库,所以只能以perl Makefile.PL LIBS='-L/usr/local/lib' 这种方式执行

# make && make install

 rm -rf /var/lib/awstats/* #删除旧的统计数据

/usr/local/awstats/tools/awstats_updateall.pl now

重新生成数据即可,查看监控页面就可以获取来访者的国家和地区了

这里面主要容易犯的错误就是发现不了GeoIP的C库,啥事GEOIP的C库 就是之前安装的GeoIP-1.4.8.tar.gz 这个东西,这个东西安装之后你会发现如下目录里面会多出东西

 [root@localhost plugins]# ls /usr/local/lib/
libGeoIP.a libGeoIP.la libGeoIP.so libGeoIP.so. libGeoIP.so.1.4. libGeoIPUpdate.a libGeoIPUpdate.la libGeoIPUpdate.so libGeoIPUpdate.so. libGeoIPUpdate.so.0.0.
[root@localhost plugins]#
这些文件就是正确安装了C库出来的东西,如果没有 那么说明你C库安装不成功 ,建议查看是不是服务器少了支持perl的包,或者gcc这些基础的东西。

  参考文档:http://blog.csdn.net/kumu_linux/article/details/8146958

       http://www.chedong.com/tech/awstats.html

nginx+awstats安装过程的更多相关文章

  1. CentOS7离线安装Nginx(详细安装过程)

    CentOS7离线安装Nginx(详细安装过程) 1.安装gcc.g++ 下载好所需的文件后上传至服务器(下载地址:https://download.csdn.net/download/a729360 ...

  2. Nginx & AWStats 安装、配置、使用

    —— 参考IBM文章:THIS , 不一样的指导顺序 —— 1. awstats分析nginx - access.log,网上资料大部分都是下载,然后配置.官网下载地址: http://awstats ...

  3. Nginx在安装过程经常出现的问题

    在Linux操作系统下搭建Nginx服务器,很多时候会出现不同的错误,在此我们在搭建过程中出现的错误进行一些总结: 主要问题有: 1.防火墙问题 2.缺少gc++ 3.缺少pcre.zlib库 解决办 ...

  4. centos 7.0 PHP 5.6.5 安装过程 (php+nginx)

    php网址 http://php.net/downloads.php 首先下载 php-5.6.5.tar.gz [root@localhost src]# wget http://cn2.php.n ...

  5. nginx安装过程,报错处理:make[1]: *** [objs/addon/src/bson.o] Error 1

    nginx安装过程中,经常会有各种错误: 具体安装步骤这里不做说明,网上一搜大把: 主要分析安装过程中遇到的问题 在make编译的时候,若报如下错误: cc1: warnings being trea ...

  6. linux环境中,nginx安装过程

    需求描述: 记录在linux平台,nginx安装的过程. 环境描述: 操作系统:Red Hat Enterprise Linux Server release 6.6 (Santiago) 操作内核版 ...

  7. Ubuntu12.04 安装nginx和mongo过程

    1.安装php和php-cgi apt-get install php5 php5-cgi 2.安装 nginx apt-get install nginx 3.安装 MongoDB apt-get ...

  8. LNMP安装过程

    LNMP一键安装包是什么? LNMP一键安装包是一个用Linux Shell编写的可以为CentOS/RadHat/Fedora.Debian/Ubuntu/Raspbian/Deepin VPS或独 ...

  9. centos 系统下安装FastDFS+nginx+fastdfs-nginx-module安装配置

    前言: 以前的项目上传的文件都是保存到本地或者是局域网内的共享文件夹下,由于数据量,服务器的负载均衡(分机的某些图片无法访问的问题处理)等因素的情况下,就想到用fastdfs来文件管理,花了几天时间硬 ...

随机推荐

  1. OSGI命令

    OSGi的一些支离破碎的知识 以下命令说明内容来自于Eclipse的OSGi框架Equinox. ---Controlling the OSGi framework---launch - start ...

  2. 【C++ Primer | 15】构造函数与拷贝控制

    合成拷贝控制与继承 #include <iostream> using namespace std; class Base { public: Base() { cout << ...

  3. [转] iOS开发工具——网络封包分析工具Charles

    简介 Charles是在Mac下常用的截取网络封包的工具,在做iOS开发时,我们为了调试与服务器端的网络通讯协议,常常需要截取网络封包来分析.Charles通过将自己设置成系统的网络访问代理服务器,使 ...

  4. AOJ 0009 Prime Number

    题意:给出n,求不大于n的素数有多少个. 算法:先用线性时间复杂度的筛法打素数表,对于每个输入统计不超过的素数个数. #include <cstdio> int p[100010]; bo ...

  5. NDK 开发实例一(Android.mk环境配置下)

         在我写这篇文章的时候,Android Studio已经是2.3版本了,已经集成CMake 编译工具, 用户只需在 新建项目的时候,添加选项(Include C++ support),Andr ...

  6. Educational Codeforces Round 26 E - Vasya's Function

    数论题还是好恶心啊. 题目大意:给你两个不超过1e12的数 x,y,定义一个f ( x, y ) 如果y==0 返回 0 否则返回1+ f ( x , y - gcd( x , y ) ); 思路:我 ...

  7. Jquery框架1.选择器|效果图|属性、文档操作

    1.JavaScript和jquery的对比 书写繁琐,代码量大 代码复杂 动画效果,很难实现.使用定时器 各种操作和处理 <!DOCTYPE html> <html lang=&q ...

  8. (转)java面试总结-(hibernate ibatis struts2 spring)

    说说Hibernate对象的三种状态 Hibernate对象有三种状态,分别是:临时态(Transient). 持久态(Persistent).游离态(Detached). 临时状态:是指从对象通过n ...

  9. UVA 11426 (欧拉函数&&递推)

    题意:给你一个数N,求N以内和N的最大公约数的和 解题思路: 一开始直接想暴力做,4000000的数据量肯定超时.之后学习了一些新的操作. 题目中所要我们求的是N内gcd之和,设s[n]=s[n-1] ...

  10. 洛谷 p1044 栈 【Catalan(卡特兰数)】【经典题】

    题目链接:https://www.luogu.org/problemnew/show/P1044 转载于:https://www.luogu.org/blog/QiXingZhi/solution-p ...