5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

memo: osm tile server: ubuntu 13.10

Last updated at Posted at 2014-04-30

かきなぐりメモ帳。

server environment

ConoHaの一番安いプラン、ubuntu 13.10環境で作成。

postgis install

for version 2.*.

CREATE EXTENSION adminpack; needs postgresql-contrib-9.1 package.

sudo apt-get install postgresql-contrib-9.1

ただ、これのせいで postgres9.3と、postgres9.1が両方インストールされてしまった感じ。調べたら、実働しているのは9.1なので、とりあえず今回は以下のパッケージもインストールした。
たぶん、postgresql-contrib-9.3をインストールすればこんなことにはならなかった。その場合、以下のバージョンも9.3に変更する必要あり。

sudo apt-get install postgresql-9.1-postgis-2.1
sudo apt-get install postgresql-9.1-postgis-2.1-scripts
sudo apt-get install postgresql-9.1-postgis-scripts

ここも参考か?
http://technobytz.com/install-postgis-postgresql-9-3-ubuntu.html

Database creation & enable extension on the Database

sudo su - postgres
createdb hdm
psql -d hdm
create extension postgis;
create extension hstore;
\q

あと、createuserで、ユーザ作ってパスワード設定する。

mapnik

nightly build is highly unstable, using 2.2.* as package.

sudo add-apt-repository ppa:mapnik/v2.2.0
sudo apt-get update
sudo apt-get install libmapnik libmapnik-dev mapnik-utils python-mapnik

install git

as we always do.

apt-get install git

apache2

apt-get install apache2

mod_tile

sudo aptitude install apache2 apache2-threaded-dev apache2-mpm-prefork apache2-utils
sudo apt-get install libagg-dev
cd ~/src
git clone https://github.com/openstreetmap/mod_tile.git
cd mod_tile
sudo apt-get install dh-autoreconf
./autogen.sh
./configure
make
sudo make install
sudo make install-mod_tile # Only needed with recent mod_tile version

mod_tileをmods-availableに格納して、mods_enabledからリンクを張ってあげる。
a2enmodコマンドでも可。

sudo vi /etc/apache2/mods-available/mod_tile.load
sudo ln -s /etc/apache2/mods-available/mod_tile.load /etc/apache2/mods-enabled/mod_tile.load

renderdのsocket管理用ディレクトリを確保。/etc/renderd.confの中の設定、および /etc/apache2/site-availableで設定した値にあわせること。

sudo mkdir /var/run/renderd
sudo chown www-data /var/run/renderd

あと、サンプル提示されているsite-availableのコンテナ記述は、ModTileRenderdSocketNameがいろんなところのサンプルと異なっているので、他とあわせること。

LoadTileConfigFile /etc/renderd.conf
# ModTileRenderdSocketName /tmp/osm-renderd この行。
ModTileRenderdSocketName /var/run/renderd/renderd.sock
# Timeout before giving up for a tile to be rendered
ModTileRequestTimeout 3
# Timeout before giving up for a tile to be rendered that is otherwise missing
ModTileMissingRequestTimeout 30

/etc/init.d/renderdを設置する場合はこちらの手順参照。

sudo cp  ~/src/mod_tile/debian/renderd.init /etc/init.d/renderd
sudo chmod u+x /etc/init.d/renderd

Edit the /etc/init.d/renderd file as root – you’ll need to make a couple of changes to the DAEMON and DAEMON_ARGS lines so that they read:

DAEMON=/usr/local/bin/$NAME
DAEMON_ARGS="-c /usr/local/etc/renderd.conf"

いったんrootでタイル画像を作ってしまうと、daemon化した時にそのディレクトリに書き込めなくて画像の生成に失敗することがある。ので、daemon化した後はいったん作成したタイル画像を全削除することをオススメ。

osm2pgsql

sudo apt-get install osm2pgsql

要確: postgis-1.5がインストールされてしまうが大丈夫か。

osmosis

パッケージだと、0.40.1がインストールされる。

sudo apt-get install osmosis

とりあえずは大丈夫だけど、最新版をパッケージ外からインストールしたほうがいいかも。

wget http://bretth.dev.openstreetmap.org/osmosis-build/osmosis-latest.tgz
tar xvfz osmosis-latest.tgz
cd osmosis-*
chmod a+x bin/osmosis
bin/osmosis

OSM files

for test purpose, bbbike extract would be easy choice.

wget http://download.bbbike.org/osm/bbbike/Tokyo/Tokyo.osm.pbf

import data into postgis database

ユーザ名とパスワードは適度に変更すること。
GeoFabrikのJapan.-latest.pbfの場合、ファイルサイズが大きすぎてメモリのアロケート調整しないとダメぽい。あるいは slim mode?

osm2pgsql -G -U postgres -d hdm /home/nyampire/osmfile/Tokyo.osm.pbf --hstore --create

ConoHaの最安プラン(メモリ1G)だと、メモリ320MB割り当てくらいが精一杯ぽい。

osm2pgsql -W -G -U postgres -d hdm /home/nyampire/osmfile/japan-latest.osm.pbf --number-processes 2 --slim -C 320 --hstore --create 

fonts

Mapnikの設定ファイル(/etc/renderd.conf)で指定されているフォントディレクトリはシステムのフォントディレクトリ(/usr/share/fonts/truetype)を指しているので、パッケージでインストールしてしまったほうが楽な気がする。

apt-get install fonts-vlgothic

tilemill (optional)

minutely diff (optional)

もしかしたら最強ドキュメント http://switch2osm.org/loading-osm-data/

Komzpa作成のfetchコマンド https://github.com/Komzpa/furry-sansa

タイルの自動更新バッチ(mod_tile用) http://wiki.openstreetmap.org/wiki/Howto_real_time_tiles_rendering_with_mapnik_and_mod_python

mod_tile単体でもいけるぽい。state.txtをちゃんと読み込ませてあげればOK http://wiki.openstreetmap.org/wiki/Mod_tile

state.txtの生成はここがよさげ。過去のstate.txtを使っても、重複ぶんは自動的に排除してくれるようなので、少し過去のぶんから適用するのがよさそう。

とりあえず、 http://wiki.openstreetmap.org/wiki/Minutely_Mapnik の手順でいけそう。state.txtは、実際のDumpよりも過去の日付を指定していても大丈夫なので、気にせずに生成してトライすればOK。

あと、~/.pgpassに、PostGIS用のパスワードを書いておくと幸せになれる。

こんなかんじのシェルスクリプトを適当にまわして、あとはアップデートのコマンドをcronに放り込んでおけばおっけー。
これで、データベースのアップデートが可能。

# !/bin/bash
for i in {0..100}
do
  osmosis --read-replication-interval workingDirectory=$WORKDIR_OSM --simplify-change --write-xml-change - | osm2pgsql --append --number-processes 2 -G -U gis -d hdm --slim -C 320 --hstore -
done

タイルのexpireは、これをかませるらしい。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?