阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

日志分析工具Awstats实战之Apache篇-多站点日志分析

204次阅读
没有评论

共计 16735 个字符,预计需要花费 42 分钟才能阅读完成。

前面两篇都在讲述如何去部署 nginx 下的 awstats 日志分析工具

日志分析工具 Awstats 实战之 Nginx 篇: 分析结果静态化 http://www.linuxidc.com/Linux/2013-10/92150.htm

日志分析工具 Awstats 实战之 Nginx 篇: 分析结果动态化 http://www.linuxidc.com/Linux/2013-10/92150p2.htm

现在终于轮到 apache。作为老牌的网页服务器,awstats 对 apache 的支持非常完美,所以整个配置过程也是十分简单。因此,在这里我就拓展了一下部署,实现了对多站点的日志分析功能。

注意:自本篇博文发表之日,apache-2.4.x 还是无法支持部署 awstats 日志分析结果访问动态化,不过可以用前篇日志分析工具 Awstats 实战之 Nginx 篇 - 分析结果静态化中讲到的方法来实施部署 awstats。因此,本篇博文将用 apache2.2.25 版本来为大家讲解如何部署 awstats 日志分析结果动态化及多站点。
环境:

CentOS 6.4 x86_64
ip:192.168.1.113
站点 1:域名 www.linuxidc.com(server 和 client 都通过 hosts 文件解析)
站点 2:域名 www.88181.com(server 和 client 都通过 hosts 文件解析)
apache-2.2.25 编译安装,路径 /usr/local/apache,服务开启状态
日志记录格式为 apache 默认的 combined 格式,切勿更改,否则会造成 awstats 无法分析日志。
LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”” combined
apr-1.4.8  apr-util-1.5.2
awstats-7.2.tar.gz

一、日志自动切割
由于 apache 自带的日志轮询工具 rotatelogs,据专家说在进行日志切割时容易丢日志,所以这里我们就用 cronolog 来做日志切割。
1、下载并安装 cronolog

123456 cd /server/tools/
wget http://cronolog.org/download/cronolog-1.6.2.tar.gz
tar zxf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure
make&&make install

2、配置 apache 使用 cronolog
由于实验用的 apache 开启了虚拟主机功能,所以以下配置都在虚拟主机中进行,这样也是为了方便对多站点的分析操作。
vim /usr/local/apache/httpd/extra/httpd-vhosts.conf
将配置文件中的 CustomLog 和 ErrorLog 替换为下面的(由于我们要对多站点,所以这里要替换两个虚拟主机的,并且将日志存放名字做有效的区分才好)

123456 www.linuxidc.com
CustomLog “|/usr/local/sbin/cronolog /app/logs/linuxidc_access_%Y%m%d.log” combined
ErrorLog “|/usr/local/sbin/cronolog /app/logs/linuxidc_error_%Y%m%d.log”
www.88181.com
CustomLog “|/usr/local/sbin/cronolog /app/logs/88181_access_%Y%m%d.log” combined
ErrorLog “|/usr/local/sbin/cronolog /app/logs/88181_error_%Y%m%d.log”

注意:这里一定要注意对两个网站的日志名称配置。

二、Awstats 的安装与配置
1、部署 awstats
首先我们要下载 awstats 软件包,并将其放在常规目录(/usr/local)下

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 将无法运行

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

cd /usr/local/awstats/tools/
./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):
> /usr/local/apache/conf/httpd.conf #有可能是新版本的原因,这里会自动找到 apache 的配置文件,无需我们再自己填了,不过会问你一次,你回答 y 即可
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.linuxidc.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,所以直接回车即可
—–> Create config file ‘/etc/awstats/awstats.www.linuxidc.com.conf’
 Config file /etc/awstats/awstats.www.linuxidc.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=www.linuxidc.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.www.linuxidc.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for ‘www.linuxidc.com’ with command:
> perl awstats.pl -update -config=www.linuxidc.com
You can also build static report pages for ‘www.linuxidc.com’ with command:
> perl awstats.pl -output=pagetype -config=www.linuxidc.com
Press ENTER to finish… #提示配置文件创建完成和如何更新配置及建立静态报告页,这里我们回车即可结束这个配置向导

结束这个向导以后,我们对 www.linuxidc.com 站点的 awstats 配置文件已经配置好了,下面配置 www.88181.com 的配置文件,步骤和上面一样,只是在域名的地方做更改即可。
2、修改 awstats 配置文件
完成配置文件的创建之后,我们还需要对 /etc/awstats/awstats.www.linuxidc.com.conf 里的一些参数进行修改。

sed -i ‘s#LogFile=”/var/log/httpd/mylog.log”#LogFile=”/app/logs/linuxidc_access_%YYYY-24%MM-24%DD-24.log”#g’ /etc/awstats/awstats.www.linuxidc.com.conf

这里更改的目的是指定 awstats 需要分析的 nginx 的日志文件路径。这里的路径大家要按自己的日志路径来填。

sed -i ‘s#DirData=”/var/lib/awstats”#DirData=”/usr/local/awstats/data”#g’ /etc/awstats/awstats.www.linuxidc.com.conf

这里更改的目的是指定 awstats 的数据库配置文件(即 awstats 的数据库 (纯文本))。
以上的两个替换操作进行完之后一定要用命令查看替换是否成功,以便及早发现纰漏。

grep “LogFile=” /etc/awstats/awstats.www.linuxidc.com.conf
grep “DirData=” /etc/awstats/awstats.www.linuxidc.com.conf

查询替换结果正确之后,即可进行下面的步骤。
同样,重复以上的 2 个 sed 步骤,来对 www.88181.com 的 awstats 配置文件做操作,需要注意的是命令里面的日志路径和对应的 awstats 的数据库配置文件不要搞错即可。
由于,此处没有 /usr/local/awstats/data 目录,所以我们要创建出来
1 mkdir /usr/local/awstats/data

此时我们要对 /usr/local/awstats 目录进行属主变更,变更为 apache 的 daemon 用户,不然一会访问就会报错。这里也是和 nginx 的一个明显区别所在。
chown -R daemon /usr/local/awstats

3、生成 awstats 统计信息数据库
现在我们需要用 awstats 来生成对日志的统计分析信息出来了。由于我们用的是支持 perl 的 FCGI 动态化访问页面,所以此处我们只需要直接更新数据库即可。FCGI 程序会自动将数据库以动态页面的形式展现出来,无须再手动生成静态页面了。本处我们用脚本来完成。
vim /server/scripts/awstats_up.sh
#!/bin/sh
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.linuxidc.com >/dev/null 2>&1
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.88181.com >/dev/null 2>&1

该脚本里面用下面的命令也是可以的。
/usr/local/awstats/tools/awstats_updateall.pl now

运行该脚本生成分析结果
/bin/sh /server/scripts/awstats_up.sh

提示:由于我们这里用的 apache 使用 cronolog 日志轮询工具使得文件出来都是带时间格式的。因此你可能会想,为什么不改成对当天的日志进行操作。首先在这里我们可以实时的进行日志分析数据库更新来查看实时的日志,不过这里不建议大家这样去做。

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2013-11/92273p2.htm

推荐阅读:

CentOS 6.3 下 AWStats+GeoIP 实现查看网站访问归属地 http://www.linuxidc.com/Linux/2013-06/85984.htm

Nginx 日志分析 AWStats + JAWStats 安装配置 http://www.linuxidc.com/Linux/2013-06/85567.htm

经典日志分析工具 -AWStats http://www.linuxidc.com/Linux/2012-12/77080.htm

AWStats 日志系统配置文件和错误归纳 http://www.linuxidc.com/Linux/2012-12/75657.htm

使用 AWStats 分析网站日志 - 强大的日志分析工具 http://www.linuxidc.com/Linux/2012-11/74431.htm

AWStats 的详细介绍:请点这里
AWStats 的下载地址:请点这里

三、配置日志分析页面的来访 ip 的地址位置显示

这里我们用国内最准确的 ip 数据库——QQ 纯真库 (点击下载),大家下载之后通过 CRT 用 lrzsz 工具传上去,具体步骤这里不写了。
附件里面有三个文件 qqhostinfo.pm,qqwry.pl 和 QQWry.Dat,我们将这三个文件统统都放到 /usr/local/awstats/wwwroot/cgi-bin/plugins 中。
接下来,我们修改 qqwry.pl 文件,将./QQWry.Dat 修改为 ${DIR}/plugins/QQWry
vim /usr/local/awstats/wwwroot/cgi-bin/plugins/qqwry.pl
 #my $ipfile=”./QQWry.Dat”;

修改为
my $ipfile=”${DIR}/plugins/QQWry.Dat”;

然后编辑 awstats 的配置文件 /etc/awstats/awstats.www.linuxidc.com.conf(根据你前面配置的站点信息生成的文件),将 LoadPlugin=”hostinfo” 替换为 LoadPlugin=”qqhostinfo” 即可。

sed -i ‘s#\#LoadPlugin=”hostinfo”#LoadPlugin=”qqhostinfo”#g’ /etc/awstats/awstats.www.linuxidc.com.conf
sed -i ‘s#\#LoadPlugin=”hostinfo”#LoadPlugin=”qqhostinfo”#g’ /etc/awstats/awstats.www.88181.com.conf

切记,在这些替换完之后一定要查看替换是否成功,以便及早发生纰漏。
grep “LoadPlugin=\”qqhostinfo\”” /etc/awstats/awstats.www.linuxidc.com.conf

如果检查无误,那么我们的 ip 地址位置显示就配置好了,在后面的日志分析中,我们就可以清楚的看到来访 ip 的地理位置信息了。

四、配置 apache
首先我们打开 apache 的主配置文件 /usr/local/apache/conf/httpd.conf 可以看到里面多出了以下几行:

#
# Directives to allow use of AWStats as a CGI
#
Alias /awstatsclasses “/usr/local/awstats/wwwroot/classes/”
Alias /awstatscss “/usr/local/awstats/wwwroot/css/”
Alias /awstatsicons “/usr/local/awstats/wwwroot/icon/”
ScriptAlias /awstats/ “/usr/local/awstats/wwwroot/cgi-bin/”
#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory “/usr/local/awstats/wwwroot”>
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

我们可以看到 awstats 已经在 apache 的主配置文件配置好了需要的参数,是不是很方便啊。此时我们还需要在配置虚拟目录配置文件里面配置几个参数来实现站点的统计信息安全。
1 vim /usr/local/apache/httpd/extra/httpd-vhosts.conf

添加以下两行参数进去
 auth_basic “Restricted”; 
    auth_basic_user_file /usr/local/nginx/htpasswd.pass;

添加之后的文件信息
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot “/www/linuxidc”
    ServerName dummy-host.example.com
    ServerAlias www.linuxidc.com
    CustomLog “|/usr/local/sbin/cronolog /app/logs/linuxidc_access_%Y%m%d.log” combined
    ErrorLog “|/usr/local/sbin/cronolog /app/logs/linuxidc_error_%Y%m%d.log”
    auth_basic “Restricted”; 
    auth_basic_user_file /usr/local/apache/htpasswd.pass;
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot “/www/88181”
    ServerName www.88181.com
    CustomLog “|/usr/local/sbin/cronolog /app/logs/88181_access_%Y%m%d.log” combined
    ErrorLog “|/usr/local/sbin/cronolog /app/logs/88181_error_%Y%m%d.log”
    auth_basic “Restricted”;
    auth_basic_user_file /usr/local/apache/htpasswd.pass;
</VirtualHost>

接下来我们用下面的命令来生成加密文件和加密的账号及密码
htpasswd -c -m /usr/local/nginx/htpasswd.pass admin      #用户名为 admin,回车之后输入两次密码即完成创建

如果,你顺利的执行了上面的所有操作,那么 OK!现在你已经可以通过访问
http://www.linuxidc.com/awstats/awstats.pl?config=www.linuxidc.com
http://www.88181.com/awstats/awstats.pl?config=www.88181.com

来查看你多个站点的日志分析信息了。

日志分析工具 Awstats 实战之 Apache 篇 - 多站点日志分析

日志分析工具 Awstats 实战之 Apache 篇 - 多站点日志分析

五、配置 awstats 自动运行
为了让整个日志的统计过程可以实现自动化,我们将 awstats.sh 脚本加入 crontab 定时任务中去
0 1 * * * /bin/sh /server/scripts/awstats_up.sh >/dev/null 2>&1

也许你会问为什么不把 cronolog 也加入开机启动呢,因为 cronolog 已经默认被 apache 用来调用记录日志,所以无需加入到 crontab 定时任务中。

至此,我们已经通过在 nginx 和 apache 上部署 awstats 日志访问分析工具来实现了对站点来访信息的分析。整个系列的博文不多,只有三篇,不过还算是详尽,把改涉及到的都涉及到了。中间有很多技术是连同的,比如在 apche 上进行的多站点,在 nginx 上的静态化访问等,尽管我没有再出,不过我们都可以将他们来回应用实现部署需求。我也相信,只有融会贯通了,我们大家才能更好的部署好这一利器!

前面两篇都在讲述如何去部署 nginx 下的 awstats 日志分析工具

日志分析工具 Awstats 实战之 Nginx 篇: 分析结果静态化 http://www.linuxidc.com/Linux/2013-10/92150.htm

日志分析工具 Awstats 实战之 Nginx 篇: 分析结果动态化 http://www.linuxidc.com/Linux/2013-10/92150p2.htm

现在终于轮到 apache。作为老牌的网页服务器,awstats 对 apache 的支持非常完美,所以整个配置过程也是十分简单。因此,在这里我就拓展了一下部署,实现了对多站点的日志分析功能。

注意:自本篇博文发表之日,apache-2.4.x 还是无法支持部署 awstats 日志分析结果访问动态化,不过可以用前篇日志分析工具 Awstats 实战之 Nginx 篇 - 分析结果静态化中讲到的方法来实施部署 awstats。因此,本篇博文将用 apache2.2.25 版本来为大家讲解如何部署 awstats 日志分析结果动态化及多站点。
环境:

CentOS 6.4 x86_64
ip:192.168.1.113
站点 1:域名 www.linuxidc.com(server 和 client 都通过 hosts 文件解析)
站点 2:域名 www.88181.com(server 和 client 都通过 hosts 文件解析)
apache-2.2.25 编译安装,路径 /usr/local/apache,服务开启状态
日志记录格式为 apache 默认的 combined 格式,切勿更改,否则会造成 awstats 无法分析日志。
LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”” combined
apr-1.4.8  apr-util-1.5.2
awstats-7.2.tar.gz

一、日志自动切割
由于 apache 自带的日志轮询工具 rotatelogs,据专家说在进行日志切割时容易丢日志,所以这里我们就用 cronolog 来做日志切割。
1、下载并安装 cronolog

123456 cd /server/tools/
wget http://cronolog.org/download/cronolog-1.6.2.tar.gz
tar zxf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure
make&&make install

2、配置 apache 使用 cronolog
由于实验用的 apache 开启了虚拟主机功能,所以以下配置都在虚拟主机中进行,这样也是为了方便对多站点的分析操作。
vim /usr/local/apache/httpd/extra/httpd-vhosts.conf
将配置文件中的 CustomLog 和 ErrorLog 替换为下面的(由于我们要对多站点,所以这里要替换两个虚拟主机的,并且将日志存放名字做有效的区分才好)

123456 www.linuxidc.com
CustomLog “|/usr/local/sbin/cronolog /app/logs/linuxidc_access_%Y%m%d.log” combined
ErrorLog “|/usr/local/sbin/cronolog /app/logs/linuxidc_error_%Y%m%d.log”
www.88181.com
CustomLog “|/usr/local/sbin/cronolog /app/logs/88181_access_%Y%m%d.log” combined
ErrorLog “|/usr/local/sbin/cronolog /app/logs/88181_error_%Y%m%d.log”

注意:这里一定要注意对两个网站的日志名称配置。

二、Awstats 的安装与配置
1、部署 awstats
首先我们要下载 awstats 软件包,并将其放在常规目录(/usr/local)下

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 将无法运行

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

cd /usr/local/awstats/tools/
./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):
> /usr/local/apache/conf/httpd.conf #有可能是新版本的原因,这里会自动找到 apache 的配置文件,无需我们再自己填了,不过会问你一次,你回答 y 即可
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.linuxidc.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,所以直接回车即可
—–> Create config file ‘/etc/awstats/awstats.www.linuxidc.com.conf’
 Config file /etc/awstats/awstats.www.linuxidc.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=www.linuxidc.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.www.linuxidc.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for ‘www.linuxidc.com’ with command:
> perl awstats.pl -update -config=www.linuxidc.com
You can also build static report pages for ‘www.linuxidc.com’ with command:
> perl awstats.pl -output=pagetype -config=www.linuxidc.com
Press ENTER to finish… #提示配置文件创建完成和如何更新配置及建立静态报告页,这里我们回车即可结束这个配置向导

结束这个向导以后,我们对 www.linuxidc.com 站点的 awstats 配置文件已经配置好了,下面配置 www.88181.com 的配置文件,步骤和上面一样,只是在域名的地方做更改即可。
2、修改 awstats 配置文件
完成配置文件的创建之后,我们还需要对 /etc/awstats/awstats.www.linuxidc.com.conf 里的一些参数进行修改。

sed -i ‘s#LogFile=”/var/log/httpd/mylog.log”#LogFile=”/app/logs/linuxidc_access_%YYYY-24%MM-24%DD-24.log”#g’ /etc/awstats/awstats.www.linuxidc.com.conf

这里更改的目的是指定 awstats 需要分析的 nginx 的日志文件路径。这里的路径大家要按自己的日志路径来填。

sed -i ‘s#DirData=”/var/lib/awstats”#DirData=”/usr/local/awstats/data”#g’ /etc/awstats/awstats.www.linuxidc.com.conf

这里更改的目的是指定 awstats 的数据库配置文件(即 awstats 的数据库 (纯文本))。
以上的两个替换操作进行完之后一定要用命令查看替换是否成功,以便及早发现纰漏。

grep “LogFile=” /etc/awstats/awstats.www.linuxidc.com.conf
grep “DirData=” /etc/awstats/awstats.www.linuxidc.com.conf

查询替换结果正确之后,即可进行下面的步骤。
同样,重复以上的 2 个 sed 步骤,来对 www.88181.com 的 awstats 配置文件做操作,需要注意的是命令里面的日志路径和对应的 awstats 的数据库配置文件不要搞错即可。
由于,此处没有 /usr/local/awstats/data 目录,所以我们要创建出来
1 mkdir /usr/local/awstats/data

此时我们要对 /usr/local/awstats 目录进行属主变更,变更为 apache 的 daemon 用户,不然一会访问就会报错。这里也是和 nginx 的一个明显区别所在。
chown -R daemon /usr/local/awstats

3、生成 awstats 统计信息数据库
现在我们需要用 awstats 来生成对日志的统计分析信息出来了。由于我们用的是支持 perl 的 FCGI 动态化访问页面,所以此处我们只需要直接更新数据库即可。FCGI 程序会自动将数据库以动态页面的形式展现出来,无须再手动生成静态页面了。本处我们用脚本来完成。
vim /server/scripts/awstats_up.sh
#!/bin/sh
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.linuxidc.com >/dev/null 2>&1
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.88181.com >/dev/null 2>&1

该脚本里面用下面的命令也是可以的。
/usr/local/awstats/tools/awstats_updateall.pl now

运行该脚本生成分析结果
/bin/sh /server/scripts/awstats_up.sh

提示:由于我们这里用的 apache 使用 cronolog 日志轮询工具使得文件出来都是带时间格式的。因此你可能会想,为什么不改成对当天的日志进行操作。首先在这里我们可以实时的进行日志分析数据库更新来查看实时的日志,不过这里不建议大家这样去做。

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2013-11/92273p2.htm

推荐阅读:

CentOS 6.3 下 AWStats+GeoIP 实现查看网站访问归属地 http://www.linuxidc.com/Linux/2013-06/85984.htm

Nginx 日志分析 AWStats + JAWStats 安装配置 http://www.linuxidc.com/Linux/2013-06/85567.htm

经典日志分析工具 -AWStats http://www.linuxidc.com/Linux/2012-12/77080.htm

AWStats 日志系统配置文件和错误归纳 http://www.linuxidc.com/Linux/2012-12/75657.htm

使用 AWStats 分析网站日志 - 强大的日志分析工具 http://www.linuxidc.com/Linux/2012-11/74431.htm

AWStats 的详细介绍:请点这里
AWStats 的下载地址:请点这里

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计16735字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中