老谢博客

  • 首页
  • WordPress
  • 网络技术
  • 乱七八糟
  • 运维技术
  • 给我留言
  • 关于老谢

LNMP安装AWStats分析日志

分类:linux日期:2014-09-23 - 19:37:29作者:老谢

只用vnstat来统计vps的流量,但是这个只能统计整个vps的网卡流量,统计不到具体的网站流量,于是就想到了安装awstats来统计具体的网站流量,下面记录配置过程:

首先修改nginx的日志格式,修改/usr/local/nginx/conf/vhost/域名,

log_format  www.xj123.info  '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

log_format www.xj123.info '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';

下面两行命令是nginx的日志切割脚本:

mv /home/wwwlogs/xj123.info.log /home/wwwlogs/xj123.info_`date +%Y%m%d`.log
killall –s USR1 nginx #使用USR1参数通知Nginx进程切换日志文件

mv /home/wwwlogs/xj123.info.log /home/wwwlogs/xj123.info_`date +%Y%m%d`.log killall –s USR1 nginx #使用USR1参数通知Nginx进程切换日志文件

确定日志格式没有问题之后,下面开始安装awstats:

wget http://softlayer-sng.dl.sourceforge.net/project/awstats/AWStats/7.3/awstats-7.3.zip
unzip awstats-7.3.zip
mv awstats-7.3 /usr/local/awstats
cd /usr/local/awstats/tool/
perl awstats_configure.pl

wget http://softlayer-sng.dl.sourceforge.net/project/awstats/AWStats/7.3/awstats-7.3.zip unzip awstats-7.3.zip mv awstats-7.3 /usr/local/awstats cd /usr/local/awstats/tool/ perl awstats_configure.pl

下面开始生成awstats的配置文件:

[root@xj123 tools]# perl 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 #这里输入nano
 
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.xj123.info #输入要统计的站点,下面一路回车
 
-----> 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):
> 
 
-----> Create config file '/etc/awstats/awstats.www.xj123.info.conf'
 Config file /etc/awstats/awstats.www.xj123.info.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.xj123.info
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.xj123.info.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.xj123.info' with command:
> perl awstats.pl -update -config=www.xj123.info
You can also build static report pages for 'www.xj123.info' with command:
> perl awstats.pl -output=pagetype -config=www.xj123.info
 
Press ENTER to finish...

[root@xj123 tools]# perl 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 #这里输入nano 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.xj123.info #输入要统计的站点,下面一路回车 -----> 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): > -----> Create config file '/etc/awstats/awstats.www.xj123.info.conf' Config file /etc/awstats/awstats.www.xj123.info.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.xj123.info 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.xj123.info.conf You should have a look inside to check and change manually main parameters. You can then manually update your statistics for 'www.xj123.info' with command: > perl awstats.pl -update -config=www.xj123.info You can also build static report pages for 'www.xj123.info' with command: > perl awstats.pl -output=pagetype -config=www.xj123.info Press ENTER to finish...

接着编辑在/etc/awstats/生成的配置文件,修改其中的日志路径:

vim /etc/awstats/awstats.www.xj123.info.conf
 
LogFile="改成你的日志的对应路径"

vim /etc/awstats/awstats.www.xj123.info.conf LogFile="改成你的日志的对应路径"

下面开始分析日志:

mkdir /var/lib/awstats
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.xj123.info

mkdir /var/lib/awstats /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.xj123.info

下面是来生成HTML页面以供访问,注意需要先创建awstats目录:

chmod +x /usr/local/awstats/tools/awstats_buildstaticpages.pl
/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.xj123.info -lang=cn -dir=/home/wwwroot/xj123.info/awstats -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl

chmod +x /usr/local/awstats/tools/awstats_buildstaticpages.pl /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.xj123.info -lang=cn -dir=/home/wwwroot/xj123.info/awstats -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl

最后为了页面的图片可以正常显示,nginx配置文件加入下面的配置:

location ~ ^/icon/ {
        root   /usr/local/awstats/wwwroot;
        index  index.html;
        access_log off;
        }

location ~ ^/icon/ { root /usr/local/awstats/wwwroot; index index.html; access_log off; }

对了,最后切记不要忘记把切割日志以及awstats生成静态文件加入到计划任务!

本文主要参考:

awstats分析Nginx日志
LNMP使用Awstats分析Nginx日志[转载]

原文地址 : https://www.xj123.info/5210.html

本站遵循 : 署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5)

版权声明 : 原创文章转载时,请务必以超链接形式标明文章原始出处

  • 上一篇:关于为什么要提交支持单来处理问题
  • 下一篇:VPS被攻击,记录下常用的检查命令
0条评论

暂时没有评论!

发表评论 点击取消评论.

*必填

*必填

  • 文章归档
  • 子网计算
  • 我的共享
  • 锻炼计划
  • 给我留言
  • 关于老谢
2025 年 6 月
一 二 三 四 五 六 日
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« 5 月    

最新文章

  • 认知,是否是一座大山?当架构决策变成配置清单比价
  • 重装博客服务器环境
  • 特斯拉24款标续 Model Y 2万公里使用体验
  • 接盘的傻子
  • 小牛us电瓶指示灯闪三次不上电
  • 一次还不错的小米售后体验
  • 装台1600元办公主机
  • 2021好久没更新博客
  • Zabbix监控oxidized备份状态
  • Zabbix 5.0 LTS版本MySQL表分区及编译安装随记

最新评论

  • zwwooooo:类似以前做网站开发时,一开始有自...
  • 老陳网志:有点高端,像我们整点nas玩玩就够...
  • springwood:自从 CentOS 不维护之后,我换 U...
  • 大D:难都搞下来了,那就更得YM了
  • 大D:只能是YM了,谢总牛啊
  • 灰常记忆:经济不好 今年我也换了机器 一...
  • 大峰:这是海外服务器嘛?速度挺快的。
  • 大D:只能单走一个6了哈哈哈
  • zwwooooo:买特斯拉和买iPhone的人群其实相似...
  • 平安家属子痕:一直坚持油车,看你写的心里有...

日志存档

  • 2025 年 5 月
  • 2025 年 4 月
  • 2025 年 3 月
  • 2024 年 9 月
  • 2024 年 5 月
  • 2024 年 1 月
  • 2023 年 4 月
  • 2021 年 10 月
  • 2021 年 4 月
  • 2021 年 3 月
  • 2021 年 2 月
  • 2020 年 11 月
  • 2020 年 9 月
  • 2020 年 5 月
  • 2020 年 4 月
  • 2020 年 3 月
  • 2020 年 1 月
  • 2019 年 12 月
  • 2019 年 10 月
  • 2019 年 7 月
  • 2019 年 6 月
  • 2019 年 5 月
  • 2019 年 3 月
  • 2019 年 1 月
  • 2018 年 12 月
  • 2018 年 11 月
  • 2018 年 10 月
  • 2018 年 7 月
  • 2018 年 6 月
  • 2018 年 5 月
  • 2018 年 4 月
  • 2018 年 3 月
  • 2018 年 1 月
  • 2017 年 10 月
  • 2017 年 9 月
  • 2017 年 8 月
  • 2017 年 7 月
  • 2017 年 2 月
  • 2017 年 1 月
  • 2016 年 12 月
  • 2016 年 11 月
  • 2016 年 10 月
  • 2016 年 7 月
  • 2016 年 6 月
  • 2016 年 4 月
  • 2016 年 2 月
  • 2016 年 1 月
  • 2015 年 12 月
  • 2015 年 10 月
  • 2015 年 9 月
  • 2015 年 7 月
  • 2015 年 5 月
  • 2015 年 4 月
  • 2015 年 3 月
  • 2015 年 2 月
  • 2015 年 1 月
  • 2014 年 12 月
  • 2014 年 10 月
  • 2014 年 9 月
  • 2014 年 8 月
  • 2014 年 7 月
  • 2014 年 6 月
  • 2014 年 5 月
  • 2014 年 4 月
  • 2014 年 3 月
  • 2014 年 2 月
  • 2014 年 1 月
  • 2013 年 12 月
  • 2013 年 11 月
  • 2013 年 10 月
  • 2013 年 9 月
  • 2013 年 8 月
  • 2013 年 7 月
  • 2013 年 6 月
  • 2013 年 5 月
  • 2013 年 4 月
  • 2013 年 3 月
  • 2013 年 2 月
  • 2013 年 1 月
  • 2012 年 12 月
  • 2012 年 11 月
  • 2012 年 9 月
  • 2012 年 8 月
  • 2012 年 7 月
  • 2012 年 6 月
  • 2012 年 5 月
  • 2012 年 4 月
  • 2012 年 3 月
  • 2012 年 2 月
  • 2012 年 1 月
  • 2011 年 12 月
  • 2011 年 11 月
  • 2011 年 10 月
  • 2011 年 9 月
  • 2011 年 8 月
  • 2011 年 7 月
  • 2011 年 6 月
  • 2011 年 5 月
  • 2011 年 4 月
  • 2011 年 3 月
  • 2011 年 2 月
  • 2011 年 1 月
  • 2010 年 12 月
  • 2010 年 11 月
  • 2010 年 10 月
  • 2010 年 9 月
  • 2010 年 8 月
  • 2010 年 7 月

W3C

  • XHTML 1.0 Transitional
  • CSS level 3
  • Google+
Copyright © 2010-2025 老谢博客 All rights reserved.
Gzipped 76.5% | Optimized loading 43 queries in 0.378 seconds | Memory 38.95 MB | 尼玛的备案
Powered by WordPress. | Hosted By LAOXUEHOST | Theme by WordPress主题巴士 | 站点地图 | SiteMap | uptime查询