echoip-server-setup/README.md

5.4 KiB

echoip-server-setup

Scripts and configuration files for quickly setting up the echo lookup server created by mpolden - https://github.com/mpolden/echoip.

The main purpose of the project in this repository was to create config files for my setup which can be quickly deployed, in the event I needed to rebuild the service.

This project provides an easy and fast way to set up EchoIP, a service that offers IP geolocation lookups, using the MaxMind GeoLite2 databases (City, ASN, and Country). The goal of this project is to streamline the deployment of EchoIP by automating the process of downloading, extracting, and organizing the required GeoLite2 data files, then running the service in a Docker container.

Features

  • Runs an EchoIP service in a Docker container to provide geolocation lookup via the GeoLite2 databases.
  • Downloads and extracts GeoLite2 databases (City, ASN, Country).
  • Configures Apache HTTP Server to proxy requests to EchoIP.

Prerequisites

Before setting up the project, ensure the following tools are installed:

Setup Instructions

1. Clone the repository:

git clone https://git.ncltech.co.uk/phil/echoip-server-setup
cd echoip-server-setup

2. Downloading GeoLite2 Databases:

To download the required databases (GeoLite2-City, GeoLite2-ASN, and GeoLite2-Country), you can run geolite2-db-update.sh script. This will:

  • Download the required GeoLite2 databases from MaxMind.
  • Extract the .tar.gz files.
  • Organize the extracted files into the appropriate folders: city, asn, and country.

Configuration

  • Open the geolite2-db-update.sh script and replace YOUR_ACCOUNT_ID:YOUR_LICENSE_KEY with your actual MaxMind account credentials.

  • Set your MaxMind account ID and license key in the AUTH variable:

AUTH="YOUR_ACCOUNT_ID:YOUR_LICENSE_KEY"
  • Change the /path/to/default/main/data/folder to the location where the project was downloaded or will be run from. The downloaded and extracted database files will be placed in the geolite2/db directory structure.

Run the script:

chmod +x geolite2-db-update.sh
./geolite2-db-update.sh

3. Docker Setup for EchoIP:

The Docker container uses the mpolden/echoip:latest image, which serves IP geolocation data based on the GeoLite2 databases. The docker-compose.yml file is provided to set up the service.

This file defines the EchoIP service and mounts the database files for the container to access. It also binds the service to port 8085. Configuration

Make sure the volumes section correctly points to the geolite2/db directory:

volumes:
  - ./geolite2/db/:/geolite2/db/:ro

Start the Docker container:

docker-compose up -d

4. Apache Setup:

To proxy requests to the EchoIP service, you'll need to configure your Apache HTTP server.

Add the following configuration to your Apache server's configuration file (httpd.conf or a dedicated virtual host file). This configures Apache to forward requests to the EchoIP service running on localhost:8085 and supports the X-Forwarded-For header.

<VirtualHost *:80>
  ServerName FULLY.QUALIFIED.DOMAIN.NAME
  RemoteIPHeader CF-Connecting-IP

  ProxyPreserveHost On
  ProxyRequests Off

  ProxyPass / http://127.0.0.1:8085/
  ProxyPassReverse / http://127.0.0.1:8085

  # Add support for X-Forwarded-For
  RequestHeader set X-Forwarded-For "%{REMOTE_ADDR}s"

  ErrorLog ${APACHE_LOG_DIR}/echoip-error.log
  CustomLog ${APACHE_LOG_DIR}/echoip-access.log combined
</VirtualHost>

Replace FULLY.QUALIFIED.DOMAIN.NAME with your server's domain name.

  • Enable the necessary Apache modules:
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod headers
sudo a2enmod rewrite
sudo a2enmod remoteip
  • Restart Apache:
sudo systemctl restart apache2

5. Accessing the Service:

After setting up Docker and Apache:

The EchoIP service will be accessible through Apache on the domain you configured. You can query geolocation data by making requests to the configured server.

For example, a request to http://FULLY.QUALIFIED.DOMAIN.NAME/?ip=8.8.8.8 will return geolocation information for the IP address 8.8.8.8.

File Structure:

.
├── apache_config.conf          # Apache virtual host configuration
├── geolite2-db-update.sh       # Bash script for downloading and extracting GeoLite2 databases
├── docker-compose.yml          # Docker Compose configuration for EchoIP service
├── log/						# Log storage for the geolite2-db-update.sh script
└── geolite2/
    └── db/
        ├── city/               # GeoLite2-City database
        ├── asn/                # GeoLite2-ASN database
        └── country/            # GeoLite2-Country database

6. Troubleshooting:

  • Ensure that your MaxMind credentials are correct in the download_geoip.sh script. Every time the geolite2-db-update.sh script is ran it will log to the log/download.log file.
  • Check the Apache logs (/var/log/apache2/echoip-error.log) for any issues related to the proxy configuration.
  • If Docker fails to start the EchoIP container, check the Docker logs with docker logs echoip.