Running awstats on Gentoo
Requirements
I'm assuming for this quick guide that you already have a website installed and consequently apache.
emerge -av awstats
A quick breakdown on the use flags from gentookit's equery:
- apache2 : Add Apache2 support
- geoip : Add geoip support for country and city lookup based on IPs
- vhosts : Adds support for installing web-based applications into a virtual-hosting environment
Configuration
Lots of configuration needs to occur for awstats to work correctly:
First, we need to setup a configuration file for the web site so we can update the statistics.
cp /etc/awstats/awstats.model.conf /etc/awstats/awstats.
Where fqdn is the fully qualified domain name of your website you'll be monitoriing. After you've copied the default configuration customize it for your particular website.
Second, you need to enable awstats in your apache vhost configuration:
CustomLog /var/www/localhost/log/apache/production.log combined
Alias /awstats/classes "/usr/share/webapps/awstats/6.9-r1/htdocs/classes/"
Alias /awstats/css "/usr/share/webapps/awstats/6.9-r1/htdocs/css/"
Alias /awstats/icons "/usr/share/webapps/awstats/6.9-r1/htdocs/icon/"
ScriptAlias /awstats/ "/usr/share/webapps/awstats/6.9-r1/hostroot/cgi-bin/"
ScriptAlias /awstats "/usr/share/webapps/awstats/6.9-r1/hostroot/cgi-bin/awstats.pl"
ScriptAlias /awstats.pl "/usr/share/webapps/awstats/6.9-r1/hostroot/cgi-bin/awstats.pl"
<Directory "/usr/share/webapps/awstats/6.9-r1/htdocs">
Options None
AllowOverride None
<IfModule mod_access.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
<Directory "/usr/share/webapps/awstats/6.9-r1/hostroot/cgi-bin">
Options ExecCGI
AllowOverride None
<IfModule mod_access.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
<Directory "/usr/share/webapps/awstats/6.9-r1/hostroot">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory "/usr/share/webapps/awstats/6.9-r1/htdocs/icon">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
And verify the logging output in /etc/apache2/modules.d/00_mod_log_config.conf:
<IfModule log_config_module>
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-Agent}i" agent
LogFormat "%v %h %l %u %t \"%r\" %>s %b %T" script
LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" VLOG=%{VLOG}e" vhost
<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" vhostio
</IfModule>
# The location and format of the access logfile (Common Logfile Format).
# If you do not define any access logfiles within a <VirtualHost>
# container, they will be logged here. Contrariwise, if you *do*
# define per-<VirtualHost> access logfiles, transactions will be
# logged therein and *not* in this file.
CustomLog /var/log/apache2/access_log common
# If you would like to have agent and referer logfiles,
# uncomment the following directives.
#CustomLog /var/log/apache2/referer_log referer
#CustomLog /var/log/apache2/agent_logs agent
# If you prefer a logfile with access, agent, and referer information
# (Combined Logfile Format) you can use the following directive.
#CustomLog /var/log/apache2/access_log combined
</IfModule>
And Lastly, you need to add a cron entry to update the statistics on a regular basis: # AWStats */15 * * * * perl /usr/share/webapps/awstats/6.9-r1/hostroot/cgi-bin/awstats.pl -config=www.alunduil.com -update > /dev/null
Everything should be running smoothly but give your installation some time to begin collecting statistics.
Optimizing Gentoo CFLAGS
Starting Off
Make sure you've at least looked at the following document: [http://www.gentoo.org/doc/en/gcc-optimization.xml](Gentoo Optimization Guide).
Checking Flags
The only real change we want to make to our system are simple things we know will not break it. Thus, we only look at making sure that we have the correct flags for enabling all of the instruction sets that our processor has available.
Checking Processor
grep flags /proc/cpuinfo | grep uniq
This pulls out all of the features of the processor as detected by the kernel. Example output is shown (line breaks added for readability):
alunduil@elijah ~ $ grep flags /proc/cpuinfo | uniq
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr
pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall
nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow rep_good
extd_apicid pni cx16 lahf_lm cmp_legacy svm extapic
cr8_legacy 3dnowprefetch
Checking Default Flags
gcc does a great job of determining what flags should be set by using the new -march=native flag (which you should have set by this point). Using the following command we can double check that all of the instructions we want enabled are enabled:
gcc -Q -c -v -march=native --help=target | grep disabled
If anything appears in the resulting list it's not enabled and should be enabled by adding the appropriate -m flag. For my cpu this results in: -msse3 -m3dnow.
Putting it Together
By adding the original guide with a check for instructions we allow gcc to utilize the instructions that were specifically created for uses we may have (multimedia, extended math, etc).
The resulting CFLAG variable that I placed in my make.conf from the above discussion:
CFLAGS="-march=native -O2 -pipe -msse3 -m3dnow"
Cleaning /etc/portage/package.*
Inroduction
After a while the files in /etc/portage become cluttered with the common, "Let's try this . . . whoops that didn't work . . . let's try this." No matter how hard you try to keep this clean you have probably forgotten something along the way. Installing a testing package then removing it because you found a better one later, etc. Well what's an easy way to clean these files up and make sure that we minimize their sizes and keep our Gentoo system crisp (or as crisp as we can by just managing these files)? I've written some bash one-liners that assist with this and could easily be adapted into a script that automates a lot of the cleaning for you.
In all of these scripts change the /etc/portage/package.use to the file you are interested in cleaning.
Checking for Multiple Occurrences of an Atom Within a File
for atom in $(gawk '{print $1}' /etc/portage/package.use); do [ "$(grep ${atom} /etc/portage/package.use | wc -l)" -gt "1" ] && echo "${atom}"; done
Checking for N Uses of a Use Flag in /etc/portage/package.use
I use this to move frequently used use flags to /etc/make.conf if it seems appropriate.
for flag in $(gawk '{print $2}' /etc/portage/package.use); do [ "$(grep "${flag}" /etc/portage/package.use | wc -l)" -gt "2" ] && echo "${flag}"; done
Checking for Removed Atoms Within a File
for atom in $(gawk '{print $1}' /etc/portage/package.use); do [ "$(portageq match / ${atom} | wc -l)" -lt "1" ] && echo "${atom}"; done