Monday, February 8, 2016

Steps to Configure AWStats to Monitor Apache on CentOS and RHEL System

AWStats is a free and very powerful tool that creating statics using log files of web,ftp or mail servers. Below is the steps to configure AWStats on CentOS and RHEL system.
Step 1: Install EPEL Repository.
Install EPEL repository using below commands on RHEL/CentOS Systems.
CentOS/RHEL 6, 32 Bit (i386):
# rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

CentOS/RHEL 6, 64 Bit x86_64):
# rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

CentOS/RHEL 5, 32 Bit (i386):
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

CentOS/RHEL 5, 64 Bit (x86_64):
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

Step 2: Install Apache ( HTTPD ) Web Server.
AWStats required Apache web server to be accessible over web. If you donot have apache install Use below commands else you already have httpd installed skip this step.
# yum install httpd -y
# chkconfig httpd on
# service httpd start

Step 3: Install AWStats Package using Yum.
Install AWStats rpm using yum installer. Its will also install all other dependencies of RPM.
# yum install awstats
Step 4: Configure Apache to access AWStats on Web browser.
By default AWStats creates an Apache configuration file /etc/httpd/conf.d/awstats.conf . Edit this file and make few changes as given below.
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/"
<Directory "/usr/share/awstats/wwwroot">
        DirectoryIndex awstats.pl
        Options ExecCGI
        order deny,allow
        allow from all
</Directory>
<IfModule mod_env.c>
    SetEnv PERL5LIB /usr/share/awstats/lib:/usr/share/awstats/plugins
</IfModule>

Step 5: Create AWStats Configuration File.
Its required to create an configuration file for each of your website for which statics need to generate. Copy AWStats example configuration file with new name and make changes as below.
# cp /etc/awstats/awstats.host.example.com.conf /etc/awstats/awstats.tecadmin.net.conf
# vim /etc/awstats/awstats.tecadmin.net.conf

Update below settings in awstats.tecadmin.net.conf file
LogFile="/var/log/httpd/tecadmin.net-access_log"
SiteDomain="tecadmin.net"
HostAliases="tecadmin.net www.tecadmin.net"
Step 6: Restart Apache Server.
Restart apache server to reload new settings.
# service httpd restart

Step 7: Configure Cron to Update Logs in AWStats .
You need to configure cront to update AWStats database using newly created log entries. Add below script in cron .
# crontab -l
0 2 * * * /usr/bin/perl /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=tecadmin.net -update

Step 8: Access AWStats in Browser.
Use your server ip address or domain name to access AWStats statics. Change domain name at the end of url as per your settings.
http://192.168.1.90/awstats/awstats.pl?config=tecadmin.net

No comments: