<!本贴参照互联网上网友的帖子,加入自己实际操作过程中遇到问题的解决方法;仅供学习交流用途。>
Step 1: 更新Ubuntu的软件库
# sudo apt update
# sudo apt upgrade
Step 2: 使用PostGIS安装PostgreSQL数据库服务器
We will usePostgreSQL to store map data. PostGIS is a geospatial extenstion to PostgreSQL.Run the following commands to install them.
# sudo apt install postgresql postgresql-contrib postgis postgresql-9.5-postgis-2.2
A usernamed postgres will be created during the installation process. Thisallows the use of peer authentication. Let’s switch tothe postgres user:
# sudo -u postgres -i
Create a PostgreSQL database user osm
# createuser osm
Create adatabase named gis andat the same time make osm as the owner of the database. -EUTF8 specifies the character encoding scheme to be used in the database isUTF8.
# createdb -E UTF8 -O osm gis
Create hstore and postgis extension.
# psql -c "CREATE EXTENSION hstore;" -d gis
# psql -c "CREATE EXTENSION postgis;" -d gis
Exit from the postgres user.
# exit
Create osmuseruser on your operating system so the tile server can run as osmuser user.
# sudo adduser osmuser
Step 3: 下载地图样式表和地图数据
First switch to osmuser user
# su - osmuser
Download the latest CartoCSS mapstylesheets to the osmuser user’s homedirectory.
# wget https://github.com/gravitystorm/openstreetmap-carto/archive/v2.41.0.tar.gz
Extract it.
# tar xvf v2.41.0.tar.gz
Next, download map data to the osmuser user’s home directory. Use the belowcommand to download the map data of the whole planet (32G).
# wget -c http://planet.openstreetmap.org/pbf/planet-latest.osm.pbf
【If you want a map of individual country orstate, go to http://download.geofabrik.de.Also, BBBike.org provides extractsof more than 200 cities and regions world-wide in different formats.】
For example, download the map data of GreatBritain (847M).
# wget -c http://download.geofabrik.de/europe/great-britain-latest.osm.pbf
Now exit from the osmuser user.
#exit
Step 4: 将地图数据导入PostgreSQL
To import mapdata, we need to install osm2pgsql which converts OpenStreetMap datato postGIS-enabled PostgreSQL databases.
# sudo apt install osm2pgsql
Switch to osmuseruser again.
#su - osm