Setting Up GeoIP Lookup in awstats on RHEL5

I assume awstats (and awstats-selinux) are already installed.

Step 1: Install the most excellent GeoLite data from MaxMind

mkdir /usr/local/share/GeoIP
cd /usr/local/share/GeoIP
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
wget http://geolite.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz
gunzip *gz

Step 2: Install the GeoIP C API

There will be a dependency on zlib so make sure zlib-devel is installed:

yum install zlib-devel

Now download and compile:

wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.6.tar.gz
tar xvzf GeoIP-1.4.6.tar.gz
cd GeoIP-1.4.6
make check
sudo make install

Make it possible to link against the geoip library:

sudo echo '/usr/local/lib' > /etc/ld.so.conf.d/geoip.conf
sudo ldconfig

Step 3: Install the Geo::IP Perl Module

cd ~
wget http://geolite.maxmind.com/download/geoip/api/perl/Geo-IP-1.38.tar.gz
tar xzvf Geo-IP-1.38.tar.gz
cd Geo-IP-1.38
perl Makefile.PL LIBS='-L/usr/local/lib'
make test
sudo make install

Step 4: Enable the GeoIP Plugin

Edit /etc/awstats/awstats.yourdomain.conf to add these lines:

LoadPlugin="geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat"
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /usr/local/share/GeoIP/GeoLiteCity.dat"
LoadPlugin="geoip_org_maxmind GEOIP_STANDARD /usr/local/share/GeoIP/GeoIPASNum.dat"

Reference: GeoIP Information for AWStats
Speedup Awstats by using GeoIP instead of DNS Lookups

Cacti Segfaulting on CentOS5

I was getting Cacti set up and was having trouble with PHP. Specifically, it appeared that enabling the Cacti cron job caused a PHP segfault. I looked in /etc/cron.d/cacti to see what was being run:

cat /etc/cron.d/cacti
#*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1

Then I ran it from the command line myself:

# php -v
PHP 5.1.6 (cli) (built: Jan 13 2010 17:13:05)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

# php /usr/share/cacti/poller.php
Segmentation fault

Sure enough, an ugly error was recorded in /var/log/messages:

kernel: php[5250]: segfault at bf29ce64 ip b788cbf3 sp bf29cdc4 error 6 in libc-2.5.so[b7851000+13f000]

It turns out that this is what happens when you bork the permissions on cacti's MySQL table. After issuing a command like the following to MySQL, my segfault went away.

GRANT ALL ON cacti.* TO 'cactiusername'@'localhost' IDENTIFIED BY 'secret';

Performance presentation, Des Moines Web Geeks

Matt Nuzum, the webmaster of ubuntu.com, invited me to speak at the Des Moines Web Geeks meeting last night. The venue, Impromptu Studios, was a bit hard to find. There were no signs for Impromptu Studios, but after lurking in dark alleyways for a while I eventually discovered what should have been obvious from the beginning: enter the furniture store with the "Closed" sign on the front and go up the stairs past the disused lavatory with a sign on the door saying "Beware of the Leopard."

The group was great and we talked for about an hour and half about bottlenecks and optimization. I even went home with a Django book!

Since this was a diverse group I tried to talk about things that everyone has to deal with (bottlenecks for storage, network, memory and CPU) rather than anything Drupal-specific.

As promised, last night's slides: Performance, Scalability on the Server Side (PDF, 1MB).

Installing mytop on RHEL5

I recently installed mytop on a new 64-bit Red Hat Enterprise Linux 5.4 server. Here are my notes.

The mytop program requires two Perl modules. So let's make sure those are installed first. The perl-DBI package is usually installed as a dependency already. Check if it's there:

# yum list installed *DBI
Loaded plugins: rhnplugin, security
Installed Packages
perl-DBI.x86_64             1.52-2.el5           installed

Install TermReadKey module, also known as Term::ReadKey. I am installing this from the EPEL repository, which I regard as very safe (in terms of compatibility, longevity and maintenance). If you're not set up with EPEL, you can do

# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

Anyway, installing Term::ReadKey from EPEL:

# yum install perl-TermReadKey
Loaded plugins: rhnplugin, security
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package perl-TermReadKey.x86_64 0:2.30-4.el5 set to be updated
--> Finished Dependency Resolution
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : perl-TermReadKey                                                                                                                                                 1/1

  perl-TermReadKey.x86_64 0:2.30-4.el5

Now it's time to get mytop.

# wget http://jeremy.zawodny.com/mysql/mytop/mytop-1.6.tar.gz
# tar zxvf mytop-1.6.tar.gz
# cd mytop-1.6
# perl Makefile.PL
Writing Makefile for mytop

# make test
cp mytop blib/script/mytop
/usr/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/mytop
PERL_DL_NONLAZY=1 /usr/bin/perl "-Iblib/lib" "-Iblib/arch" test.pl
ok 1

# make
Manifying blib/man1/mytop.1

# make install
Installing /usr/share/man/man1/mytop.1
Installing /usr/bin/mytop
Writing /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/mytop/.packlist
Appending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod

# which mytop



Subscribe to RSS - CentOS5