Maxmind’s GeoIP.dat.gz location change

4 Comments

Today I noticed that AWStats, the web traffic analysis tool, had stopped generating valid reports since November 23. After spending about 3 whole hours trying to figure out what on earth had happened and having checked all the things that could have gone wrong, I went through all the automatic emails my server had sent me during the last 4 days and, finally, found out that a cronjob, which updates the GeoIP database on a weekly basis, instead of saving the actual database, it had saved the HTML error document, because the actual database could not be found at its normal location on the web. Maxmind, the company that publishes the database had just moved it to a new location without even bothering to create a symlink! AWStats on the other hand did not print any relevant error message. It just behaved strangely. As soon as I fixed the URL to GeoIP.dat.gz inside the cronjob and updated the files, all things came back to normal.

Update: Talking about URLs without actually writing them is a bit awkward, so here is the ugly script I use to update the free GeoIP databases from Maxmind:

#! /bin/sh
 
LIMIT="100k"
 
# Update GeoLite Country (GeoIP default)
wget --limit-rate=$LIMIT http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz -O /usr/share/GeoIP/GeoIP.dat.gz
rm -f /usr/share/GeoIP/GeoIP.dat
gunzip /usr/share/GeoIP/GeoIP.dat.gz
 
# Update GeoLite City
wget --limit-rate=$LIMIT http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz -O /usr/share/GeoIP/GeoLiteCity.dat.gz
rm -f /usr/share/GeoIP/GeoLiteCity.dat
gunzip /usr/share/GeoIP/GeoLiteCity.dat.gz

It shows the current URLs for the free or lite versions of GeoLite Country (GeoIP.dat) and GeoLiteCity databases. Currently, I have enabled the first one in AWStats.

Note to self. I should urgently add some checks prior to replacing the current databases. This goes in the TODO list.

Maxmind’s GeoIP.dat.gz location change by George Notaras is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Copyright © 2008 - Some Rights Reserved

George Notaras avatar

About George Notaras

George Notaras is the editor of the G-Loaded Journal, a technical blog about Free and Open-Source Software. George, among other things, is an enthusiast self-taught GNU/Linux system administrator. He has created this web site to share the IT knowledge and experience he has gained over the years with other people. George primarily uses CentOS and Fedora. He has also developed some open-source software projects in his spare time.

4 responses on “Maxmind’s GeoIP.dat.gz location change

  1. BOK Permalink →

    It would be appreciated if you could give your readers the correct URL to the new GeoIP.dat.gz! ;-)

  2. George Notaras Post authorPermalink →

    @BOK: You are right. I added the script, which shows the URLs
    @joost: Exactly

    Thanks for the feedback

  3. Oliver Schad Permalink →

    Small enhancements for the script (untested)

    ———————————-
    #! /bin/sh

    # download data rate limit
    LIMIT=”100k”

    # tmp file for storing downloads
    OUTPUT=$(mktemp)

    # delete tmp output
    function cleanup {
    rm “$OUTPUT”
    }

    function download {
    # download and uncompress with one command
    wget –limit-rate=$LIMIT “$1” -O /dev/stdout | zcat > “$OUTPUT”
    # do update atomically
    mv “$OUTPUT” “$2”
    }

    # cleanup after ctrl+c and kill
    trap cleanup SIGINT SIGTERM

    # Update GeoLite Country (GeoIP default), uncompress directly
    update http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz \
    /usr/share/GeoIP/GeoIP.dat

    # Update GeoLite City
    update http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz \
    /usr/share/GeoIP/GeoLiteCity.dat

    cleanup
    —————————————————————-