Notes

Automating the updating of GeoLocation database (GeoIP2 by MaxMind)

Edit on GitHub

System Administration

There are multiple ways of doing this.

  • Direct download script (with cron)
1GEOIPUPDATE_LICENSE_KEY=''
2
3#https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${GEOIPUPDATE_LICENSE_KEY}&suffix=tar.gz
4
5curl "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${GEOIPUPDATE_LICENSE_KEY}&suffix=tar.gz" -o GeoLite2-Country.tar.gz \
6  && tar -xzvf GeoLite2-Country.tar.gz \
7  && mkdir -p /var/opt/maxmind/ \
8  && mv GeoLite2-Country_*/GeoLite2-Country.mmdb /var/opt/maxmind/GeoLite2-Country.mmdb
# top of crontab
MAILTO=your@email.com

38 2 * * 0,4 /usr/local/bin/geoipupdate
# end of crontab
 1geoipupdate:
 2  container_name: geoip_update
 3  image: maxmindinc/geoipupdate
 4  restart: unless-stopped
 5  environment:
 6    GEOIPUPDATE_ACCOUNT_ID: ${GEOIPUPDATE_ACCOUNT_ID}
 7    GEOIPUPDATE_LICENSE_KEY: ${GEOIPUPDATE_LICENSE_KEY}
 8    GEOIPUPDATE_EDITION_IDS: GeoLite2-Country
 9    GEOIPUPDATE_FREQUENCY: 96 # number of hours between geoipupdate runs, 96 is four days, GeoIP2 Country is updated twice weekly on Tuesdays and Fridays
10  volumes:
11    - ./data/maxmind:/usr/local/share/GeoIP

This assumes you have a .env file in the project root that has your account ID and license key. Otherwise you can just hard code these values

# .env

# MaxMind Credentials
GEOIPUPDATE_ACCOUNT_ID=123456
GEOIPUPDATE_LICENSE_KEY=7CajsdbjkasbdkKj