In this howto we will assume: you are root, you own example.com and have administrative access to create the subdomain stats.example.com.
Installing the EPEL software repository, AWStats and optional components for Geo tracking:
Click the EPEL link for more verbose instructions or give this command:
su -c "http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm"
Then issue this command:
yum --enablerepo=epel install awstats GeoIP-data perl-Geo-IP
Since there is no Centos package for the GeoLiteCity.dat you can get the single file from MaxMind as well as updated GeoIP.dat files here:
http://www.maxmind.com/app/geolitecountry
http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
http://www.maxmind.com/app/geolitecity
http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
If you choose to use only the MaxMind files directly, you can put them in /var/www/GeoIP as follows:
sudo mkdir /var/www/GeoIP; cd /var/www/GeoIP
sudo wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
sudo wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
sudo gunzip GeoIP.dat.gz GeoLiteCity.dat.gz
After successful install of the above software we will make a copy of the default AWStats config that we can use over and over:
Copy default conf so we always have a clean starting point if something goes wrong.
cp /etc/awstats/awstats.model.conf /etc/awstats/awstats.model.conf.orig
Make another copy for our example site.
cp /etc/awstats/awstats.model.conf.orig /etc/awstats/awstats.stats.example.com.conf
Next we create the directories for the new subdomain stats.example.com. For security purposes the default Apache httpd docroot in Centos is /var/www/ :
mkdir /var/www/stats.example.com && mkdir /var/www/stats.example.com/cgi-bin
Next we copy the AWStats program files to our newly created stats.example.com/cgi-bin directory:
cd /usr/share/awstats/wwwroot/ && cp -R * /var/www/stats.example.com/
(For this example we're using: awstats-6.95-1.el5)
Next let’s alter the Apache httpd conf file and add an entry for our new subdomain:
vi /etc/httpd/conf/httpd.conf add this information at the bottom in the vhosts section or in /etc/httpd.conf.d/vhosts.conf either will work:
You should already have a domain configured that you'd like to track the stats of like this:
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
ScriptAlias /cgi-bin/ /var/www/example.com/cgi-bin/
CustomLog logs/example.com_access_log combined
ErrorLog logs/example.com_error_log
</VirtualHost>
We'll be adding this subdomain to track the above domains stats:
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName stats.example.com
DocumentRoot /var/www/stats.example.com
ScriptAlias /cgi-bin/ /var/www/stats.example.com/cgi-bin/
CustomLog logs/example.com.stats_access_log combined
ErrorLog logs/example.com.stats_error_log
## AWstats ##
Alias /classes "/var/www/stats.example.com/classes/"
Alias /css "/var/www/stats.example.com/css/"
Alias /icon "/var/www/stats.example.com/icon/"
ScriptAlias /awstats/ "/var/www/stats.example.com/cgi-bin/"
## End AWstats ##
</VirtualHost>
Next we’ll edit /etc/httpd/conf.d/awstats.conf to include information about our new subdomain at /var/www/stats.example.com:
vi /etc/httpd/conf.d/awstats.conf
<Directory "/var/www/stats.example.com">
DirectoryIndex awstats.pl
Options ExecCGI
Options FollowSymLinks
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Now let’s edit the awstats.stats.example.com.conf we created in Step 2:
vi /etc/awstats/awstats.stats.example.com.conf
We will be editing the following lines:
1. LogFile="/var/log/httpd/example.com_access_log"
2. SiteDomain="stats.example.com"
3. HostAliases="stats.example.com"
4. DirData="/var/www/stats.example.com/"
5. LoadPlugin="geoip GEOIP_STANDARD /var/lib/GeoIP/GeoIP.dat"
(using the yum install method)
6. LoadPlugin="geoip GEOIP_STANDARD /var/www/GeoIP/GeoIP.dat"
(using the MaxMind direct download method)
7. LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /var/www/GeoIP/GeoLiteCity.dat"
(using the MaxMind direct download method)
Note: The LogFile directive must be the same as the httpd CustomLog directive for the site we actually want the stats from (example.com).
Next let’s restart Apache httpd so our changes take effect:
service httpd restart
Next we’ll call the AWStats perl script to automatically update our stats right now:
perl /var/www/stats.example.com/cgi-bin/awstats.pl -config=stats.example.com -update
Finally, to update our stats automatically every hour via cron we do the following:
cd /etc/cron.hourly && vi 01awstats
Add this line, save and exit:
perl /var/www/stats.example.com/cgi-bin/awstats.pl -config=stats.example.com -update > /dev/null 2>&1
chmod 755 01awstats
service crond restart
We can also use htpasswd to secure the directory from prying eyes:
We'll be doing this work as root in the directory: /var/www/stats.example.com
(In the vi editor use i for insert text, esc + :wq to write and quit vi)
htpasswd -s .htpasswds joe
New password: (This is the user Joe's password to access the stats.)
Re-type new password:
Adding password for user joe
Let's Check to see the password was actually added as expected:
vi .htpasswds
joe:{SHA}9Q+DCACuf4OZs8b0E8eR5j1aIVU=
vi /etc/httpd/conf/httpd.conf
Add this to the virtualhost entry for stats.example.com:
1
2
3
4
5
6
7
8
<Directory "/var/www/stats.example.com">
AuthName "Restricted Area"
AuthType Basic
AuthBasicProvider file
AuthUserFile /var/www/stats.example.com/.htpasswds
AuthGroupFile /dev/null
require valid-user
</Directory>
Now, try hitting your site at: http://stats.example.com You should be prompted for a username and password for your user.
If it does not work, try double checking the steps or join #centoshelp or #httpd on Freenode for further assistance.
Troubleshooting
How to test
Explanation troubleshooting basics and expectations.
Testing your configuration:
You should now be able to go to: http://stats.example.com/cgi-bin/awstats.pl and see your sites stats.
If this does not work for you, please go through the howto more slowly and double check every setting as well as your Apache httpd error logs:
Common mistakes are: Typos, file permissions, file ownership, improper or conflicting Apache httpd Options directives or other Apache httpd config errors.
If you do not see the GeoIP data, but the rest of AWStats works, check the SELinux file contexts for the GeoIP files:
ls -alsZ /var/lib/GeoIP/
incorrect SElinux context --> -rw-r--r-- root root system_u:object_r:var_lib_t GeoIP.dat
incorrect SElinux context --> -rw-r--r-- root root system_u:object_r:var_lib_t GeoLiteCity.dat
sudo chcon -t httpd_sys_content_t /var/lib/GeoIP/GeoIP.dat
sudo chcon -t httpd_sys_content_t /var/lib/GeoIP/GeoLiteCity.dat
ls -alsZ /var/lib/GeoIP/
correct SElinux context --> -rw-r--r-- root root system_u:object_r:httpd_sys_content_t GeoIP.dat
correct SElinux context --> -rw-r--r-- root root system_u:object_r:httpd_sys_content_t GeoLiteCity.dat
You should be able to see country/city GeoIP data now if you refresh the page.
No comments:
Post a Comment