Author |
Topic: Install AWStats on AWS EC2 instance |
|
AwsEC2 member offline |
|
posts: |
39 |
joined: |
08/28/2012 |
from: |
CA |
|
|
|
|
|
Install AWStats on AWS EC2 instance |
Download and install AWStats
# /etc/init.d/httpd stop
# mkdir /usr/local
# cd /usr/local
# wget http://prdownloads.sourceforge.net/awstats/awstats-7.0.tar.gz
# tar -zvxf awstats-7.0.tar.gz
# mv awstats-7.0 awstats
# chown -R root:root awstats
|
|
|
|
|
|
|
AwsEC2 member offline |
|
posts: |
39 |
joined: |
08/28/2012 |
from: |
CA |
|
|
|
|
|
Configure httpd to support AWStats |
AWStats is now installed under /usr/local/awstats, but you may need to make some minor modifications to the Apache configuration file in order to use it via a web browser.
Step 1. Set global permisstion for the AWStats directory
<Directory "/usr/local/awstats/wwwroot/cgi-bin">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Step 2. Local within each virtual host
<VirtualHost *:80>
ServerName example1.com
ServerAlias www.example1.com
DocumentRoot /home/ec2-user/example1.com/html
# http://example1.com/cgi-bin/awstats/awstats.pl
ScriptAlias /cgi-bin/awstats /usr/local/awstats/wwwroot/cgi-bin
Alias /awstats /usr/local/awstats/wwwroot
CustomLog "/home/ec2-user/example1.com/access_log" "combined"
</VirtualHost>
|
|
|
|
|
|
|
AwsEC2 member offline |
|
posts: |
39 |
joined: |
08/28/2012 |
from: |
CA |
|
|
|
|
|
Configure AWStats for each virtul host |
# cp /usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf /etc/awstats/awstats.example1.com.conf
# vi /etc/awstats/awstats.example1.com.conf
Make sure the following:
LogFile="/home/ec2-user/example1.com/access_log"
LogType=W
LogFormat=1
SiteDomain="example1.com"
DirData="/home/ec2-user/example1.com/awstats"
DirCgi="/cgi-bin/awstats"
DirIcons="/awstats/icon"
AllowToUpdateStatsFromBrowser=1
Here DirData is used for store updated statistics results. If it does not exist, create one first. Also, as the statistics is allowed to be updated from browser (AllowToUpdateStatsFromBrowser=1), DirData may have to be set to allow write permission for nobody (apache).
# mkdir /home/ec2-user/example1.com/awstats
# chmod 777 /home/ec2-user/example1.com/awstats
|
|
|
|
|
|
|
AwsEC2 member offline |
|
posts: |
39 |
joined: |
08/28/2012 |
from: |
CA |
|
|
|
|
|
Update Statistics |
/usr/local/awstats/tools/awstats_updateall.pl now
-confdir="/etc/awstats/"
-awstatsprog="/usr/local/awstats/wwwroot/cgi-bin/awstats.pl"
If you want to periodically run the above update, you can put the script into /ect/cron.d as follows:
List of scripts:
$ ls -l /etc/cron.d
-rw-r--r-- 1 root root 47 Jul 7 2008 awstatcronsetup
-rw-r--r-- 1 root root 151 Sep 6 23:55 awstats
AWStats cron setup:
$ cat /etc/cron.d/awstatcronsetup
55 23 * * * root /usr/share/awstats/cronsetup
AWStats script setup:
$ cat /usr/share/awstats/cronsetup
#!/bin/bash
hour=`echo $[$RANDOM % 24]`
if [ $hour -gt 9 ]; then
echo "00 $hour * * * root /usr/share/awstats/awstats_updateall.pl now
-awstatsprog=/var/www/cgi-bin/awstats/awstats.pl
-configdir=/etc/awstats/ >/dev/null 2>&1" >/etc/cron.d/awstats
else
echo "00 0$hour * * * root /usr/share/awstats/awstats_updateall.pl now
-awstatsprog=/var/www/cgi-bin/awstats/awstats.pl
-configdir=/etc/awstats/ >/dev/null 2>&1" >/etc/cron.d/awstats
fi
/sbin/service crond restart >/dev/null 2>&1
AWStats update cron script:
$ cat /etc/cron.d/awstats
00 18 * * * root /usr/share/awstats/awstats_updateall.pl now
-awstatsprog=/var/www/cgi-bin/awstats/awstats.pl
-configdir=/etc/awstats/ >/dev/null 2>&1
Details can be found here: http://forumeasy.com/forums/thread.jsp?tid=134670661180&fid=javaprof12
|
|
|
|
|
|
|
AwsEC2 member offline |
|
posts: |
39 |
joined: |
08/28/2012 |
from: |
CA |
|
|
|
|
|
Start the server |
# /etc/init.d/httpd start
Then verify AWStats by url:
http://example1.com/cgi-bin/awstats/awstats.pl
|
|
|
|
|
|
|
AwsEC2 member offline |
|
posts: |
39 |
joined: |
08/28/2012 |
from: |
CA |
|
|
|
|
|
Awstats update cron job on AWS EC2 instance |
Finally, a simpler version (fixed time) of cron job is placed:
$ cat /etc/cron.d/awstats
45 03 * * * root /usr/local/awstats/tools/awstats_updateall.pl now
-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
-configdir=/etc/awstats/ >/dev/null 2>&1
|
|
|
|
|
|
|
AwsEC2 member offline |
|
posts: |
39 |
joined: |
08/28/2012 |
from: |
CA |
|
|
|
|
|
Protect your Awstats statistics with password |
For most cases, you may want to prevent your web statistics from public access. You can do it by protecting your script directory with a password challenge.
Replace what in 'Step 1. Set global permisstion for the AWStats directory' with the following:
<Directory /usr/local/awstats/wwwroot/cgi-bin>
AuthType Basic
AuthName "AWStats - Web, FTP, and Mail Statistics"
AuthUserFile /usr/local/awstats/wwwroot/.awstats.pwd
Require valid-user
</Directory>
For details, please check the link below:
How to protect Apache web resources
|
|
|
|
|
|
|