Centos7.6下搭建AWStats日志分析系统

一、AWStats日志分析系统简介

  • Perl语言开发的一款开源日志分析系统
  • 可用来分析Apache、Samba、Vsftpd、IIS等服务器的访问日志
  • 结合crond等计划任务服务,可对日志内容定期进行分析

二、部署AWStats日志分析系统

  • 实验环境:VMware Workstation 15.5、Centos7.6、Xshell 6、Windows10专业工作站版

  • 实验准备:新建两台虚拟机,一台为Centos7.6系统,作为DNS和http服务器(IP:192.168.50.136);另一台为windows10系统,作为客户机(IP:192.168.50.140),在客户机上进行如下设置:
    acu9Tx.png

  • 实验步骤:

1、关闭系统系统核心防护并清空防火墙规则

[root@localhost ~]# setenforce 0
[root@localhost ~]# iptables -F

2、安装DNS与http服务

[root@localhost ~]# yum -y install bind httpd

3、修改DNS主配置文件

[root@localhost ~]# vi /etc/named.conf 

将红框标记的两处127.0.0.1改为any

acuPk6.md.png
4、修改DNS区域配置文件

[root@localhost ~]# vi /etc/named.rfc1912.zones

对照行号修改配置文件如下两处:

zone "test.com" IN {
        type master;
        file "test.com.zome";
        allow-update { none; };
};

acnv6J.png
5、复制区域数据配置文件模板并改名为刚才设置的test.zom.zone

[root@localhost named]# cp -p named.localhost test.com.zome

6、编辑DNS区域数据配置文件

[root@localhost named]# vi test.com.zome    ## 编辑配置文件

修改最后一行内容为:
www IN  A       192.168.50.136

acnxX9.png
7、启动DNS服务

[root@localhost named]# systemctl start named

8、使用客户机进行域名解析

acnjl4.png
9、修改http服务主配置文件

[root@localhost named]# vim /etc/httpd/conf/httpd.conf    ## 修改配置文件
   
将41、42行的监听地址修改为:
Listen 192.168.50.136:80
#Listen 80

将95行的域名修改为:
ServerName www.test.com:80

acuSmR.png
acup01.png

10、在http服务站点目录下创建一个页面

[root@localhost named]# vi /var/www/html/index.html   ## 新建网页文件

写入如下内容:
<h1>This is a test Web!</h1>

11、启动http服务

[root@localhost named]# systemctl start httpd

12、在客户机上打打开浏览器,访问www.test.com
acuitK.png

下面进行安装AWStats

13、首先将源码包上传到服务器/opt目录下

[root@localhost named]# cd /opt     ## 进入opt目录
上传源码包    ## 有多种方式,Xshell6支持拖拽上传,如果使用putty等客户端可以使用XFTP工具连接服务器后进行上传

14、加压缩源码包

[root@localhost opt]# tar zxvf awstats-7.6.tar.gz

15、将解压后的目录移动到安装目录中并新建一个awstats目录

[root@localhost opt]# mv awstats-7.6 /usr/local/awstats

16、进入awstats目录,进行软件配置

[root@localhost opt]# cd /usr/local/awstats/     ## 进入软件目录

[root@localhost tools]# ./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):
> /etc/httpd/conf/httpd.conf         ## 输入http服务主配置文件路径

-----> Check and complete web server config file '/etc/httpd/conf/httpd.conf'
  Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'
  Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"'
  Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"'
  Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"'
  Add '<Directory>' directive
  AWStats directives added to Apache config file.

-----> 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.test.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):
>              ## 直接回车

-----> Create config file '/etc/awstats/awstats.www.test.com.conf'
 Config file /etc/awstats/awstats.www.test.com.conf created.

-----> Restart Web server with '/sbin/service httpd restart'
Redirecting to /bin/systemctl restart httpd.service

-----> 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.test.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...      ## 回车继续


A SIMPLE config file has been created: /etc/awstats/awstats.www.test.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.test.com' with command:
> perl awstats.pl -update -config=www.test.com
You can also read your statistics for 'www.test.com' with URL:
> http://localhost/awstats/awstats.pl?config=www.test.com     ## 软件后台地址

Press ENTER to finish...        ## 直接回车,结束配置

17、修改http服务配置文件

[root@localhost tools]# vi /etc/httpd/conf/httpd.conf 

将371与372行注释掉,并在下方添加一行内容:

#Order allow,deny
#Allow from all
Require all granted

18、编辑awstats服务生成的配置文件

[root@localhost awstats]# vi /etc/awstats/awstats.www.test.com.conf 

修改如下内容:
修改第50行内容:LogFile="/var/log/httpd/access_log"

找到220行,有如下内容:
DirData="/var/lib/awstats"

但在/var/lib/目录下并找不到awstats这个目录,所以我们要手动创建一个
[root@localhost awstats]# mkdir /var/lib/awstats

acuFfO.png

19、重启http服务

[root@localhost awstats]# systemctl restart httpd

20、在客户机中打开浏览器,访问统计后台地址

http://www.test.com/awstats/awstats.pl?config=www.test.com

注意:链接原本中写的是localhost,需要将其改为自己的域名

acuE1e.md.png

21、为了方便管理,我们可以将脚本添加进计划任务,每5分钟执行一次更新数据

[root@localhost awstats]# crontab -e     ## 编辑周期性计划任务

写入如下内容:
*/5 * * * * /usr/local/awstats/tools/awststs_updateall.pl now

22、进入客户机访问www.test.com站点,并多刷新几次

进入awstats软件目录,执行脚本刷新访问数据

[root@localhost awstats]# cd /usr/local/awstats/tools/     ## 进入目录
[root@localhost tools]# ./awstats_updateall.pl now   ## 更新数据

23、再次访问后台统计页面,发现访问数据已经刷新了
acuApD.md.png

猜你喜欢

转载自blog.csdn.net/u014042047/article/details/107833066