设为首页 收藏本站
查看: 2794|回复: 1

[经验分享] awstats的安装和配置

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-11-10 08:44:00 | 显示全部楼层 |阅读模式
1、下载awstats软件
链接地址:https://prdownloads.sourceforge.net/awstats/awstats-7.5.tar.gz
QQ截图20161110084241.png
2、安装
将下载的软件直接放到/usr/local/下解压,改名成awstats

2、生成配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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 字符串中间有空格的问题,所以在处理日志的时候给这两个字段加了中括号处理
处理日志的语句如下:
1
awk -F'|' '{print $3" "$12" "$5" "$14" "$11" ""["$2"]"" ""["$13"]”}’access.log >access_20161101.log



有了日志格式我们就可以去修改awstats对应域名的日志格式了
1
2
3
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就可以了。
1
LogFile="/data/awstats/logs/www/combine/access_%YYYY-24%MM-24%DD-24.log”



#生成分析完的结果目录
1
DirData="/data/awstats/web”



#确认域名,如果是生成的配置文件,只要域名写对了,这地方就没什么问题,如果是从其他配置文件copy过来就需要记得修改下面这两项
1
2
SiteDomain="www.xxxx.com”
HostAliases="xxxx.com www.xxxx.com 127.0.0.1 localhost”



#如果同一个域名有多个nginx的日志需要合并可以使用awstats自带的工具/usr/local/awstats/tools/logresolvemerge.pl
使用方法:
1
logresolvemerge.pl access1.log access2.log accessN.log >access_20161109.log



因我这是让awstats的CGI来处理分析结果所以需要安装perl的FCGI和FCI-ProcManager来支持
4、perl支持的FCGI和FCGI-ProcManager的安装
QQ截图20161110084249.png
    install FCGI::ProcManger
QQ截图20161110084257.png

启动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的域名配置文件中的一行
1
2
将LoadPlugin=“hostinfo"
修改成LoadPlugin=“qqhostinfo"



如果本身是注释的,请将注释去掉
效果图:
QQ截图20161110084303.png
6、nginx配置
新建一个虚拟主机
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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同级目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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、自动处理日志文件
每天会在凌晨将昨天日志取过来后处理完毕存放在配置文件设置的目录中,然后执行
1
/usr/local/awstats/tools/awstats_updateall.pl now



或者:
1
2
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.
xxxx.com




将这个处理的脚本放入crontab中
QQ截图20161110084318.png

我这的处理脚本如下:仅供参考
QQ截图20161110084309.png
8、访问
可以在浏览器输入你在nginx配置的IP或者域名来访问
http://youdomain/cgi-bin/awstats.pl?config=www.xxx.com,多个不同域名就修改地址栏的config段

QQ截图20161110084322.png


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-298228-1-1.html 上篇帖子: AWStats日志分析工具 下篇帖子: 我的aws安装好了,可是却出不来数据呢,
累计签到:70 天
连续签到:1 天
发表于 2016-11-14 09:00:17 | 显示全部楼层
感谢分享啊

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表