Monitoring

Awstats – Log Analyzer To Analize Apache Logs On CentOS,Fedora and RHEL System

OVERVIEW:

Awstats is powerful log analyzer tool which provides all information about website visit. Awstats use CGI scripts to generate graphical statics using any logs file. Using Awstats we can analyze Apache logs, Mail server logs and FTP logs and many more.

In this tutorial I am going to explain how we can install and configure Awstats on CentOS,Fedora and RHEL Systems.

EPEL REPOSITORY INSTALLATION

Follow the below command to install EPEL Repository on system.

#yum install epel-release

APACHE INSTALLATION

Follow the below command to install Apache on system.

#yum install httpd

After installing Apache start httpd service.

#service httpd start

AWSTATS INSTALLATION

After installing Apache web server follow the below command to install Awstats on system.

#yum install awstats

You will get some output like below.

Loaded plugins: priorities, update-motd, upgrade-helper
epel/x86_64/metalink | 15 kB 00:00
epel/x86_64 | 4.3 kB 00:00
epel/x86_64/group_gz | 150 kB 00:00
epel/x86_64/updateinfo | 736 kB 00:00
epel/x86_64/primary_db | 5.9 MB 00:00
1316 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package awstats.noarch 0:7.0-3.el6 will be installed
--> Processing Dependency: perl(URI::Escape) for package: awstats-7.0-3.el6.noarch
--> Processing Dependency: perl(Switch) for package: awstats-7.0-3.el6.noarch
--> Processing Dependency: perl(LWP::UserAgent) for package: awstats-7.0-3.el6.noarch
--> Processing Dependency: perl(HTML::Entities) for package: awstats-7.0-3.el6.noarch
--> Running transaction check
---> Package perl-HTML-Parser.x86_64 0:3.71-4.7.amzn1 will be installed
--> Processing Dependency: perl(HTML::Tagset) >= 3 for package: perl-HTML-Parser-3.71-4.7.amzn1.x86_64
--> Processing Dependency: perl(HTTP::Headers) for package: perl-HTML-Parser-3.71-4.7.amzn1.x86_64
---> Package perl-Switch.noarch 0:2.16-7.5.amzn1 will be installed
---> Package perl-URI.noarch 0:1.60-9.8.amzn1 will be installed
--> Processing Dependency: perl(Business::ISBN) for package: perl-URI-1.60-9.8.amzn1.noarch
---> Package perl-libwww-perl.noarch 0:6.05-2.17.amzn1 will be installed
--> Processing Dependency: perl(HTTP::Daemon) >= 6 for package: perl-libwww-perl-6.05-2.17.amzn1.noarch
--> Processing Dependency: perl(WWW::RobotRules) >= 6 for package: perl-libwww-perl-6.05-2.17.amzn1.noarch
--> Processing Dependency: perl(HTTP::Negotiate) >= 6 for package: perl-libwww-perl-6.05-2.17.amzn1.noarch
--> Processing Dependency: perl(HTTP::Date) >= 6 for package: perl-libwww-perl-6.05-2.17.amzn1.noarch
--> Processing Dependency: perl(HTTP::Cookies) >= 6 for package: perl-libwww-perl-6.05-2.17.amzn1.noarch
--> Processing Dependency: perl(Net::HTTP) >= 6.04 for package: perl-libwww-perl-6.05-2.17.amzn1.noarch
--> Processing Dependency: perl(File::Listing) >= 6 for package: perl-libwww-perl-6.05-2.17.amzn1.noarch
--> Processing Dependency: perl(LWP::MediaTypes) >= 6 for package: perl-libwww-perl-6.05-2.17.amzn1.noarch
--> Processing Dependency: perl(Encode::Locale) for package: perl-libwww-perl-6.05-2.17.amzn1.noarch
--> Running transaction check
---> Package perl-Business-ISBN.noarch 0:2.06-2.7.amzn1 will be installed
--> Processing Dependency: perl(Business::ISBN::Data) >= 20120719.001 for package: perl-Business-ISBN-2.06-2.7.amzn1.noarch
---> Package perl-Encode-Locale.noarch 0:1.03-5.8.amzn1 will be installed
---> Package perl-File-Listing.noarch 0:6.04-7.11.amzn1 will be installed
---> Package perl-HTML-Tagset.noarch 0:3.20-15.7.amzn1 will be installed
---> Package perl-HTTP-Cookies.noarch 0:6.01-5.12.amzn1 will be installed
---> Package perl-HTTP-Daemon.noarch 0:6.01-5.11.amzn1 will be installed
---> Package perl-HTTP-Date.noarch 0:6.02-8.8.amzn1 will be installed
--> Processing Dependency: perl(Time::Zone) for package: perl-HTTP-Date-6.02-8.8.amzn1.noarch
---> Package perl-HTTP-Message.noarch 0:6.06-6.10.amzn1 will be installed
--> Processing Dependency: perl(IO::HTML) for package: perl-HTTP-Message-6.06-6.10.amzn1.noarch
---> Package perl-HTTP-Negotiate.noarch 0:6.01-5.12.amzn1 will be installed
---> Package perl-LWP-MediaTypes.noarch 0:6.02-2.9.amzn1 will be installed
---> Package perl-Net-HTTP.noarch 0:6.06-2.11.amzn1 will be installed
--> Processing Dependency: perl(IO::Socket::SSL) >= 1.38 for package: perl-Net-HTTP-6.06-2.11.amzn1.noarch
---> Package perl-WWW-RobotRules.noarch 0:6.02-5.12.amzn1 will be installed
--> Running transaction check
---> Package perl-Business-ISBN-Data.noarch 0:20120719.001-2.7.amzn1 will be installed
---> Package perl-IO-HTML.noarch 0:1.00-2.5.amzn1 will be installed
---> Package perl-IO-Socket-SSL.noarch 0:1.94-3.13.amzn1 will be installed
--> Processing Dependency: perl(Net::SSLeay) >= 1.21 for package: perl-IO-Socket-SSL-1.94-3.13.amzn1.noarch
--> Processing Dependency: perl(IO::Socket::IP) >= 0.20 for package: perl-IO-Socket-SSL-1.94-3.13.amzn1.noarch
--> Processing Dependency: perl(Net::LibIDN) for package: perl-IO-Socket-SSL-1.94-3.13.amzn1.noarch
--> Processing Dependency: perl(Net::SSLeay) for package: perl-IO-Socket-SSL-1.94-3.13.amzn1.noarch
---> Package perl-TimeDate.noarch 1:2.30-2.7.amzn1 will be installed
--> Running transaction check
---> Package perl-IO-Socket-IP.noarch 0:0.21-4.5.amzn1 will be installed
---> Package perl-Net-LibIDN.x86_64 0:0.12-15.6.amzn1 will be installed
---> Package perl-Net-SSLeay.x86_64 0:1.65-2.10.amzn1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================================
Installing:
awstats noarch 7.0-3.el6 epel 1.2 M
Installing for dependencies:
perl-Business-ISBN noarch 2.06-2.7.amzn1 amzn-main 25 k
perl-Business-ISBN-Data noarch 20120719.001-2.7.amzn1 amzn-main 26 k
perl-Encode-Locale noarch 1.03-5.8.amzn1 amzn-main 16 k
perl-File-Listing noarch 6.04-7.11.amzn1 amzn-main 13 k
perl-HTML-Parser x86_64 3.71-4.7.amzn1 amzn-main 119 k
perl-HTML-Tagset noarch 3.20-15.7.amzn1 amzn-main 18 k
perl-HTTP-Cookies noarch 6.01-5.12.amzn1 amzn-main 27 k
perl-HTTP-Daemon noarch 6.01-5.11.amzn1 amzn-main 21 k
perl-HTTP-Date noarch 6.02-8.8.amzn1 amzn-main 14 k
perl-HTTP-Message noarch 6.06-6.10.amzn1 amzn-main 84 k
perl-HTTP-Negotiate noarch 6.01-5.12.amzn1 amzn-main 17 k
perl-IO-HTML noarch 1.00-2.5.amzn1 amzn-main 24 k
perl-IO-Socket-IP noarch 0.21-4.5.amzn1 amzn-main 38 k
perl-IO-Socket-SSL noarch 1.94-3.13.amzn1 amzn-main 118 k
perl-LWP-MediaTypes noarch 6.02-2.9.amzn1 amzn-main 25 k
perl-Net-HTTP noarch 6.06-2.11.amzn1 amzn-main 29 k
perl-Net-LibIDN x86_64 0.12-15.6.amzn1 amzn-main 29 k
perl-Net-SSLeay x86_64 1.65-2.10.amzn1 amzn-main 361 k
perl-Switch noarch 2.16-7.5.amzn1 amzn-main 23 k
perl-TimeDate noarch 1:2.30-2.7.amzn1 amzn-main 53 k
perl-URI noarch 1.60-9.8.amzn1 amzn-main 109 k
perl-WWW-RobotRules noarch 6.02-5.12.amzn1 amzn-main 18 k
perl-libwww-perl noarch 6.05-2.17.amzn1 amzn-main 215 k

Transaction Summary
===================================================================================================================================================
Install 1 Package (+23 Dependent packages)

Total download size: 2.5 M
Installed size: 6.6 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/latest/epel/packages/awstats-7.0-3.el6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Public key for awstats-7.0-3.el6.noarch.rpm is not installed
(1/24): awstats-7.0-3.el6.noarch.rpm | 1.2 MB 00:00
(2/24): perl-Business-ISBN-2.06-2.7.amzn1.noarch.rpm | 25 kB 00:00
(3/24): perl-Business-ISBN-Data-20120719.001-2.7.amzn1.noarch.rpm | 26 kB 00:00
(4/24): perl-Encode-Locale-1.03-5.8.amzn1.noarch.rpm | 16 kB 00:00
(5/24): perl-File-Listing-6.04-7.11.amzn1.noarch.rpm | 13 kB 00:00
(6/24): perl-HTML-Parser-3.71-4.7.amzn1.x86_64.rpm | 119 kB 00:00
(7/24): perl-HTML-Tagset-3.20-15.7.amzn1.noarch.rpm | 18 kB 00:00
(8/24): perl-HTTP-Cookies-6.01-5.12.amzn1.noarch.rpm | 27 kB 00:00
(9/24): perl-HTTP-Daemon-6.01-5.11.amzn1.noarch.rpm | 21 kB 00:00
(10/24): perl-HTTP-Date-6.02-8.8.amzn1.noarch.rpm | 14 kB 00:00
(11/24): perl-HTTP-Message-6.06-6.10.amzn1.noarch.rpm | 84 kB 00:00
(12/24): perl-HTTP-Negotiate-6.01-5.12.amzn1.noarch.rpm | 17 kB 00:00
(13/24): perl-IO-HTML-1.00-2.5.amzn1.noarch.rpm | 24 kB 00:00
(14/24): perl-IO-Socket-IP-0.21-4.5.amzn1.noarch.rpm | 38 kB 00:00
(15/24): perl-IO-Socket-SSL-1.94-3.13.amzn1.noarch.rpm | 118 kB 00:00
(16/24): perl-LWP-MediaTypes-6.02-2.9.amzn1.noarch.rpm | 25 kB 00:00
(17/24): perl-Net-HTTP-6.06-2.11.amzn1.noarch.rpm | 29 kB 00:00
(18/24): perl-Net-LibIDN-0.12-15.6.amzn1.x86_64.rpm | 29 kB 00:00
(19/24): perl-Net-SSLeay-1.65-2.10.amzn1.x86_64.rpm | 361 kB 00:00
(20/24): perl-Switch-2.16-7.5.amzn1.noarch.rpm | 23 kB 00:00
(21/24): perl-TimeDate-2.30-2.7.amzn1.noarch.rpm | 53 kB 00:00
(22/24): perl-URI-1.60-9.8.amzn1.noarch.rpm | 109 kB 00:00
(23/24): perl-WWW-RobotRules-6.02-5.12.amzn1.noarch.rpm | 18 kB 00:00
(24/24): perl-libwww-perl-6.05-2.17.amzn1.noarch.rpm | 215 kB 00:00
---------------------------------------------------------------------------------------------------------------------------------------------------
Total 2.3 MB/s | 2.5 MB 00:00:01
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Importing GPG key 0x0608B895:
Userid : "EPEL (6) <[email protected]>"
Fingerprint: 8c3b e96a f230 9184 da5c 0dae 3b49 df2a 0608 b895
Package : epel-release-6-8.9.amzn1.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : perl-LWP-MediaTypes-6.02-2.9.amzn1.noarch 1/24
Installing : perl-Encode-Locale-1.03-5.8.amzn1.noarch 2/24
Installing : perl-IO-HTML-1.00-2.5.amzn1.noarch 3/24
Installing : perl-Net-LibIDN-0.12-15.6.amzn1.x86_64 4/24
Installing : perl-IO-Socket-IP-0.21-4.5.amzn1.noarch 5/24
Installing : perl-Switch-2.16-7.5.amzn1.noarch 6/24
Installing : perl-Business-ISBN-Data-20120719.001-2.7.amzn1.noarch 7/24
Installing : perl-Business-ISBN-2.06-2.7.amzn1.noarch 8/24
Installing : perl-URI-1.60-9.8.amzn1.noarch 9/24
Installing : perl-WWW-RobotRules-6.02-5.12.amzn1.noarch 10/24
Installing : 1:perl-TimeDate-2.30-2.7.amzn1.noarch 11/24
Installing : perl-HTTP-Date-6.02-8.8.amzn1.noarch 12/24
Installing : perl-HTTP-Message-6.06-6.10.amzn1.noarch 13/24
Installing : perl-HTTP-Daemon-6.01-5.11.amzn1.noarch 14/24
Installing : perl-HTTP-Cookies-6.01-5.12.amzn1.noarch 15/24
Installing : perl-HTTP-Negotiate-6.01-5.12.amzn1.noarch 16/24
Installing : perl-File-Listing-6.04-7.11.amzn1.noarch 17/24
Installing : perl-Net-SSLeay-1.65-2.10.amzn1.x86_64 18/24
Installing : perl-IO-Socket-SSL-1.94-3.13.amzn1.noarch 19/24
Installing : perl-Net-HTTP-6.06-2.11.amzn1.noarch 20/24
Installing : perl-HTML-Tagset-3.20-15.7.amzn1.noarch 21/24
Installing : perl-HTML-Parser-3.71-4.7.amzn1.x86_64 22/24
Installing : perl-libwww-perl-6.05-2.17.amzn1.noarch 23/24
Installing : awstats-7.0-3.el6.noarch 24/24
Verifying : perl-HTML-Tagset-3.20-15.7.amzn1.noarch 1/24
Verifying : perl-URI-1.60-9.8.amzn1.noarch 2/24
Verifying : perl-Net-SSLeay-1.65-2.10.amzn1.x86_64 3/24
Verifying : 1:perl-TimeDate-2.30-2.7.amzn1.noarch 4/24
Verifying : perl-WWW-RobotRules-6.02-5.12.amzn1.noarch 5/24
Verifying : perl-Business-ISBN-Data-20120719.001-2.7.amzn1.noarch 6/24
Verifying : perl-LWP-MediaTypes-6.02-2.9.amzn1.noarch 7/24
Verifying : awstats-7.0-3.el6.noarch 8/24
Verifying : perl-Encode-Locale-1.03-5.8.amzn1.noarch 9/24
Verifying : perl-Switch-2.16-7.5.amzn1.noarch 10/24
Verifying : perl-HTTP-Date-6.02-8.8.amzn1.noarch 11/24
Verifying : perl-Business-ISBN-2.06-2.7.amzn1.noarch 12/24
Verifying : perl-File-Listing-6.04-7.11.amzn1.noarch 13/24
Verifying : perl-Net-HTTP-6.06-2.11.amzn1.noarch 14/24
Verifying : perl-libwww-perl-6.05-2.17.amzn1.noarch 15/24
Verifying : perl-IO-Socket-IP-0.21-4.5.amzn1.noarch 16/24
Verifying : perl-HTTP-Daemon-6.01-5.11.amzn1.noarch 17/24
Verifying : perl-HTML-Parser-3.71-4.7.amzn1.x86_64 18/24
Verifying : perl-Net-LibIDN-0.12-15.6.amzn1.x86_64 19/24
Verifying : perl-HTTP-Cookies-6.01-5.12.amzn1.noarch 20/24
Verifying : perl-IO-Socket-SSL-1.94-3.13.amzn1.noarch 21/24
Verifying : perl-HTTP-Negotiate-6.01-5.12.amzn1.noarch 22/24
Verifying : perl-HTTP-Message-6.06-6.10.amzn1.noarch 23/24
Verifying : perl-IO-HTML-1.00-2.5.amzn1.noarch 24/24

Installed:
awstats.noarch 0:7.0-3.el6

Dependency Installed:
perl-Business-ISBN.noarch 0:2.06-2.7.amzn1 perl-Business-ISBN-Data.noarch 0:20120719.001-2.7.amzn1 perl-Encode-Locale.noarch 0:1.03-5.8.amzn1
perl-File-Listing.noarch 0:6.04-7.11.amzn1 perl-HTML-Parser.x86_64 0:3.71-4.7.amzn1 perl-HTML-Tagset.noarch 0:3.20-15.7.amzn1
perl-HTTP-Cookies.noarch 0:6.01-5.12.amzn1 perl-HTTP-Daemon.noarch 0:6.01-5.11.amzn1 perl-HTTP-Date.noarch 0:6.02-8.8.amzn1
perl-HTTP-Message.noarch 0:6.06-6.10.amzn1 perl-HTTP-Negotiate.noarch 0:6.01-5.12.amzn1 perl-IO-HTML.noarch 0:1.00-2.5.amzn1
perl-IO-Socket-IP.noarch 0:0.21-4.5.amzn1 perl-IO-Socket-SSL.noarch 0:1.94-3.13.amzn1 perl-LWP-MediaTypes.noarch 0:6.02-2.9.amzn1
perl-Net-HTTP.noarch 0:6.06-2.11.amzn1 perl-Net-LibIDN.x86_64 0:0.12-15.6.amzn1 perl-Net-SSLeay.x86_64 0:1.65-2.10.amzn1
perl-Switch.noarch 0:2.16-7.5.amzn1 perl-TimeDate.noarch 1:2.30-2.7.amzn1 perl-URI.noarch 0:1.60-9.8.amzn1
perl-WWW-RobotRules.noarch 0:6.02-5.12.amzn1 perl-libwww-perl.noarch 0:6.05-2.17.amzn1

Complete!

APACHE CONFIGURATION FOR AWSTATS

After installing Awstats you will need to edit its default configurations file “/etc/httpd/conf.d/awstats.conf“. To access Awstats remotely you will need to edit its configuration file.Follow the below configuration file to access Awstats remotely.

#vim /etc/httpd/conf.d/awstats.conf

#
# Content of this file, with correct values, can be automatically added to
# your Apache server by using the AWStats configure.pl tool.
#
# If using Windows and Perl ActiveStat, this is to enable Perl script as CGI.
#ScriptInterpreterSource registry
#
# Directives to add to your Apache conf file to allow use of AWStats as a CGI.
# Note that path "/usr/share/awstats/" must reflect your AWStats install path.
#
Alias /awstatsclasses "/usr/share/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/share/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/share/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/share/awstats/wwwroot/cgi-bin/"
#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory "/usr/share/awstats/wwwroot">
Options None
AllowOverride None
#Order allow,deny
#Allow from 127.0.0.1

<IfModule mod_authz_core.c>
 # Apache 2.4
 <RequireAny>
 Require ip 127.0.0.1
 Require ip ::1
 </RequireAny>
 </IfModule>
 <IfModule !mod_authz_core.c>
 # Apache 2.2
 Order Deny,Allow
 Deny from All
 Allow from All
 Allow from ::1
 </IfModule>
</Directory>

# Additional Perl modules
<IfModule mod_env.c>
SetEnv PERL5LIB /usr/share/awstats/lib:/usr/share/awstats/plugins
</IfModule>

Save and exit.

CREATE CONFIGURATION FILE FOR EACH VIRTUAL HOST

You will need to create Awstats config file for each virtual host like below.

Awstats configuration file for looklinux.com

# cp /etc/awstats/awstats.localhost.localdomain.conf /etc/awstats/awstats.looklinux.com.conf

Awstats configuration file for example.com

# cp /etc/awstats/awstats.localhost.localdomain.conf /etc/awstats/awstats.example.com.conf

After creating Awstats configuration file for each vhost you will need to make some changing like below.

Open “/etc/awstats/awstats.looklinux.com.conf” update LogFile,SiteDomain and HostAliases for each vhost file.

LogFile="/var/log/httpd/looklinux.com_access_log"
SiteDomain="looklinux.com"
HostAliases="looklinux.com www.looklinux.com"

Same for example.com open “/etc/awstats/awstats.example.com.conf” update LogFile,SiteDomain and HostAliases for each vhost file.

LogFile="/var/log/httpd/example.com_access_log"
SiteDomain="example.com"
HostAliases="example.com www.example.com"

Now Awstats is configured for each virtual host.

DATA COMPUTING AND LOG UPDATING

Now follow below command to compute and update logs files.

For looklinux.com

# perl /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=looklinux.com -update

For example.com

# perl /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=example.com -update

You will get some output like below.

Create/Update database for config "/etc/awstats/awstats.looklinux.com.conf" by AWStats version 7.0 (build 1.971)
From data in log file "/var/log/nginx/vhost/looklinix.com_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: 673
Found 673 dropped records,
Found 0 comments,
Found 0 blank records,
Found 0 corrupted records,
Found 0 old records,
Found 0 new qualified records.

SCHEDULE CRON TO COMPUTE DATA AUTOMATICALLY

You can set cron job for update logs regularly (e.g, each 5 minutes, once a day, each hours etc..) according to your requirement.

#crontab -e

0 1 * * * /usr/bin/perl /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=looklinux.com -update

0 1 * * * /usr/bin/perl /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=example.com -update

ACCESS AWSTATS STATICS

Open your browser and use your domain name and IP address to access Awstats statics. Follow below example and change as per your settings.

http://looklinux.com/awstats/awstats.pl?config=looklinux.com
looklinux-awstats-example

I hope this article will be helpful to understand how we can install and configure Awstats on CentOS,Fedora and RHEL systems. Read our another article Googler – Command Line Google Search On Linux System and Easy Steps To Install Python3 On CentOS.  If you have any queries and problem please comment in comment section or you can also ask your question.

Thanks:)

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment