Apache优化之AWStatus分析日志

Apache优化之AWStatus分析日志

前言

前面我们知道了日志文件如果不进行分割将会越来越大,给我们带来诸多不便,所以我们有了日志分割,将巨大的数据块分割成一小块一小块的,这样便于我们迁移和备份日志文件。日志被分割成一小块一小块的,便于我们分析其中的数据,所以,接下来我们来学习一下日志分析。

PS:

这是日志分割的cronolog的rpm包,由于在刚刚的那一部分,忘记分享了,在这边补上

链接:https://pan.baidu.com/s/1ykE0M6sDeMbx8Kd9b0mOxg
提取码:bc0q

这个是AWStatus日志分析的工具

链接:https://pan.baidu.com/s/1u5AUo2svTts1ln6FXB93eQ
提取码:vid9

实验环境

centos7虚拟机一台

win10主机一台

xshell6 ssh连接工具

实验步骤

1.安装本次实验所需的安装包

[root@localhost ~]# yum -y install httpd bind
[root@localhost ~]# rpm -q bind
bind-9.11.4-9.P2.el7.x86_64
[root@localhost ~]# rpm -q httpd
httpd-2.4.6-90.el7.centos.x86_64

2.配置DNS服务

[root@localhost ~]# vim /etc/named.conf
        listen-on port 53 { any; };
        allow-query     { any; };
[root@localhost ~]# vim /etc/named.rfc1912.zones 
zone "hello.com" IN {
        type master;
        file "hello.com.zone";
        allow-update { none; };
};
[root@localhost ~]# cd /var/named/
[root@localhost named]# ls
data  dynamic  named.ca  named.empty  named.localhost  named.loopback  slaves
[root@localhost named]# cp -p named.localhost hello.com.zone 
[root@localhost named]# vim hello.com.zone
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A       127.0.0.1
www IN  A       192.168.73.166
[root@localhost named]# systemctl restart named

3.配置Apache服务

[root@localhost named]# vim /etc/httpd/conf/httpd.conf
Listen 192.168.73.166:80
#Listen 80
ServerName www.hello.com:80

4.关闭防火墙和测试Apache和DNS服务

[root@localhost named]# systemctl stop firewalld
[root@localhost named]# setenforce 0
[root@localhost named]# systemctl restart httpd

在这里插入图片描述

写完后记得点击确定,接下来我们打开win10主机的cmd,重新获取一下IP地址和dns服务器的IP地址

先释放自己的IP地址

在这里插入图片描述

重新获取IP地址和dns服务器地址

在这里插入图片描述

测试dns域名解析是否能成功

在这里插入图片描述

打开浏览器,输入www.hello.com查看Apache配置是否成功

在这里插入图片描述

5.接下来我们将AWStatus工具包解压,并重命名

[root@localhost named]# cd
[root@localhost ~]# ls
anaconda-ks.cfg     initial-setup-ks.cfg  模板  图片  下载  桌面
awstats-7.6.tar.gz  公共                  视频  文档  音乐
[root@localhost ~]# tar -zxvf awstats-7.6.tar.gz -C /opt/
[root@localhost ~]# cd /opt
[root@localhost opt]# ls
awstats-7.6  rh
[root@localhost opt]# cd awstats-7.6/
[root@localhost awstats-7.6]# ls
docs  README.md  tools  wwwroot
[root@localhost awstats-7.6]# cd tools
[root@localhost tools]# ls
awstats_buildstaticpages.pl  awstats_updateall.pl  httpd_conf          nginx               xslt
awstats_configure.pl         dolibarr              logresolvemerge.pl  urlaliasbuilder.pl
awstats_exportlib.pl         geoip_generator.pl    maillogconvert.pl   webmin
[root@localhost tools]# cd /opt
[root@localhost opt]# ls
awstats-7.6  rh
[root@localhost opt]# mv awstats-7.6/ awstats/

6.将AWStatus移动到/usr/local/下面,并执行awstatus_configure.pl脚本

[root@localhost opt]# mv awstats/ /usr/local/
[root@localhost opt]# cd /usr/local/awstats/
[root@localhost awstats]# ls
docs  README.md  tools  wwwroot
[root@localhost awstats]# cd tools
[root@localhost tools]# ls
awstats_buildstaticpages.pl  awstats_updateall.pl  httpd_conf          nginx               xslt
awstats_configure.pl         dolibarr              logresolvemerge.pl  urlaliasbuilder.pl
awstats_exportlib.pl         geoip_generator.pl    maillogconvert.pl   webmin
----- 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    //这里是写Apache主配置文件的目录

-----> 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.hello.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.hello.com.conf'
 Config file /etc/awstats/awstats.www.hello.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.hello.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.hello.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.hello.com' with command:
> perl awstats.pl -update -config=www.hello.com
You can also read your statistics for 'www.hello.com' with URL:
> http://localhost/awstats/awstats.pl?config=www.hello.com

Press ENTER to finish...    //回车

7.修改Apache的主配置文件

[root@localhost tools]# vim /etc/httpd/conf/httpd.conf
<Directory "/usr/local/awstats/wwwroot">
    Options None
    AllowOverride None
#    Order allow,deny
#    Allow from all
    Require all granted
</Directory>

8.修改AWStatus的主配置文件,并创建/var/lib/awstats

[root@localhost tools]# vim /etc/awstats/awstats.www.hello.com.conf
LogFile="/var/log/httpd/access_log"
DirData="/var/lib/awstats"
[root@localhost tools]# mkdir /var/lib/awstats

9.重启Apache服务,并且去win10主机查看AWStatus服务

[root@localhost tools]# systemctl stop httpd
[root@localhost tools]# systemctl start httpd

在浏览器中输入http://www.hello.com/awstats/awstats.pl?config=www.hello.com

在这里插入图片描述

10.刷新AWStatus服务,然后查看结果

[root@localhost tools]# ./awstats_updateall.pl now
Running '"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=www.hello.com -configdir="/etc/awstats"' to update config www.hello.com
Create/Update database for config "/etc/awstats/awstats.www.hello.com.conf" by AWStats version 7.6 (build 20161204)
From data in log file "/var/log/httpd/access_log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 72
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 1 corrupted records,
 Found 0 old records,
 Found 71 new qualified records.

查看AWStatus服务,没有报错即为成功

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值