Ubuntu 16.04 で OpenStreetMap タイルサーバを構築 – 2 –

目次

前回 さくらVPS RAM : 1GB  ディスク100GB で挑戦するも、 スペック不足で断念したので

気を取り直して、今回は さくらクラウド 上で Ubuntu 16.04 を用意しました。

RAM : 3GB  CPU : 2コア  ディスク100GB でも大丈夫でしょうか? 結果は後程。

で、今回も

元の内容はこちらから をほぼそのままやっています。

https://www.linuxbabe.com/linux-server/openstreetmap-tile-server-ubuntu-16-04

元記事の 更新日2016/07/22 By: Xiao Guoan 氏

ステップ1:

ソフトウェア アップデート

sudo apt update
sudo apt update

ステップ2:

PostgreSQL データベース サーバーと PostGIS

地図データの格納にPostgreSQL を使用します。

PostGIS は PostgreSQL に地理空間情報を拡張します。

それらをインストールするコマンドを次のように実行します。

sudo apt install postgresql postgresql-contrib postgis postgresql-9.5-postgis-2.2

postgres という名前のユーザーは、インストール プロセス中に作成されます。
これらは Peer 認証を使用します。
postgres ユーザー に切り替えます。

sudo -u postgres -i

osm という PostgreSQL データベースユーザーを作成します。

createuser osm

osm が所有者 で 文字コードエンコーディング がUTF8 のgis という名前のデータベースを作成します。

createdb -E UTF8 -O osm gis

(今回は成功しました・・)

hstore と postgis エクステンションを作成します。

psql -c "CREATE EXTENSION hstore;" -d gis
psql -c "CREATE EXTENSION postgis;" -d gis

postgres ユーザを抜けます

exit

タイルサービスを実行する osm ユーザーを作成します。

sudo adduser osm

ステップ3:

マップスタイルシートとマップデータのダウンロード

osm ユーザーに切り替えます。

su - osm

osm ユーザーの ホームディレクトリにCartoCSS マップ スタイスシートをダウンロードします。

wget https://github.com/gravitystorm/openstreetmap-carto/archive/v2.41.0.tar.gz

展開します

tar xvf v2.41.0.tar.gz

続いて、マップデータ を osm ユーザーの ホームディレクトリにダウンロードします。

マップデータ planet (32G)

wget -c http://planet.openstreetmap.org/pbf/planet-latest.osm.pbf

必要な国・地域のでマップを取得するためには http://download.geofabrik.de または

BBBuke.org などから ダウンロードできます。

例として、日本のマップデータをダウンロードします (1G)

wget -c http://download.geofabrik.de/asia/japan-latest.osm.pbf

osm ユーザーから抜けます

exit

ステップ4:

PostgreSQL に マップデータをインポート

PostgreSQL データベースで postGIS を使えるように OpenStreetMap データをコンバートする osm2pgsql を インストールします。

sudo apt install osm2pgsql

osm ユーザーに切り替えます

su - osm

gis データーベースに マップスタイルシートと マップデータを読み込みます。

japan-latest.osm.pbf の部分はあなたの環境に読み替えてください。

前回の教訓を踏まえて
-C はキャッシュサイズです。 これを 3000 に設定
以下は意味があるのか不明ですが

http://home.a00.itscom.net/hatada/gis/doc/osm2pgsql01.html
こちらに記載の
–number-processes 2 -I –unlogged のオプションを併せて 試してみます。

osm2pgsql --slim -d gis -C 3000  --number-processes 3 -I --unlogged --hstore -S openstreetmap-carto-2.41.0/openstreetmap-carto.style japan-latest.osm.pbf

osm2pgsql コマンドを実行するときのオプション指定には

-d で データベースを指定します

Node stats: total(120211558), max(4360452535) in 630s
Way stats: total(12580338), max(438309849) in 695s
Relation stats: total(35064), max(6520105) in 654s
Committing transaction for planet_osm_point
Committing transaction for planet_osm_line
Committing transaction for planet_osm_polygon
Committing transaction for planet_osm_roads
Setting up table: planet_osm_nodes
Setting up table: planet_osm_ways
Setting up table: planet_osm_rels
Using built-in tag processing pipeline
Setting up table: planet_osm_nodes
Setting up table: planet_osm_ways
Setting up table: planet_osm_rels
Using built-in tag processing pipeline
Setting up table: planet_osm_nodes
Setting up table: planet_osm_ways
Setting up table: planet_osm_rels
Using built-in tag processing pipeline

Going over pending ways...
        5297581 ways are pending

Using 3 helper-processes

ここまで開始から 20分 しばらくこのまま

Committing transaction for planet_osm_roads
WARNING:  there is no transaction in progress
Committing transaction for planet_osm_point
WARNING:  there is no transaction in progress
Committing transaction for planet_osm_line
WARNING:  there is no transaction in progress
Committing transaction for planet_osm_polygon
WARNING:  there is no transaction in progress
Committing transaction for planet_osm_roads
WARNING:  there is no transaction in progress
Sorting data and creating indexes for planet_osm_point
Stopping table: planet_osm_nodes
Stopping table: planet_osm_ways
Building index on table: planet_osm_ways
Stopping table: planet_osm_rels
Building index on table: planet_osm_rels
Stopped table: planet_osm_nodes in 0s
Stopped table: planet_osm_rels in 7s
Copying planet_osm_point to cluster by geometry finished
Creating geometry index on  planet_osm_point
Creating osm_id index on  planet_osm_point
Creating indexes on  planet_osm_point finished
All indexes on  planet_osm_point created  in 73s
Completed planet_osm_point
Sorting data and creating indexes for planet_osm_line

ここまで 開始から 40分

Copying planet_osm_line to cluster by geometry finished
Creating geometry index on planet_osm_line
Creating osm_id index on planet_osm_line
Creating indexes on planet_osm_line finished
All indexes on planet_osm_line created in 1298s
Completed planet_osm_line
Sorting data and creating indexes for planet_osm_polygon

ここまで開始から 60分

Copying planet_osm_polygon to cluster by geometry finished
Creating geometry index on planet_osm_polygon
Creating osm_id index on planet_osm_polygon
Creating indexes on planet_osm_polygon finished
All indexes on planet_osm_polygon created in 784s
Completed planet_osm_polygon
Sorting data and creating indexes for planet_osm_roads
Copying planet_osm_roads to cluster by geometry finished
Creating geometry index on planet_osm_roads
Creating osm_id index on planet_osm_roads
Creating indexes on planet_osm_roads finished
All indexes on planet_osm_roads created in 92s
Completed planet_osm_roads

ここまで開始から 75分

Stopped table: planet_osm_ways in 3392s
node cache: stored: 120211558(100.00%), 
storage efficiency: 58.98% 
(dense blocks: 76668, sparse nodes: 62652878), 
hit rate: 100.00%

Osm2pgsql took 6472s overall

インポートが完了したので  osm ユーザーから 抜けます。

exit

ちなみに、前回の環境でも、スワップファイルを追加作成すれば、作業完了していたかも。

やり方はこちら
続きはまた後で

タグ: , ,