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"'; |
下面两行命令是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 |
下面开始生成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... |
接着编辑在/etc/awstats/生成的配置文件,修改其中的日志路径:
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 |
下面是来生成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 |
最后为了页面的图片可以正常显示,nginx配置文件加入下面的配置:
location ~ ^/icon/ { root /usr/local/awstats/wwwroot; index index.html; access_log off; } |
对了,最后切记不要忘记把切割日志以及awstats生成静态文件加入到计划任务!
本文主要参考:
暂时没有评论!