1、下载awstats软件

链接地址:https://prdownloads.sourceforge.net/awstats/awstats-7.5.tar.gz

2、安装

将下载的软件直接放到/usr/local/下解压,改名成awstats

2、生成配置文件

cd /usr/local/awstats/tools
./awstats_configure.pl
----- AWStats awstats_configure 1.0 (build 20140126) (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 (此处如果是apache就写上apache的配置文件路径,我用的是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
-----> 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.xxx.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):
> /etc/awstats (此处写上你要存放awstats的配置文件的路径,一般都放在/etc/awstats,如果自定义在后面分析的时候会找不到配置文件)
-----> Create config file '/etc/awstats/awstats.www.xxxx.com.conf'
Config file /etc/awstats/awstats.www.xxxx.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=www.xxxx.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.www.xxxx.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.xxxx.com' with command:
> perl awstats.pl -update -config=www.xxxx.com
You can also build static report pages for 'www.xxxx.com' with command:
> perl awstats.pl -output=pagetype -config=www.xxxx.com
Press ENTER to finish…

完成后,配置文件就生成了。如果有多个域名需要分析,就多执行几次,每个域名对应一个配置文件

3、日志格式处理及awstats配置文件的修改

因为我这nginx的日志格式是自定义的格式,写的比较多,所以分析的时候就处理下格式,只取了不部分日志

取值的字段:$remote_addr  $request $status  $body_bytes_sent  $http_referer  $time_local $http_user_agent

因为$time_local和$http_user_agent 字符串中间有空格的问题,所以在处理日志的时候给这两个字段加了中括号处理

处理日志的语句如下:

awk -F'|' '{print $3" "$12" "$5" "$14" "$11" ""["$2"]"" ""["$13"]”}’access.log >access_20161101.log

有了日志格式我们就可以去修改awstats对应域名的日志格式了

vim /etc/awstats/awstats.www.xxxx.com.conf
LogFormat = "%host %method %url %other %code %bytesd %referer %time1 %uabracket”
LogSeparator=“” #按默认空格分隔

还有需要修改的地方是:

#存放log的路径,最后%YYYY-24%MM-24%DD-24代表是当前日期的前一天,今天是20161109,那此处转换后就是20161108,如果要取当天的日志文件,把-24改成-0就可以了。

LogFile="/data/awstats/logs/www/combine/access_%YYYY-24%MM-24%DD-24.log”

#生成分析完的结果目录

DirData="/data/awstats/web”

#确认域名,如果是生成的配置文件,只要域名写对了,这地方就没什么问题,如果是从其他配置文件copy过来就需要记得修改下面这两项

SiteDomain="www.xxxx.com”
HostAliases="xxxx.com www.xxxx.com 127.0.0.1 localhost”

#如果同一个域名有多个nginx的日志需要合并可以使用awstats自带的工具/usr/local/awstats/tools/logresolvemerge.pl

使用方法:

logresolvemerge.pl access1.log access2.log accessN.log >access_20161109.log

因我这是让awstats的CGI来处理分析结果所以需要安装perl的FCGI和FCI-ProcManager来支持

4、perl支持的FCGI和FCGI-ProcManager的安装

install FCGI::ProcManger

启动fcgi来支持CGI的解析

从网上下载了fcgi的脚本,nginx调用cgi的时候我用的是ip地址方式连接,所以将文件中$socket = FCGI::OpenSocket( "127.0.0.1:8999", 10 );的注释去掉了,将 #$socket = FCGI::OpenSocket( "/usr/local/awstats/perl_cgi-dispatch.sock", 10 );给注释,如果是使用unix套接字来访来访问就掉个个就可以。

启动/usr/local/awstats/fcgi &

查看是否启动:netstat -ntpl|grep 8999

5、QQ纯真库支持显示来访IP的地理位置信息

从网上找得三个文件qqhostinfo.pm qqwry.dat qqwry.pl,将这三个文件存放在/usr/local/awstats/wwwroot/cgi-bin/plugins下,然后修改awstats的域名配置文件中的一行

将LoadPlugin=“hostinfo"
修改成LoadPlugin=“qqhostinfo"

如果本身是注释的,请将注释去掉

效果图:

6、nginx配置

新建一个虚拟主机

server{listen 80;server_name 10.0.0.xxx; #或者是访问的域名,我这用的ip地址来访问的location / {root /data/awstats/web/;index index.html index.htm;access_log logs/access.log;}location ~* ^/cgi-bin/.*\.pl$ {include awstats.conf; #此处我是直接加载一个配置文件来处理的,具体配置见下面}location ~ ^/icon/{root /usr/local/awstats/wwwroot;index index.html;charset gb2312;}
}

awsstats.conf 存放路径是:nginx的配置文件目录conf下,和nginx.conf同级目录

fastcgi_pass 127.0.0.1:8999;
fastcgi_index awstats.pl;
fastcgi_param SCRIPT_FILENAME /usr/local/awstats/wwwroot/cgi-bin/awstats.pl;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_read_timeout 60;

7、自动处理日志文件

每天会在凌晨将昨天日志取过来后处理完毕存放在配置文件设置的目录中,然后执行

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

或者:

/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.
xxxx.com

将这个处理的脚本放入crontab中

我这的处理脚本如下:仅供参考

8、访问

可以在浏览器输入你在nginx配置的IP或者域名来访问

http://youdomain/cgi-bin/awstats.pl?config=www.xxx.com,多个不同域名就修改地址栏的config段

转载于:https://blog.51cto.com/joeyang/1870974

awstats的安装和配置相关推荐

  1. awstats mysql_AWstats7.4在Windows 10 64位下的安装与配置,以支持Apache 2.4的日志分析...

    1.AWstats7.4在Windows 10 64位下的安装与配置,以支持Apache 2.4的日志分析: 2.安装perl,打开:https://www.perl.org/ ,如图1,在Windo ...

  2. Maven安装与配置(最实用!!!)eclipse中配置maven

    Maven安装与配置 一.需要准备的东西 JDK Eclipse(本章主要是在eclipse中进行配置maven) Maven程序包 二.下载与安装 1. 前往maven下载最新版的Maven程序: ...

  3. Portainer 安装与配置

    文章目录 Portainer 安装与配置 一.介绍 二.安装使用 1.单机运行 2.基于swarm集群方式运行 Portainer 安装与配置 一.介绍 ​ Portainer 是一个开源.轻量级Do ...

  4. Myeclipse安装、配置、测试

    Myeclipse安装.配置.测试(win7_64bit) 目录 1.概述 2.本文用到的工具 3.安装与激活 4.JavaSE开发测试(确保JDK已正确安装) 5.JavaEE开发测试(确保服务器和 ...

  5. [网摘学习]在Ubuntu上安装和配置OpenStack Nova之二

    再收藏一份Openstack的文章,这两天的操作与此相同.但其中出现的问题还需要查找原因.待个人继续学习研究. 原文参考:http://www.linuxde.net/2011/11/1599.htm ...

  6. centos6.5 php5.2,Linux中PHP安装与配置(CentOS-6.5:php-5.2.13)

    1 PHP简介     PHP(PHP: Hypertext Preprocessor的缩写,中文名:"超文本预处理器")是一种通用开源脚本语言.语法吸收了C语言.Java和Per ...

  7. java jdk 1.8 安装_下载、安装、配置 java jdk1.8

    近期配置react native的开发环境,所以就从配置环境开始.rn的环境配置有那么几项,其中重要的一个就是java jdk(Java Development Kit 的缩写),那么以下就是下载.安 ...

  8. mysql安装好需要优化配置一下_Mysql的安装、配置、优化

    Mysql的安装.配置.优化 安装步骤 1.先单击中的安装文件,如果是win7系统,请选择以管理员的方式运行. 2.大概需要30秒的时间,开始进入安装界面.请先把标红的打勾,好进行下一步的动作. 3. ...

  9. windows下opencv安装及配置(vs2010环境)

    opecv下载 前往官方下载地址 https://opencv.org/releases/ opencv安装及配置 解压,会得到一个opencv文件夹,可将提取出的文件移动到任意位置,我将其放在F盘. ...

最新文章

  1. 基于html5海贼王单页视差滚动特效
  2. 把eclipse从英文调整为中文
  3. 【组队学习】【32期】Linux实践
  4. 2019.03.13 ZJOI2019模拟赛 解题报告
  5. Flask的闪现(message) 请求扩展 中间件 蓝图
  6. 打工人一次性考过高项的备考指南(52.50.50)
  7. 巧用css text-indent减小中文标点符号的占位大小
  8. [CF475E]Strongly Connected City 2
  9. 基于bboss开发平台eclipse开发工程生成工具介绍
  10. 解析 WordPress 插件机制
  11. 祁飞机器人_转自祈飞:什么是智能机器人
  12. 如何查找rpm方式安装的软件路径
  13. 异常:Caused by: java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z
  14. [必看]首先要求做到的事情![sumtec]
  15. Janusec WAF网关安装体验
  16. 不搞数字货币的科技巨头们,在区块链的布局上有这三个方向
  17. 原生js 修改html,原生JS改变HTML内容
  18. kali解压deb_Kali下安装网易云音乐
  19. 常见机器视觉软件OpenCV/Halcon/VisionPro/MIL的区别
  20. 电竞级还带主动降噪,莱仕达X2无线蓝牙耳机实测,品控值得安利

热门文章

  1. oracle recyclebin详解,oracle recyclebin详解
  2. PHP exec xargs 不执行,关于 ‘--exec’ 参数( find 命令)及介绍 ‘xargs ’命令区别(新版)...
  3. java 投票ip限制_java 限定网站在指定IP段访问
  4. mysql jdbc简介_JDBC简介
  5. wsdl2java 工具下载_利用wsdl2java工具生成webservice的客户端代码
  6. Verilog初级教程(7)Verilog模块例化以及悬空端口的处理
  7. 【 FPGA 】总线实现形式之选择器
  8. CentOS 6.5使用yum快速搭建LAMP环境
  9. 自己封装JSTL 自定义标签
  10. ssh开启root用户登录