1.下载安装cronolog
1.解压缩 # tar zxvf cronolog-1.6.2.tar.gz
2.进入安装文件所在目录 # cd cronolog-1.6.2
3.运行安装 # ./configure # make # make install
4.查看cronolog安装后所在目录(验证安装是否成功) # which cronolog 一般情况下显示为:/usr/local/sbin/cronolog
2.创建命名管道
mkfifo /usr/local/nginx/access_log_pipe
3.修改Nginx配置生成log
修改nginx配置文件添加如下内容
access_log /usr/local/nginx/access_log_pipe main;
4.配置cronolog,日期按天
如果按小时使用access_%Y-%m-%d-%H.log;如果按分钟使用access_%Y-%m-%d-%H-%M.log
#nohup cat /usr/local/nginx/access_log_pipe | /usr/local/sbin/cronolog /usr/local/nginx/logs/access-%Y-%m-%d.log &
5:重启nginx
cd /usr/local/nginx/sbin ./nginx -s reload
如按要求生成log文件则cronolog配置使用没问题。
1.部署awstats
1
2
3
|
wget http:
//awstats
.sourceforge.net
/files/awstats-7
.2.
tar
.gz
tar
zxf awstats-7.2.
tar
.gz
mv
awstats-7.2
/usr/local/awstats
|
由于wget下载下来的包中权限是非root的,所以这里要修改权限,否则稍后*.pl将无法运行
1
2
3
|
chown
-R root.root
/usr/local/awstats
chmod
+x
/usr/local/awstats/tools/
*.pl
chmod
+x
/usr/local/awstats/wwwroot/cgi-bin/
*.pl
|
接下来我们要执行awstats/tools下的awstats_configure.pl配置向导,用来生成awstats的配置文件,awstats配置文件的命名规则是awstats.website.conf。
1
2
|
cd
/usr/local/awstats/tools/
.
/awstats_configure
.pl
|
此时会出现如下提示
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
----- 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
#这里让填写网页服务器的配置文件路径,因为我们用的不是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
#询问是否创建一个新的配置文件,这里填y
-----> Define config
file
name to create
What is the name of your web site or profile analysis ?
Example: xxx.com
Example: demo
Your web site, virtual server or profile name:
> xxxxx.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):
>
#这里要填写你配置文件存放路径,我们使用它默认的路径/etc/awstats,所以直接回车即可
Config
file
/etc/awstats/awstats
.xxx.com.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=xxx.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
...
#提示不能自动加入crontab定时任务,需要稍后自己添加,我们按回车继续即可
A SIMPLE config
file
has been created:
/etc/awstats/awstats
.xxx.com.conf
You should have a
look
inside to check and change manually main parameters.
You can
then
manually update your statistics
for
'xxx.com'
with
command
:
> perl awstats.pl -update -config=xxx.com
You can also build static report pages
for
'xxx.com'
with
command
:
> perl awstats.pl -output=pagetype -config=xxx.com
Press ENTER to finish...
#提示配置文件创建完成和如何更新配置及建立静态报告页,这里我们回车即可结束这个配置向导
|
2、修改awstats配置文件
完成配置文件的创建之后,我们还需要对/etc/awstats/awstats.xxx.com.conf里的一些参数进行修改。
这里更改的目的是指定awstats需要分析的nginx的日志文件路径。这里的路径大家要按自己的日志路径来填。
以上的两个替换操作进行完之后一定要用命令查看替换是否成功,以便及早发现纰漏。
配置脚本自动生成日志,自动生成静态结果文件
1.生成日志文件脚本:
nohup cat /usr/local/nginx/access_log_pipe | /usr/local/sbin/cronolog /usr/local/nginx/logs/access-%Y%m%d.log &
2.生成日志静态结果文件
#!/bin/bash
Awstats_Dir="/usr/local/awstats"
$Awstats_Dir/wwwroot/cgi-bin/awstats.pl -update -config=xxx.com
$Awstats_Dir/tools/awstats_buildstaticpages.pl -update -config=xxx.com -awstatsprog=$Awstats_Dir/wwwroot/cgi-bin/awstats.pl -lang=cn -dir=/usr/local/awstats/html
/*
/usr/local/awstats/tools/awstats_buildstaticpages
.pl Awstats 静态页面生成工具
-update -config=xxx.com 更新配置项
-awstatsprog=
/usr/local/awstats/wwwroot/cgi-bin/awstats
.pl Awstats 日志更新程序路径
-lang=cn 语言为中文
-
dir
=
/www/awstats
统计结果输出目录
添加定时任务(crontab)
1 0 * * * bash /usr/local/nginxlog/awstats.sh //生成静态结果文件脚本
0 0 * * * bash /usr/local/nginxlog/genrateRz.sh //生成当天日志脚本
当零点生成当天Nginx以日期为末尾的日志文件。
0点1分生成脚本 为生成以昨天日志文件为基础生成html静态结果页
配置Nginx访问静态资源
其他方式详情百度,这里servce为例
server
{
listen 8080;
server_name localhost;
index index.html index.htmindex.php default.html default.htm default.php;
root /usr/local/awstats/html; //静态页面生成目录
location ~ ^/awstats/ {
root /usr/local/awstats/html;
index awstats.xxx.com.html;
access_log off;
}
location ^~ /icon/ {
root /usr/local/awstats/wwwroot; //awstats静态素材文件
index index.html;
access_log off;
}
location / {
root /usr/local/awstats/html;
index awstats.xxx.com.html;//默认首页 localhost:8080
autoindex on;
access_log off;
}