Configure a Remote Debian Based Linux Server for AWStats

From CSLabsWiki

Jump to: navigation, search

This How To covers the process of setting up AWStats to generate reports for a remote Debian based Linux system.

At the time this was written the latest version of AWStats was v6.9 .

Contents

Remote System

Install

Create Needed Directories

  • mkdir -p /usr/local/awstats/httpd_logs

Modify httpd.conf

  • /etc/apache2/httpd.conf
# Needed to Export httpd_logs to AWStats on netstat

Alias /httpd_logs "/usr/local/awstats/httpd_logs/"

<Directory "/usr/local/awstats/httpd_logs/">
    Options None
    AllowOverride None
    Order Deny,Allow
    Deny from all
    Allow from 128.153.145.16
    AuthName "Prohibited"
    AuthType Basic
    AuthUserFile /usr/local/awstats/htpasswd.httpd_logs
    Require valid-user
</Directory>

Create htpasswd file

  • htpasswd -c /usr/local/awstats/htpasswd.httpd_logs webuser
    • Enter password

Copy Needed File

  • Copy over /usr/bin/logresolvemerge.pl on NetStat to /usr/local/awstats/

Create Script

  • /usr/local/awstats/httpd_logs.sh
#!/bin/bash

rm /usr/local/awstats/httpd_logs/access_log
gzip -d /var/log/apache2/access.log.*.gz
perl /usr/local/awstats/logresolvemerge.pl /var/log/apache2/access.log* > /usr/local/awstats/httpd_logs/access_log
gzip /var/log/apache2/access.log.*

Make script executable

  • chmod +x /usr/local/awstats/httpd_logs.sh

Run script for first time

  • /usr/local/awstats/httpd_logs.sh

Modify script

  • /usr/local/awstats/httpd_logs.sh
#!/bin/bash

rm /usr/local/awstats/httpd_logs/access_log
perl /usr/local/awstats/logresolvemerge.pl /var/log/apache2/access_log /var/log/apache2/access_log.1 > /usr/local/awstats/httpd_logs/access_log

Modify crontab

  • crontab -e
40 * * * * /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/local/awstats/httpd_logs.sh

Restart Apache

  • /etc/init.d/apache2 restart

AWStats Server

Install

Create Needed Directory

  • mkdir /usr/local/awstats/<server>

Create New Configuration File

  • Copy a current file
    • cp /etc/awstats/awstats.<a_current_server>.conf /etc/awstats/awstats.<new_server>.conf
  • Modify New File
    • Change LogFile="/usr/local/awstats/httpd_logs/<server_name>/access_log"
    • Change SiteDomain="<new_server>"
    • Change HostAliases="<new_server>"

Create Script to Get Logs

  • /usr/local/awstats/httpd_logs/get_logs.sh
#!/bin/bash

rm /usr/local/awstats/<server>/access_log
wget --http-user=webuser --http-password=<enter password here> -O /usr/local/awstats/<server>/access_log "http://<server>/httpd_logs/access_log"

Modify crontab

  • crontab -e
20 * * * * /usr/local/awstats/httpd_logs/get_logs.sh
Personal tools