老谢博客

  • 首页
  • 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条评论

暂时没有评论!

发表评论 点击取消评论.

*必填

*必填

  • 文章归档
  • 子网计算
  • 我的共享
  • 锻炼计划
  • 给我留言
  • 关于老谢
2023年 4月
一 二 三 四 五 六 日
 12
3456789
10111213141516
17181920212223
24252627282930
« 10月    

最新文章

  • 2021好久没更新博客
  • Zabbix监控oxidized备份状态
  • Zabbix 5.0 LTS版本MySQL表分区及编译安装随记
  • centos7.9部署oxidized自动备份交换机配置
  • Surface Pro 4更换屏幕与电池
  • VCSA中删除horizon view链接克隆生成的replica-受保护副本
  • Esxi6.7U3安装SanDisk Fusion-io 1.3T ioscale Pci SSD加速卡驱动
  • 搭建ELK日志系统分析处理fortigate的syslog日志
  • 华为USG防火墙配置NAT映射回流解决内网通过公网映射访问内部服务器
  • 飞塔防火墙fortitoken配置

最新评论

  • 无敌风火轮:和索尼没啥关系,这是索尼电脑的...
  • zhudong:老大,有VMware Horizon 7.12相关资...
  • qx:所有连接失效了,求一份
  • RainH:大佬,这个111.111.111.111是什么鬼?...
  • 王叨叨:幸福的人都是相似的,不幸的人各有各...
  • 李海博客:李海博客前来学习!
  • 明月登楼:最近使用了ZeroSSL证书,感觉还不...
  • 鸟叔:尽管不知道干啥的,还是来顶一下
  • 鸟叔:鸟叔来贵博客参观学习,通过十年之约穿...
  • 周良粥凉:往前看。

日志存档

  • 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-2023 老谢博客 All rights reserved.
Gzipped 76.5% | Optimized loading 55 queries in 0.301 seconds | Memory 33.55 MB | 皖ICP备13010663号-1
Powered by WordPress. | Hosted By 腾讯云 | Theme by WordPress主题巴士 | 站点地图 | SiteMap | Uptime | 技术支持:苏州天剑计算机系统有限公司