Apache configuration and application: AWStats log analysis system (actual combat!)

AWStats log analysis system

An open source log analysis system developed by Perl
 It can be used to analyze the access logs of Apache, Samba, Vsftpd, IIS and other servers.
Information combined with crond and other scheduled task services can regularly analyze the log content

Environmental Science

One Linux service host (192.168.13.132)
A win7 test pc

1. Install http and bind services.

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

2. Configure DNS profile

[root@localhost ~]# vim /etc/named.conf   ##Master profile

options {
                listen-on port 53 { any; };      ##Monitor this machine as all
                listen-on-v6 port 53 { ::1; };
                directory       "/var/named";
                dump-file       "/var/named/data/cache_dump.db";
                statistics-file "/var/named/data/named_stats.txt";
                memstatistics-file "/var/named/data/named_mem_stats.txt";
                recursing-file  "/var/named/data/named.recursing";
                secroots-file   "/var/named/data/named.secroots";
                allow-query     { any; };      ##Allow all

3. Configuration area configuration file etc / named.rfc1912.areas)

[root@localhost ~]# vim /etc/named.rfc1912.zones  ##Configure zone profiles
zone "localhost" IN {             ##Copy two templates below
                                type master;
                                file "named.localhost";
                                allow-update { none; };
};

zone "kgc.com" IN {              ##Change localhost to kgc.com
                                type master;
                                file "kgc.com.zone";      ##Create area data profile
                                allow-update { none; };
};

4. Edit the region data configuration file (kgc.com.zone)

[root@localhost ~]# cd /var/named/     ##Switch to / var/named directory  
[root@localhost named]# cp -p named.localhost kgc.com.zone   
##Copy template as kgc.com.zone
[root@localhost named]# vim kgc.com.zone  ##Edit area data profile
[root@localhost named]# systemctl start named   ##Start dns Service
$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.13.132   ##Remove ipv6 add domain name resolution address as native

5. Configure the http main configuration file, modify the listening port, and restart the network service.

[root@localhost html]# vim /etc/httpd/conf/httpd.conf     ##Modify profile
Listen 192.168.13.132:80               ##Modify the ipv4 listening port
#Listen 80      ##Comment ipv6 port
ServerName www.kgc.com:80       ##Modify domain name
[root@localhost named]# systemctl stop firewalld.service    ##Turn off firewall
[root@localhost named]# setenforce 0   ##Turn off enhancements
[root@localhost html]# systemctl start httpd.service  ##Start network service

6. Use the testing machine (dns service address 192.168.13.132) to visit the testing website


7. View your log file

[root@localhost html]# cd /var/log/httpd/ ##Switch to your log file
[root@localhost httpd]# cat access_log   ##view log file

8. Windows file sharing, using Linux remote mount to install AWStats

1) share the required compression package of LAMP on Windows (if you have any questions here, please refer to the previous blog articles)

2) use remote share to get files on Linux and mount them to / abc directory

[root@localhost httpd]# mkdir /abc   ##Create mount point / abc
root@lamp ~]# smbclient -L //192.168.10.88/
        Sharename       Type      Comment
        ---------       ----      -------
        LAMP-C7         Disk      

[root@lamp ~]# mount.cifs //192.168.10.88/LAMP-C7 /abc  
##Remote mount package to / abc directory

3) decompress the source package to the / opt directory

[root@localhost httpd]# cd /abc  ##Switch to mount point
[root@localhost abc]# tar zxvf awstats-7.6.tar.gz -C /opt  ##Unzip to / opt

4) configure AWStats

[root@localhost abc]# cd /opt/  ##Switch to / opt directory
[root@localhost opt]# ls
awstats-7.6  rh
[root@localhost opt]# mv awstats-7.6/ /usr/local/awstats  
##Move awstats to / usr/local/awstats
[root@localhost opt]# cd /usr/local/  ##Switch to this directory
[root@localhost local]# ls
awstats  bin  etc  games  include  lib  lib64  libexec  sbin  share  src
[root@localhost local]# cd awstats/    ##Switch to awstats directory
[root@localhost awstats]# ls
docs  README.md  tools  wwwroot
[root@localhost awstats]# cd tools/    ##Switch to tools Directory
[root@localhost tools]# ./awstats_configure.pl   ##Start configuration 
##Here is the configuration information
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     ##Fill in profile path

Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y  ##OK to create a new profile

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.kgc.com        ##Enter your domain name

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):
>     ##Enter the profile directory corresponding to the default domain name

> http://localhost/awstats/awstats.pl?config=www.kgc.com
##This page is our website to visit
    Press ENTER to finish...

9. Configure the http main configuration file

[root@localhost tools]# cd /etc/httpd/conf
[root@localhost conf]# vim httpd.conf
<Directory "/usr/local/awstats/wwwroot">      ##Big G to last line
        Options None
        AllowOverride None
#    Order allow,deny   ##Note these two permission settings
#    Allow from all
Require all granted   ##Add allow all

10. Configure the default awstats configuration file

[root@localhost conf]# cd /etc/awstats/
[root@localhost awstats]# ls
awstats.www.kgc.com.conf
[root@localhost awstats]# vim awstats.www.kgc.com.conf  ##Modify configuration
LogFile="/var/log/httpd/access_log"   ##Modify to access log file
DirData="/var/lib/awstats"   ##Data saving directory
[root@localhost awstats]# cd /var/lib/
[root@localhost lib]# mkdir awstats   ##Create data saving directory
[root@localhost lib]# systemctl restart httpd.service  ##Restart Web Services

11. Enter the awstats log analysis system page (change local host to www.kgc.com)

12. Conduct data collection and review your log analysis system page

[root@localhost ~]# cd /usr/local/awstats/tools
[root@localhost tools]# ./awstats_updateall.pl now

13. Optimize the update data, optimize the web address

[root@localhost tools]# crontab -e   ##Create recurring scheduled tasks
*/5 * * * * /usr/local/awstats/tools/awstats_updataall.pl now ##Refresh every five minutes
[root@localhost tools]# cd /var/www/html  ##Switch to site
[root@localhost html]# vim aws.html  ##Optimize web address

<html>
 <head>
     <meta http-equiv=refresh content="0;url=http://www.kgc.com/awstats/awstats.pl
?config=www.kgc.com">
 </head>
 <body></body>
</html>

At this time, the awstats log analysis system is completed.

Thank you for reading!

Keywords: Linux vim Apache DNS

Added by breckenridge on Fri, 25 Oct 2019 18:03:22 +0300