Back to articles
DevOps & Systems

Building an Optimized Geospatial Tile Server with OpenStreetMap and PostGIS on VPS

This technical guide details how to build a high-performance geospatial tile server using OpenStreetMap and PostGIS on a VPS. It covers database configuration, data ingestion, tile...

DPTCloud Engineering4 min read
Building an Optimized Geospatial Tile Server with OpenStreetMap and PostGIS on VPS

Image credit: jhenning · Pixabay Content License

This technical guide details how to build a high-performance geospatial tile server using OpenStreetMap and PostGIS on a VPS. It covers database configuration, data ingestion, tile server setup, performance optimization, and operational verification, enabling interactive mapping for web and mobile applications.

Introduction

Building a high-performance geospatial tile server allows for fast and stable interactive map services in web or mobile applications. Combining OpenStreetMap (OSM) with PostGIS on a NVMe Cloud VPS provides a cost-effective, easily deployable, and scalable solution. This guide explains how to construct and optimize a geospatial tile server on a VPS using open-source technologies, including database setup, tile server configuration, and performance tuning.

Requirements and Preparation

To implement this solution, you need:

  • A VPS with at least 4GB RAM and 80GB SSD (recommended: Cloud VPS NVMe)
  • Operating System: Ubuntu 22.04 LTS
  • Software: PostgreSQL with PostGIS, osm2pgsql, Mapnik, Node.js, Nginx, and tileserver-gl or MapProxy

Implementation Steps

1. Install and Configure PostgreSQL with PostGIS

Run the following commands on the VPS to install PostgreSQL and the PostGIS extension:

sudo apt update
sudo apt install -y postgresql postgresql-contrib postgis
sudo -u postgres psql -c "CREATE USER osmuser WITH PASSWORD 'osmpassword';"
sudo -u postgres psql -c "CREATE DATABASE osm WITH OWNER osmuser;"
sudo -u postgres psql -c "CREATE EXTENSION IF NOT EXISTS postgis;"

2. Load OpenStreetMap Data

Download OSM data from sources like Geofabrik (e.g., Vietnam). Then, use osm2pgsql to load the data into the database:

osm2pgsql -d osm -U osmuser -W --slim --hstore --number-processes 4 --style /usr/share/osm2pgsql/default.style /path/to/vietnam-latest.osm.pbf

3. Configure the Tile Server

Choose a suitable tile server. Below is an example using TileServer GL:

docker run -d --name tileserver-gl -p 8080:80 -v /path/to/osm/data:/data maptiler/tileserver-gl

Alternatively, use MapProxy with the following configuration:

layers:
  - name: osm
    title: OpenStreetMap
    sources: [osm]
sources:
  osm:
    type: wms
    url: http://localhost:8080/wms

4. Optimize Performance

  • Specify the data region to process to reduce memory usage.
  • Use Nginx as a reverse proxy and cache tiles.
  • Set PostgreSQL cache parameters: shared_buffers = 1GB, effective_cache_size = 3GB in postgresql.conf.
  • Run osm2pgsql with the --number-processes parameter set to the number of CPU cores.

Testing and Operation

Access http://your-vps-ip:8080 to check the tile server. Use tools like OpenStreetMap or MapTiler to view the map.

Run the following command to verify the database connection:

sudo -u postgres psql -U osmuser -d osm -c "SELECT COUNT(*) FROM planet_osm_point;"

Alternative Solutions and Resources

For scaling, consider using a distributed storage architecture with JuiceFS and Ceph. For high-performance requirements, refer to the guide on optimizing a time series data warehouse.

For simpler systems, see the guide on optimizing PocketBase to understand performance management on VPS.

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478