MaxMind
The MaxMind module provides geolocation lookups using MaxMind's GeoIP2 databases.
Install the MaxMind module
Log into your account at the MaxMind website and download the GeoIP databases. Copy them to your HAProxy Enterprise server (e.g. /etc/hapee-1.7/GeoIP2-City.mmdb, /etc/hapee-1.7/GeoIP2-ISP.mmdb).
-
Install the MaxMind module according to your platform:
$ # On Debian/Ubuntu $ sudo apt-get install hapee-1.7r1-lb-maxmind
$ # On CentOS/RedHat/Oracle $ sudo yum install hapee-1.7r1-lb-maxmind
-
In the
global
section of your configuration, add the following lines:global module-load hapee-lb-maxmind.so maxmind-load mlock_max 512000000 CITY
/etc/hapee-1.7/GeoIP2-City.mmdbISP/etc/hapee-1.7/GeoIP2-ISP.mmdbmaxmind-cache-size 200000 Reload the HAProxy Enterprise configuration to apply the changes.
Global directives
The module adds the following global
directives:
Directive | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|
| Required. Loads a MaxMind database.
| ||||||||
| The size of the LRU cache used for lookups, defaults to 0. Setting to 0 disables cache. | ||||||||
| Enables logging of unsuccessful IP address lookups, as well as logging of attempts to read unavailable fields from records of successfully looked up IP addresses. |
Converter
maxmind-lookup
Use the converter maxmind-lookup
to perform a lookup in the database that returns the values of the specified property. Properties in the MaxMind database are stored hierarchically. For example, you can find the name of a city in English at city > names > en.
Syntax
maxmind-lookup(<db_type>,<prop-level1>[,<prop-level2>*])
Set HTTP request headers that contain CITY and ISP properties based on client's source IP address
frontend www
bind :80
mode http
http-request add-header X-CityName %[src,maxmind-lookup("CITY","city","names","en")]
http-request add-header X-ISOCode %[src,maxmind-lookup("CITY","country","iso_code")]
http-request add-header X-ASN %[src,maxmind-lookup("ISP","autonomous_system_number")]
http-request add-header X-ASNOrg %[src,maxmind-lookup("ISP","autonomous_system_organization")]
Discover properties
Use the mmdblookup utility to look up an IP address in a MaxMind database file and learn the structure of the data.
-
Install the mmdblookup utility according to your platform:
$ # On Debian/Ubuntu $ sudo apt install mmdb-bin $ # On CentOS/RedHat $ dnf --enablerepo=PowerTools install libmaxminddb-devel
-
Look up an IP address. For this exercise, the IP value can be any routable address:
$ mmdblookup --file /etc/hapee-1.7/GeoLite2-City.mmdb --ip 40.121.152.233
This returns a JSON document, as shown below. Use the document's structure to find a property to use with the
maxmind-lookup
converter. For example, to have HAProxy Enterprise look up the English language city name for a client's IP address, use the keys city, names, and en as represented in the JSON returned frommmdblookup
:{ "city": { "geoname_id": 4792307 <uint32> "names": { "en": "Washington" <utf8_string> } } // data continues... }
Update the database during runtime
Use the MaxMind Update feature to keep the contents of the geolocation database current. This allows you to keep multiple instances of HAProxy Enterprise synced with the latest data.
Install a Web server of your choice and host the database file(s) at a URL where HAProxy Enterprise can access. For example, host the files at http://192.168.122.1/GeoIP2-City.mmdb and http://192.168.122.1/GeoIP2-ISP.mmdb.
-
Add the following lines to the
global
section of your configuration file, where the URL hosts an updated version of the file:global # ... other global settings maxmind-update url CITY
http://192.168.122.1/GeoIP2-City.mmdburlISP http://192.168.122.1/GeoIP2-ISP.mmdb delay 24h checksum hash log
With this configuration, HAProxy Enterprise downloads the database every 24 hours and displays a message in the logs when it succeeds or if it encountered errors during the update.
maxmind-update
The maxmind-update
directive enables updating the database over HTTP from a specified URL. You can specify multiple database types and their respective URLs. If there are multiple database types specified, they will download sequentially with a delay between each download. Updating a database with a newer version invalidates any cached lookups (if caching is used), unless you enable checksum
and the new and old database contents are identical.
The directive supports the following syntax:
maxmind-update url <db_type> <db_url>
[url <db_type> <db_url>]*
[delay <number>]
[timeout <number>]
[retries <number>]
[checksum]
[log]
[dontlog-normal]
Parameters | Description |
---|---|
| Required. Can be any of the following: - CITY - COUNTRY - ISP - ANONYMOUS You must have already used the <db_type> with the |
| Required. URL to connect to and download a new version of the database of type |
| Specifies the delay between each attempt to download a new database version. |
| Specifies the HTTP connect timeout for attempts to download a new database version. The default value is in milliseconds, but you can specify any other unit if you add it as a suffix to the number (default: 5 milliseconds). |
| Specifies the number of retries to download a new database version. If unspecified, the global retries value applies (default: 3). |
| If present, it specifies to use a SHA1 checksum to verify that a newly downloaded database is identical to the current one. If they are identical, then a live-reload of the database does not take place, thereby preserving cache contents (if using caching). |
| Specifies whether to log operation errors. |
| Deactivates logging for successful updates. |
Runtime API
The following Runtime API commands are available:
| Disables the LRU cache. |
| Enables the LRU cache. |
| Invalidates the LRU cache. |
| Disables the database lookup engine. |
| Enables the database lookup engine. |
| Dumps the configuration set by the |
| Shows the module status. |
| Initiates the currently scheduled database type to attempt downloading immediately. |
Next up
Health Checking