您的位置:首页 > 运维架构 > Nginx

Nginx & AWStats 安装、配置、使用

2014-04-11 11:46 1011 查看
—— 参考IBM文章:THIS , 不一样的指导顺序 ——

1. awstats分析nginx - access.log,网上资料大部分都是下载,然后配置。官网下载地址:


http://awstats.sourceforge.net/#DOWNLOAD

cd /usr/local

wget http://prdownloads.sourceforge.net/awstats/awstats-7.2.zip
unzip awstats-7.2.zip

mv awstats-7.2 awstats

sudo chown -R root:root awstats # 注意权限,否则会影响以后执行



2. 安装好了,配置:


cd /usr/local/awstats/tools

sudo chmod 711 awstats_configure.pl #把awstats_configure.pl 权限修改与 awstats_buildstaticpages.pl 相同

sudo ./awstats_configure.pl


然后就是“向导 一”:


----- AWStats awstats_configure 1.0 (build 1.9) (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 # 这里要输入,完整的,你使用的服务器的 配置文件,但是 我们用的是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:
> lengxiaohua.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):
> # 默认配置文件路径


"五" - 得到关键的 执行命令:


-----> 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=lengxiaohua.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...

命令-----> /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=lengxiaohua.com


"六" - 配置文件路径:


A SIMPLE config file has been created: /etc/awstats/awstats.lengxiaohua.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'lengxiaohua.com' with command:
> perl awstats.pl -update -config=lengxiaohua.com
You can also build static report pages for 'lengxiaohua.com' with command:
> perl awstats.pl -output=pagetype -config=lengxiaohua.com

Press ENTER to finish...

路径 ----> /etc/awstats/awstats.lengxiaohua.com.conf


完成。

3. 修改调整配置:


路径 ----> /etc/awstats/awstats.lengxiaohua.com.conf

vim /etc/awstats/awstats.lengxiaohua.com.conf

修改:LogFile="/var/log/httpd/mylog.log"

变为:LogFile="/var/log/nginx/access_%YYYY-0%MM-0%DD-0.log" # 察看 vim /etc/nginx/nginx.conf,可以知道 access.log路径



4. 执行(手动)统计:


执行 : 命令-----> /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=lengxiaohua.com

(本地 - 自己:执行 : 命令-----> /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.lengxiaohua.com)

错误:

Error: AWStats database directory defined in config file by 'DirData' parameter (/var/lib/awstats) does not exist or is not writable.
Setup ('/etc/awstats/awstats.lengxiaohua.com.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).

试试: sudo apt-get install awstats



然后基本执行成功了,可能需要重启?或者其他操作

3. webroot 目录 ,这是什么?

就是指,nginx配置中,你的 虚拟服务器 指向的 静态文件 的路径。

因为 awstats 也是生成的 静态文件,所以,nginx只要能访问到这个静态文件,就可以了。【此处百度,“nginx 静态文件” - 可以有答案】

我的nginx指向的静态文件路径是:


/opt/test/html



4. 生成静态页面(能看到生成了一系列的文件,此时就是成功了):


/usr/local/awstats/tools/awstats_buildstaticpages.pl -update  \
-config=www.lengxiaohua.com -lang=cn -dir=/opt/lengxiaohua/web/html/awstats  \
-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl



5. 设置 定时任务,这样让每天都自动生成 静态页面:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: