Awstats Nginx日志分析工具
浏览量:5993
一、Awstats介绍
访问次数、独特访客人数,
访问时间和上次访问,
使用者认证、最近认证的访问,
每周的高峰时间(页数,点击率,每小时和一周的千字节),
域名/国家的主机访客(页数,点击率,字节,269域名/国家检测, geoip 检测),
主机名单,最近访问和未解析的 IP 地址名单
大多数看过的进出页面,
档案类型,
网站压缩统计表(mod_gzip 或者 mod_deflate),
使用的操作系统 (每个操作系统的页数,点击率 ,字节, 35 OS detected),
使用的浏览器,
机器人访问(检测 319 个机器人),
蠕虫攻击 (5 个蠕虫家族),
搜索引擎,利用关键词检索找到你的地址,
HTTP 协议错误(最近查阅没有找到的页面),
其他基于 URL 的个性报导,链接参数, 涉及综合行销领域目的.
贵网站被加入"最喜爱的书签".次数.
屏幕大小(需要在索引页补充一些 HTML 标签).
浏览器的支持比例: Java, Flash, RealG2 reader, Quicktime reader, WMA reader, PDF reader.
负载平衡服务器比率集群报告.
一种是通过cgi程序读取统计结果数据库输出(Linux中);
一种是运行后台脚本将输出导出成静态文件(Windows中);
二、部署搭建
2.1 下载安装包
[root@Awstats ~]# cd /usr/local/src/ [root@Awstats src]# wget http://awstats.sourceforge.net/files/awstats-7.2.tar.gz
2.2 解压及权限
[root@Awstats src]# tar xf awstats-7.2.tar.gz [root@Awstats src]# mv awstats-7.2 /usr/local/awstats [root@Awstats src]# chown -R root.root /usr/local/awstats [root@Awstats src]# chmod +x /usr/local/awstats/tools/*.pl [root@Awstats src]# chmod +x /usr/local/awstats/wwwroot/cgi-bin/*.pl
2.3 执行配置向导
[root@Awstats tools]# cd /usr/local/awstats/tools/
[root@Awstats tools]# perl awstats_configure.pl
----- AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur -----
…………
…………
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 ####因为用的是LNMP,没有apache,所以选”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:
> 192.168.56.13 ###此处可以填写域名,IP,虚拟主机,因为域名还没配置,此处我填写的IP,然后按回车
-----> 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
-----> Create config file '/etc/awstats/awstats.192.168.56.13.conf'
Config file /etc/awstats/awstats.192.168.56.13.conf created. ###生成了awstats配置文件
-----> 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.56.13 ###稍后需要把此命令添加到定时任务中,这样,awstats工具每天都会自动处理前一天的访问日志
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.192.168.56.13.conf ###新配置文件的存放路径
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for '192.168.56.13' with command:
> perl awstats.pl -update -config=192.168.56.13 ###更新日志分析的命令
You can also build static report pages for '192.168.56.13' with command:
> perl awstats.pl -output=pagetype -config=192.168.56.13 ###输出分析结果的命令
Press ENTER to finish... ###按回车完成配置2.4 修改配置文件
[root@Awstats tools]# sed -i 's#LogFile="/var/log/httpd/mylog.log"#LogFile="/home/wwwlogs/%YYYY-0%MM-0%dd_access.log"#g' /etc/awstats/awstats.192.168.56.13.conf ###此处为修改日志格式,此处日志格式应与nginx日志格式一致 DirData="/var/lib/awstats" ### 指定统计的数据文件的存放位置 tats/tools/icon/ /home/wwwlogs/tools/
2.5 创建awstats数据存放目录
[root@Awstats tools]# mkdir /var/lib/awstats
2.6 分析日志
[root@Awstats tools]# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=192.168.56.13 Create/Update database for config "/etc/awstats/awstats.192.168.56.13.conf" by AWStats version 7.0 (build 1.971) From data in log file "/home/wwwlogs/20160603_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: 91 Found 37 dropped records, Found 0 comments, Found 0 blank records, Found 1 corrupted records, Found 0 old records, Found 53 new qualified records.
执行完成后,会在/var/lib/awstats/下生成TXT格式的数据文件
[root@Awstats awstats]# cd /var/lib/awstats/ [root@Awstats awstats]# ll total 8 -rw-r--r-- 1 root root 6646 Jun 3 11:35 awstats062016.192.168.56.13.txt
2.7 生成静态页面查看
[root@Awstats tools]# mkdir /www/awstats [root@Awstats tools]# /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=192.168.56.13 -lang=cn -dir= /www/awstats -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
输出如下,则说明创建静态页面成功
Launch update process : "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=192.168.56.13 -update -configdir= Build main page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=192.168.56.13 -staticlinks -lang=cn -output Build alldomains page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=192.168.56.13 -staticlinks -lang=cn -output=alldomains Build allhosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=192.168.56.13 -staticlinks -lang=cn -output=allhosts ………. ………. Build errors404 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=192.168.56.13 -staticlinks -lang=cn -output=errors404 20 files built. Main HTML page is 'awstats.192.168.56.13.html'. ###已经生成静态页面
参数详解:
/usr/local/awstats/tools/awstats_buildstaticpages.pl #### Awstats 静态页面生成工具
-update -config=192.168.56.13 ####更新配置项
-lang=cn ####指定生成页面的语言问中文
-dir=/home/wwwlogs/tools/awstats ####指定统计结果输出目录
-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl ###Awstats 日志更新程序存放路径
2.8 设置访问权限
[root@Awstats tools]# mkdir /usr/local/nginx/httpwd [root@Awstats tools]# htpasswd -c /usr/local/nginx/httpwd/awstats webadmin -bash: htpasswd: command not found 因为此功能需要依赖httpd服务,安装好httpd服务后即可解决,无需启动httpd服务 [root@Awstats ~]# htpasswd -c /usr/local/nginx/httpwd/awstats webadmin New password: sousou1904 Re-type new password: sousou1904 Adding password for user webadmin
2.9 nginx.conf配置
location ~ ^/tools/awstats/ {
access_log off;
error_log off;
charset gb2312;
auth_basic "192.168.56.13-AWStats login";
auth_basic_user_file /usr/local/nginx/httpwd/awstats;
}浏览器查看:192.168.56.13/tools/awstats/awstats.192.168.56.13.html
来源:sousoushenbian运维工程师提供

神回复
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。