
Switch2OSMに記載された手順にもとづき、OpenStreetMapのタイルサーバを構築します。
なお、Switch2OSMではUbuntu 18.04 LTS (Bionic Beaver)を想定した手順となっていますが、今回はUbuntu 20.04 LTS (Focal Fossa)上で構築を行うため、Switch2OSMの手順から一部変更している部分があります。
目次
リポジトリ追加、パッケージリスト更新
$ sudo add-apt-repository multiverse 'multiverse'のコンポーネントはすべてのソースで有効になっています。
$ sudo apt update 取得:1 http://security.ubuntu.com/ubuntu focal-security InRelease [101 kB] ヒット:2 http://jp.archive.ubuntu.com/ubuntu focal InRelease 取得:3 http://jp.archive.ubuntu.com/ubuntu focal-updates InRelease [97.0 kB] ヒット:4 http://jp.archive.ubuntu.com/ubuntu focal-backports InRelease 取得:5 http://jp.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [14.6 kB] 213 kB を 9秒 で取得しました (24.4 kB/s) パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 パッケージはすべて最新です。
パッケージインストール
Switch2OSMの手順どおりコマンドを実行するには支障があるため、以降に記載の変更を行う必要があります。変更後の手順は以下のとおりです。
最終的な手順
bionicバージョンのmultiverseリポジトリとuniverseリポジトリを追加します。
$ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic multiverse" $ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic-updates multiverse" $ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic-backports multiverse" $ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic-security multiverse" $ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic universe" $ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic-updates universe" $ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic-backports universe" $ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic-security universe"
パッケージをインストールします。
$ sudo apt install libboost-all-dev git-core tar unzip wget bzip2 build-essential autoconf libtool libxml2-dev libgeos-dev libgeos++-dev libpq-dev libbz2-dev libproj-dev munin-node munin libprotobuf-c-dev protobuf-c-compiler libfreetype6-dev libtiff5-dev libicu-dev libgdal-dev libcairo-dev libcairomm-1.0-dev apache2 apache2-dev libagg-dev liblua5.2-dev ttf-unifont lua5.1 liblua5.1-dev libgeotiff-epsg
Switch2OSMの手順からの変更点
- bionicバージョンのmultiverseリポジトリとuniverseリポジトリを
add-apt-repository
するのを追加。 apt install
するパッケージを変更。- libprotobuf-c0-dev → libprotobuf-c-dev
変更点の経緯
エラーの原因は、Switch2OSMではUbuntu 18.04 LTS (Bionic Beaver)想定で書かれていますが、今回は20.04 LTS (Focal Fossa)を使用していることによります。20.04は2020/4/23にリリースされたばかりなので、ここで問題になっているパッケージがまだリポジトリのfocalに登録されていないのかもしれません。時間が経てば上記の変更点は不要になる可能性もあります。
エラー対処(libprotobuf-c0-dev, libgeotiff-epsg)
$ sudo apt install libboost-all-dev git-core tar unzip wget bzip2 build-essential autoconf libtool libxml2-dev libgeos-dev libgeos++-dev libpq-dev libbz2-dev libproj-dev munin-node munin libprotobuf-c0-dev protobuf-c-compiler libfreetype6-dev libtiff5-dev libicu-dev libgdal-dev libcairo-dev libcairomm-1.0-dev apache2 apache2-dev libagg-dev liblua5.2-dev ttf-unifont lua5.1 liblua5.1-dev libgeotiff-epsg [sudo] ubu のパスワード: パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 注意、'git-core' の代わりに 'git' を選択します 注意、'libcairo-dev' の代わりに 'libcairo2-dev' を選択します 注意、'liblua5.1-dev' の代わりに 'liblua5.1-0-dev' を選択します パッケージ libgeotiff-epsg は使用できませんが、別のパッケージから参照されます。 これは、パッケージが欠落しているか、廃止されたか、または別のソース からのみ利用可能であることを意味します。 E: パッケージ libprotobuf-c0-dev が見つかりません E: パッケージ 'libgeotiff-epsg' にはインストール候補がありません
上記エラーになったパッケージ名をapt search
すると、似た名前のものはありますがピッタリのものは無いようです。そこで、以下の対処をします。
libprotobuf-c0-dev
仮想パッケージ: libprotobuf-c0-dev によると、libprotobuf-c0-dev は仮想パッケージであり、libprotobuf-c-dev にて提供されるとのことなので、apt install
に渡す引数をlibprotobuf-c-dev
に変更します。
libgeotiff-epsg
» Ubuntu » パッケージ » パッケージ検索結果 によると、libgeotiff-epsg は現時点ではmultiverse以下のリポジトリにしか存在していないようです。
- xenial (16.04LTS) (science): GeoTIFF library — EPSG Geodetic Parameter Dataset [multiverse]
1.4.1-2: all - bionic (18.04LTS) (science): GeoTIFF library — EPSG Geodetic Parameter Dataset [multiverse]
1.4.2-1: all - disco (19.04) (science): GeoTIFF library — EPSG Geodetic Parameter Dataset [multiverse]
1.4.3-1: all
今回使用しているUbuntuのバージョンは Focal Fossa (20.04 LTS) であり、aptのリポジトリリスト/etc/apt/sources.list
にはfocalしか登録されていないため、インストールに失敗したようです。
そこで、リポジトリリストにbionicのmultiverseを追加します。focalにならって -updates, -backports, -security も追加しています。
$ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic multiverse" $ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic-updates multiverse" $ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic-backports multiverse" $ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic-security multiverse"
余談
ちなみに、本当は上記の中で最新のdiscoを登録しようと思ったのですが、以下のようにエラーになったのでbionicにしました。http://jp.archive.ubuntu.com/ubuntu/dists/ を見るに、discoは既にディレクトリが無いようです。
$ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ disco multiverse" 取得:1 http://security.ubuntu.com/ubuntu focal-security InRelease [101 kB] ヒット:2 http://jp.archive.ubuntu.com/ubuntu focal InRelease 取得:3 http://jp.archive.ubuntu.com/ubuntu focal-updates InRelease [97.0 kB] ヒット:4 http://jp.archive.ubuntu.com/ubuntu focal-backports InRelease 無視:5 http://jp.archive.ubuntu.com/ubuntu disco InRelease エラー:6 http://jp.archive.ubuntu.com/ubuntu disco Release 404 Not Found [IP: 160.26.2.187 80] パッケージリストを読み込んでいます... 完了 E: リポジトリ http://jp.archive.ubuntu.com/ubuntu disco Release には Release ファイルがありません。 N: このようなリポジトリから更新を安全に行うことができないので、デフォルトでは更新が無効になっています。 N: リポジトリの作成とユーザ設定の詳細は、apt-secure(8) man ページを参照してください。
エラー対処(libgeotiff-epsg, libgeotiff2)
$ sudo apt install libboost-all-dev git-core tar unzip wget bzip2 build-essential autoconf libtool libxml2-dev libgeos-dev libgeos++-dev libpq-dev libbz2-dev libproj-dev munin-node munin libprotobuf-c-dev protobuf-c-compiler libfreetype6-dev libtiff5-dev libicu-dev libgdal-dev libcairo-dev libcairomm-1.0-dev apache2 apache2-dev libagg-dev liblua5.2-dev ttf-unifont lua5.1 liblua5.1-dev libgeotiff-epsg パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 注意、'git-core' の代わりに 'git' を選択します 注意、'libcairo-dev' の代わりに 'libcairo2-dev' を選択します 注意、'liblua5.1-dev' の代わりに 'liblua5.1-0-dev' を選択します bzip2 はすでに最新バージョン (1.0.8-2) です。 bzip2 は手動でインストールしたと設定されました。 tar はすでに最新バージョン (1.30+dfsg-7) です。 tar は手動でインストールしたと設定されました。 unzip はすでに最新バージョン (6.0-25ubuntu1) です。 unzip は手動でインストールしたと設定されました。 wget はすでに最新バージョン (1.20.3-1ubuntu1) です。 wget は手動でインストールしたと設定されました。 インストールすることができないパッケージがありました。おそらく、あり得 ない状況を要求したか、(不安定版ディストリビューションを使用しているの であれば) 必要なパッケージがまだ作成されていなかったり Incoming から移 動されていないことが考えられます。 以下の情報がこの問題を解決するために役立つかもしれません: 以下のパッケージには満たせない依存関係があります: libgeotiff-epsg : 依存: libgeotiff2 しかし、インストールすることができません E: 問題を解決することができません。壊れた変更禁止パッケージがあります。
libgeotiff2が原因のようなので、これのインストールを試みます。
$ sudo apt install libgeotiff2 パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 パッケージ libgeotiff2 は使用できませんが、別のパッケージから参照されます。 これは、パッケージが欠落しているか、廃止されたか、または別のソース からのみ利用可能であることを意味します。 E: パッケージ 'libgeotiff2' にはインストール候補がありません
» Ubuntu » パッケージ » パッケージ検索結果 によると、libgeotiff2は以下のリポジトリにあるようです。
- xenial (16.04LTS) (libs): GeoTIFF (geografic enabled TIFF) library — run-time files [universe]
1.4.1-2: amd64 arm64 armhf i386 powerpc ppc64el s390x - bionic (18.04LTS) (libs): GeoTIFF (geografic enabled TIFF) library — run-time files [universe]
1.4.2-2build1: amd64 arm64 armhf i386 ppc64el s390x - disco (19.04) (libs): GeoTIFF (geografic enabled TIFF) library — run-time files [universe]
1.4.3-1: amd64 arm64 armhf i386 ppc64el s390x - eoan (19.10) (libs): GeoTIFF (geografic enabled TIFF) library — run-time files [universe]
1.4.3-1: amd64 arm64 armhf i386 ppc64el s390x
無難にbionicのuniverseをリポジトリリストに追加します。
$ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic universe" $ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic-updates universe" $ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic-backports universe" $ sudo add-apt-repository "deb http://jp.archive.ubuntu.com/ubuntu/ bionic-security universe"
libgeotiff2のインストールを再度試みます。今度は成功しました。
$ sudo apt install libgeotiff2 パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 以下の追加パッケージがインストールされます: libproj12 proj-data 提案パッケージ: geotiff-bin gdal-bin libgeotiff-epsg proj-bin 以下のパッケージが新たにインストールされます: libgeotiff2 libproj12 proj-data アップグレード: 0 個、新規インストール: 3 個、削除: 0 個、保留: 1 個。 7,865 kB のアーカイブを取得する必要があります。 この操作後に追加で 24.9 MB のディスク容量が消費されます。 続行しますか? [Y/n] Y 取得:1 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 proj-data all 6.3.1-1 [7,647 kB] 取得:2 http://jp.archive.ubuntu.com/ubuntu bionic/universe amd64 libproj12 amd64 4.9.3-2 [159 kB] 取得:3 http://jp.archive.ubuntu.com/ubuntu bionic/universe amd64 libgeotiff2 amd64 1.4.2-2build1 [58.5 kB] 7,865 kB を 15秒 で取得しました (529 kB/s) 以前に未選択のパッケージ proj-data を選択しています。 (データベースを読み込んでいます ... 現在 186353 個のファイルとディレクトリがインストールされています。) .../proj-data_6.3.1-1_all.deb を展開する準備をしています ... proj-data (6.3.1-1) を展開しています... 以前に未選択のパッケージ libproj12:amd64 を選択しています。 .../libproj12_4.9.3-2_amd64.deb を展開する準備をしています ... libproj12:amd64 (4.9.3-2) を展開しています... 以前に未選択のパッケージ libgeotiff2:amd64 を選択しています。 .../libgeotiff2_1.4.2-2build1_amd64.deb を展開する準備をしています ... libgeotiff2:amd64 (1.4.2-2build1) を展開しています... proj-data (6.3.1-1) を設定しています ... libproj12:amd64 (4.9.3-2) を設定しています ... libgeotiff2:amd64 (1.4.2-2build1) を設定しています ... libc-bin (2.31-0ubuntu9) のトリガを処理しています ...
postgresql / postgis インストール
最終的な手順
Switch2OSMの手順どおりコマンドを実行するには支障があるため、以降に記載の変更を行う必要があります。変更後の手順は以下のとおりです。
$ sudo apt-get install postgresql postgresql-contrib postgis postgresql-12-postgis-3 postgresql-12-postgis-3-scripts パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 以下の追加パッケージがインストールされます: libgmpxx4ldbl libllvm10 libsfcgal1 postgis-doc postgresql-12 postgresql-client-12 postgresql-client-common postgresql-common sysstat 提案パッケージ: postgis-gui postgresql-doc postgresql-doc-12 libjson-perl isag 以下のパッケージが新たにインストールされます: libgmpxx4ldbl libllvm10 libsfcgal1 postgis postgis-doc postgresql postgresql-12 postgresql-12-postgis-3 postgresql-12-postgis-3-scripts postgresql-client-12 postgresql-client-common postgresql-common postgresql-contrib sysstat アップグレード: 0 個、新規インストール: 14 個、削除: 0 個、保留: 1 個。 39.6 MB のアーカイブを取得する必要があります。 この操作後に追加で 178 MB のディスク容量が消費されます。 続行しますか? [Y/n] Y 取得:1 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 libgmpxx4ldbl amd64 2:6.2.0+dfsg-4 [9,128 B] 取得:2 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 libllvm10 amd64 1:10.0.0-4ubuntu1 [15.3 MB] 取得:3 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 libsfcgal1 amd64 1.3.7-4ubuntu3 [1,926 kB] 取得:4 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 postgis amd64 3.0.0+dfsg-6ubuntu4 [305 kB] 取得:5 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 postgis-doc all 3.0.0+dfsg-6ubuntu4 [2,630 kB] 取得:6 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 postgresql-client-common all 214 [28.2 kB] 取得:7 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 postgresql-client-12 amd64 12.2-4 [1,042 kB] 取得:8 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 postgresql-common all 214 [169 kB] 取得:9 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 postgresql-12 amd64 12.2-4 [13.4 MB] 取得:10 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 postgresql all 12+214 [4,004 B] 取得:11 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 postgresql-12-postgis-3-scripts all 3.0.0+dfsg-6ubuntu4 [1,075 kB] 取得:12 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 postgresql-12-postgis-3 amd64 3.0.0+dfsg-6ubuntu4 [3,194 kB] 取得:13 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 postgresql-contrib all 12+214 [4,004 B] 取得:14 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 sysstat amd64 12.2.0-2 [453 kB] 39.6 MB を 1分 15秒 で取得しました (530 kB/s) パッケージを事前設定しています ... 以前に未選択のパッケージ libgmpxx4ldbl:amd64 を選択しています。 (データベースを読み込んでいます ... 現在 224953 個のファイルとディレクトリがインストールされています。) .../00-libgmpxx4ldbl_2%3a6.2.0+dfsg-4_amd64.deb を展開する準備をしています ... libgmpxx4ldbl:amd64 (2:6.2.0+dfsg-4) を展開しています... 以前に未選択のパッケージ libllvm10:amd64 を選択しています。 .../01-libllvm10_1%3a10.0.0-4ubuntu1_amd64.deb を展開する準備をしています ... libllvm10:amd64 (1:10.0.0-4ubuntu1) を展開しています... 以前に未選択のパッケージ libsfcgal1 を選択しています。 .../02-libsfcgal1_1.3.7-4ubuntu3_amd64.deb を展開する準備をしています ... libsfcgal1 (1.3.7-4ubuntu3) を展開しています... 以前に未選択のパッケージ postgis を選択しています。 .../03-postgis_3.0.0+dfsg-6ubuntu4_amd64.deb を展開する準備をしています ... postgis (3.0.0+dfsg-6ubuntu4) を展開しています... 以前に未選択のパッケージ postgis-doc を選択しています。 .../04-postgis-doc_3.0.0+dfsg-6ubuntu4_all.deb を展開する準備をしています ... postgis-doc (3.0.0+dfsg-6ubuntu4) を展開しています... 以前に未選択のパッケージ postgresql-client-common を選択しています。 .../05-postgresql-client-common_214_all.deb を展開する準備をしています ... postgresql-client-common (214) を展開しています... 以前に未選択のパッケージ postgresql-client-12 を選択しています。 .../06-postgresql-client-12_12.2-4_amd64.deb を展開する準備をしています ... postgresql-client-12 (12.2-4) を展開しています... 以前に未選択のパッケージ postgresql-common を選択しています。 .../07-postgresql-common_214_all.deb を展開する準備をしています ... 'postgresql-common による /usr/bin/pg_config から /usr/bin/pg_config.libpq-dev への退避 (divert)' を追加しています postgresql-common (214) を展開しています... 以前に未選択のパッケージ postgresql-12 を選択しています。 .../08-postgresql-12_12.2-4_amd64.deb を展開する準備をしています ... postgresql-12 (12.2-4) を展開しています... 以前に未選択のパッケージ postgresql を選択しています。 .../09-postgresql_12+214_all.deb を展開する準備をしています ... postgresql (12+214) を展開しています... 以前に未選択のパッケージ postgresql-12-postgis-3-scripts を選択しています。 .../10-postgresql-12-postgis-3-scripts_3.0.0+dfsg-6ubuntu4_all.deb を展開する準備をしています ... postgresql-12-postgis-3-scripts (3.0.0+dfsg-6ubuntu4) を展開しています... 以前に未選択のパッケージ postgresql-12-postgis-3 を選択しています。 .../11-postgresql-12-postgis-3_3.0.0+dfsg-6ubuntu4_amd64.deb を展開する準備をしています ... postgresql-12-postgis-3 (3.0.0+dfsg-6ubuntu4) を展開しています... 以前に未選択のパッケージ postgresql-contrib を選択しています。 .../12-postgresql-contrib_12+214_all.deb を展開する準備をしています ... postgresql-contrib (12+214) を展開しています... 以前に未選択のパッケージ sysstat を選択しています。 .../13-sysstat_12.2.0-2_amd64.deb を展開する準備をしています ... sysstat (12.2.0-2) を展開しています... postgresql-12-postgis-3-scripts (3.0.0+dfsg-6ubuntu4) を設定しています ... update-alternatives: /usr/share/postgresql/12/extension/postgis.control (postgresql-12-postgis.control) を提供するために自動モードで /usr/share/postgresql/12/extension/postgis-3.control を使います postgresql-client-common (214) を設定しています ... postgis (3.0.0+dfsg-6ubuntu4) を設定しています ... libllvm10:amd64 (1:10.0.0-4ubuntu1) を設定しています ... postgis-doc (3.0.0+dfsg-6ubuntu4) を設定しています ... postgresql-client-12 (12.2-4) を設定しています ... update-alternatives: /usr/share/man/man1/psql.1.gz (psql.1.gz) を提供するために自動モードで /usr/share/postgresql/12/man/man1/psql.1.gz を使います libgmpxx4ldbl:amd64 (2:6.2.0+dfsg-4) を設定しています ... postgresql-common (214) を設定しています ... ユーザ postgres をグループ ssl-cert に追加 Creating config file /etc/postgresql-common/createcluster.conf with new version Building PostgreSQL dictionaries from installed myspell/hunspell packages... en_us Removing obsolete dictionary files: Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /lib/systemd/system/postgresql.service. libsfcgal1 (1.3.7-4ubuntu3) を設定しています ... postgresql-12 (12.2-4) を設定しています ... Creating new PostgreSQL cluster 12/main ... /usr/lib/postgresql/12/bin/initdb -D /var/lib/postgresql/12/main --auth-local peer --auth-host md5 The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale "ja_JP.UTF-8". The default database encoding has accordingly been set to "UTF8". initdb: could not find suitable text search configuration for locale "ja_JP.UTF-8" The default text search configuration will be set to "simple". Data page checksums are disabled. fixing permissions on existing directory /var/lib/postgresql/12/main ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting default time zone ... Asia/Tokyo creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... ok Success. You can now start the database server using: pg_ctlcluster 12 main start Ver Cluster Port Status Owner Data directory Log file 12 main 5432 down postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log update-alternatives: /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) を提供するために自動モードで /usr/share/postgresql/12/man/man1/postmaster.1.gz を使います sysstat (12.2.0-2) を設定しています ... Creating config file /etc/default/sysstat with new version update-alternatives: /usr/bin/sar (sar) を提供するために自動モードで /usr/bin/sar.sysstat を使います Created symlink /etc/systemd/system/multi-user.target.wants/sysstat.service → /lib/systemd/system/sysstat.service. postgresql-12-postgis-3 (3.0.0+dfsg-6ubuntu4) を設定しています ... postgresql-contrib (12+214) を設定しています ... postgresql (12+214) を設定しています ... systemd (245.4-4ubuntu3) のトリガを処理しています ... man-db (2.9.1-1) のトリガを処理しています ... libc-bin (2.31-0ubuntu9) のトリガを処理しています ...
Switch2OSMの手順からの変更点
apt-get install
するパッケージを変更。- postgresql-10-postgis-2.4 → postgresql-12-postgis-3
- postgresql-10-postgis-scripts → postgresql-12-postgis-3-scripts
変更点の経緯
sudo apt-get install postgresql postgresql-contrib postgis postgresql-10-postgis-2.4 postgresql-10-postgis-scripts
となっており、postgresqlバージョン10想定でインストールしていますが、今回はせっかくなので最新のバージョン12で進めてみます。
なお、リポジトリ上でも現在postgresqlはバージョン12が登録されています。
$ apt search "^postgresql$" ソート中... 完了 全文検索... 完了 postgresql/focal,focal 12+214 all オブジェクトリレーショナル SQL データベース (サポート版)
ところで、バージョン10系と12系でpostgis関連のパッケージを比べてみると、バージョン10系のほうが一つパッケージが多く、postgresql-10-postgis-scripts というのがあり、手順ではこれがインストール対象になっています。
$ apt search "^postgresql-10-postgis" ソート中... 完了 全文検索... 完了 postgresql-10-postgis-2.4/bionic 2.4.3+dfsg-4 amd64 Geographic objects support for PostgreSQL 10 postgresql-10-postgis-2.4-scripts/bionic,bionic 2.4.3+dfsg-4 all Geographic objects support for PostgreSQL 10 -- SQL scripts postgresql-10-postgis-scripts/bionic,bionic 2.4.3+dfsg-4 all 移行用ダミーパッケージ $ apt search "^postgresql-12-postgis" ソート中... 完了 全文検索... 完了 postgresql-12-postgis-3/focal 3.0.0+dfsg-6ubuntu4 amd64 Geographic objects support for PostgreSQL 12 postgresql-12-postgis-3-scripts/focal,focal 3.0.0+dfsg-6ubuntu4 all Geographic objects support for PostgreSQL 12 -- SQL scripts
This is a transitional dummy package. It can safely be removed.
https://launchpad.net/ubuntu/bionic/+package/postgresql-10-postgis-scripts
「移行用ダミー」「can safely be removed」とのことなので、これをインストールしなくても大丈夫かな?ということで、今回は代わりに以下のパッケージをapt install
します。
- postgresql-10-postgis-2.4 → postgresql-12-postgis-3
- postgresql-10-postgis-scripts → postgresql-12-postgis-3-scripts
postgis データベース作成
postgisデータベースを作成し設定します。
- renderaccount
Mapnikでマップをレンダリングするユーザー名と同じである必要があります。任意のユーザ名に置き換えてください。ここではrenderaccount
というユーザ名にします。もしOSにまだユーザが未作成の場合は作成します。
ubu@ubu-VirtualBox:~$ sudo useradd -m renderaccount ubu@ubu-VirtualBox:~$ sudo passwd renderaccount 新しいパスワード: 新しいパスワードを再入力してください: passwd: パスワードは正しく更新されました
ubu@ubu-VirtualBox:~$ sudo -u postgres -i postgres@ubu-VirtualBox:~$ createuser renderaccount postgres@ubu-VirtualBox:~$ createdb -E UTF8 -O renderaccount gis postgres@ubu-VirtualBox:~$ psql psql (12.2 (Ubuntu 12.2-4)) Type "help" for help. postgres=# \c gis You are now connected to database "gis" as user "postgres". gis=# CREATE EXTENSION postgis; CREATE EXTENSION gis=# CREATE EXTENSION hstore; CREATE EXTENSION gis=# ALTER TABLE geometry_columns OWNER TO renderaccount; ALTER TABLE gis=# ALTER TABLE spatial_ref_sys OWNER TO renderaccount; ALTER TABLE gis=# \q postgres@ubu-VirtualBox:~$ exit ログアウト
osm2pgsql インストール
OpenStreetMapデータをデータベースにインポートおよび管理するためのツールとしてosm2pgsqlをインストールします。
gitからのcloneと、パッケージのインストールを行います。
$ mkdir ~/src $ cd ~/src $ git clone git://github.com/openstreetmap/osm2pgsql.git Cloning into 'osm2pgsql'... remote: Enumerating objects: 282, done. remote: Counting objects: 100% (282/282), done. remote: Compressing objects: 100% (167/167), done. remote: Total 14221 (delta 122), reused 246 (delta 112), pack-reused 13939 Receiving objects: 100% (14221/14221), 46.56 MiB | 978.00 KiB/s, done. Resolving deltas: 100% (10225/10225), done.
$ cd osm2pgsql/ $ sudo apt install make cmake g++ libboost-dev libboost-system-dev libboost-filesystem-dev libexpat1-dev zlib1g-dev libbz2-dev libpq-dev libgeos-dev libgeos++-dev libproj-dev lua5.2 liblua5.2-dev パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 g++ はすでに最新バージョン (4:9.3.0-1ubuntu2) です。 g++ は手動でインストールしたと設定されました。 libboost-dev はすでに最新バージョン (1.71.0.0ubuntu2) です。 libboost-dev は手動でインストールしたと設定されました。 libboost-filesystem-dev はすでに最新バージョン (1.71.0.0ubuntu2) です。 libboost-filesystem-dev は手動でインストールしたと設定されました。 libboost-system-dev はすでに最新バージョン (1.71.0.0ubuntu2) です。 libboost-system-dev は手動でインストールしたと設定されました。 libbz2-dev はすでに最新バージョン (1.0.8-2) です。 libexpat1-dev はすでに最新バージョン (2.2.9-1build1) です。 libexpat1-dev は手動でインストールしたと設定されました。 liblua5.2-dev はすでに最新バージョン (5.2.4-1.1build3) です。 libpq-dev はすでに最新バージョン (12.2-4) です。 make はすでに最新バージョン (4.2.1-1.2) です。 make は手動でインストールしたと設定されました。 zlib1g-dev はすでに最新バージョン (1:1.2.11.dfsg-2ubuntu1) です。 zlib1g-dev は手動でインストールしたと設定されました。 libgeos++-dev はすでに最新バージョン (3.8.0-1build1) です。 libgeos-dev はすでに最新バージョン (3.8.0-1build1) です。 libproj-dev はすでに最新バージョン (6.3.1-1) です。 以下の追加パッケージがインストールされます: cmake-data libjsoncpp1 librhash0 提案パッケージ: cmake-doc ninja-build 以下のパッケージが新たにインストールされます: cmake cmake-data libjsoncpp1 librhash0 lua5.2 アップグレード: 0 個、新規インストール: 5 個、削除: 0 個、保留: 1 個。 5,569 kB のアーカイブを取得する必要があります。 この操作後に追加で 28.7 MB のディスク容量が消費されます。 続行しますか? [Y/n] Y 取得:1 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 cmake-data all 3.16.3-1ubuntu1 [1,612 kB] 取得:2 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 libjsoncpp1 amd64 1.7.4-3.1ubuntu2 [75.6 kB] 取得:3 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 librhash0 amd64 1.3.9-1 [113 kB] 取得:4 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 cmake amd64 3.16.3-1ubuntu1 [3,669 kB] 取得:5 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 lua5.2 amd64 5.2.4-1.1build3 [99.8 kB] 5,569 kB を 42秒 で取得しました (134 kB/s) 以前に未選択のパッケージ cmake-data を選択しています。 (データベースを読み込んでいます ... 現在 227545 個のファイルとディレクトリがインストールされています。) .../cmake-data_3.16.3-1ubuntu1_all.deb を展開する準備をしています ... cmake-data (3.16.3-1ubuntu1) を展開しています... 以前に未選択のパッケージ libjsoncpp1:amd64 を選択しています。 .../libjsoncpp1_1.7.4-3.1ubuntu2_amd64.deb を展開する準備をしています ... libjsoncpp1:amd64 (1.7.4-3.1ubuntu2) を展開しています... 以前に未選択のパッケージ librhash0:amd64 を選択しています。 .../librhash0_1.3.9-1_amd64.deb を展開する準備をしています ... librhash0:amd64 (1.3.9-1) を展開しています... 以前に未選択のパッケージ cmake を選択しています。 .../cmake_3.16.3-1ubuntu1_amd64.deb を展開する準備をしています ... cmake (3.16.3-1ubuntu1) を展開しています... 以前に未選択のパッケージ lua5.2 を選択しています。 .../lua5.2_5.2.4-1.1build3_amd64.deb を展開する準備をしています ... lua5.2 (5.2.4-1.1build3) を展開しています... lua5.2 (5.2.4-1.1build3) を設定しています ... update-alternatives: /usr/bin/lua (lua-interpreter) を提供するために自動モードで /usr/bin/lua5.2 を使います update-alternatives: /usr/bin/luac (lua-compiler) を提供するために自動モードで /usr/bin/luac5.2 を使います librhash0:amd64 (1.3.9-1) を設定しています ... cmake-data (3.16.3-1ubuntu1) を設定しています ... libjsoncpp1:amd64 (1.7.4-3.1ubuntu2) を設定しています ... cmake (3.16.3-1ubuntu1) を設定しています ... man-db (2.9.1-1) のトリガを処理しています ... libc-bin (2.31-0ubuntu9) のトリガを処理しています ...
ビルドします。
$ mkdir build && cd build $ cmake .. -- The C compiler identification is GNU 9.3.0 -- The CXX compiler identification is GNU 9.3.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Building osm2pgsql 1.2.0 -- Building in C++11 mode -- Found Git: /usr/bin/git (found version "2.25.1") -- Looking for include file termios.h -- Looking for include file termios.h - found -- Looking for include file unistd.h -- Looking for include file unistd.h - found -- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11") -- Looking for pthread.h -- Looking for pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - found -- Found Threads: TRUE -- Found Protozero: /home/ubu/src/osm2pgsql/contrib/protozero/include (found suitable version "1.6.8", minimum required is "1.6.3") -- Found EXPAT: /usr/lib/x86_64-linux-gnu/libexpat.so (found version "2.2.9") -- Found BZip2: /usr/lib/x86_64-linux-gnu/libbz2.so (found version "1.0.8") -- Looking for BZ2_bzCompressInit -- Looking for BZ2_bzCompressInit - found -- Found Osmium: /home/ubu/src/osm2pgsql/contrib/libosmium/include (found suitable version "2.15.5", minimum required is "2.15.4") -- Found Lua: /usr/lib/x86_64-linux-gnu/liblua5.2.so;/usr/lib/x86_64-linux-gnu/libm.so (found version "5.2.4") -- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found suitable version "1.71.0", minimum required is "1.50") found components: system filesystem -- Found PostgreSQL: /usr/lib/x86_64-linux-gnu/libpq.so (found version "12.2") -- Found Proj4 /usr/lib/x86_64-linux-gnu/libproj.so -- Libraries used to build: Boost::system;Boost::filesystem;/usr/lib/x86_64-linux-gnu/libpq.so;/usr/lib/x86_64-linux-gnu/libz.so;-lpthread;/usr/lib/x86_64-linux-gnu/libexpat.so;/usr/lib/x86_64-linux-gnu/libbz2.so;/usr/lib/x86_64-linux-gnu/libproj.so;/usr/lib/x86_64-linux-gnu/liblua5.2.so;/usr/lib/x86_64-linux-gnu/libm.so -- Looking for clang-tidy -- Looking for clang-tidy - not found -- Build target 'clang-tidy' will not be available. -- Tests disabled. Set BUILD_TESTS=ON to enable tests. -- Configuring done -- Generating done -- Build files have been written to: /home/ubu/src/osm2pgsql/build
$ make Scanning dependencies of target osm2pgsql_lib [ 2%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/db-copy.cpp.o [ 4%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/expire-tiles.cpp.o [ 7%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/gazetteer-style.cpp.o [ 9%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/geometry-processor.cpp.o [ 11%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/geom-transform.cpp.o [ 14%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/id-tracker.cpp.o [ 16%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/middle-pgsql.cpp.o [ 19%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/middle-ram.cpp.o [ 21%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/node-persistent-cache.cpp.o [ 23%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/node-ram-cache.cpp.o [ 26%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/options.cpp.o [ 28%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/osmdata.cpp.o [ 30%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/osmium-builder.cpp.o [ 33%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/output-gazetteer.cpp.o [ 35%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/output-multi.cpp.o [ 38%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/output-null.cpp.o [ 40%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/output-pgsql.cpp.o [ 42%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/output.cpp.o [ 45%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/parse-osmium.cpp.o [ 47%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/pgsql.cpp.o [ 50%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/processor-line.cpp.o [ 52%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/processor-point.cpp.o [ 54%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/processor-polygon.cpp.o [ 57%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/reprojection.cpp.o [ 59%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/sprompt.cpp.o [ 61%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/table.cpp.o [ 64%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/taginfo.cpp.o [ 66%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/tagtransform-c.cpp.o [ 69%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/tagtransform.cpp.o [ 71%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/util.cpp.o [ 73%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/wildcmp.cpp.o [ 76%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/flex-table.cpp.o [ 78%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/flex-table-column.cpp.o [ 80%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/lua-utils.cpp.o [ 83%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/output-flex.cpp.o [ 85%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/tagtransform-lua.cpp.o [ 88%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/lua-init.cpp.o [ 90%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/version.cpp.o [ 92%] Building CXX object src/CMakeFiles/osm2pgsql_lib.dir/reprojection-generic-proj4.cpp.o [ 95%] Linking CXX static library libosm2pgsql.a [ 95%] Built target osm2pgsql_lib Scanning dependencies of target osm2pgsql [ 97%] Building CXX object CMakeFiles/osm2pgsql.dir/src/osm2pgsql.cpp.o [100%] Linking CXX executable osm2pgsql [100%] Built target osm2pgsql
$ sudo make install [ 95%] Built target osm2pgsql_lib [100%] Built target osm2pgsql Install the project... -- Install configuration: "RelWithDebInfo" -- Installing: /usr/local/bin/osm2pgsql -- Installing: /usr/local/share/man/man1/osm2pgsql.1 -- Installing: /usr/local/share/osm2pgsql/default.style -- Installing: /usr/local/share/osm2pgsql/empty.style
Mapnik インストール
最終的な手順
Switch2OSMの手順どおりコマンドを実行するには支障があるため、以降に記載の変更を行う必要があります。変更後の手順は以下のとおりです。
$ sudo apt-get install autoconf apache2-dev libtool libxml2-dev libbz2-dev libgeos-dev libgeos++-dev libproj-dev gdal-bin libmapnik-dev mapnik-utils python3-mapnik パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 apache2-dev はすでに最新バージョン (2.4.41-4ubuntu3) です。 autoconf はすでに最新バージョン (2.69-11.1) です。 libbz2-dev はすでに最新バージョン (1.0.8-2) です。 libtool はすでに最新バージョン (2.4.6-14) です。 libxml2-dev はすでに最新バージョン (2.9.10+dfsg-5) です。 libgeos++-dev はすでに最新バージョン (3.8.0-1build1) です。 libgeos-dev はすでに最新バージョン (3.8.0-1build1) です。 libproj-dev はすでに最新バージョン (6.3.1-1) です。 以下の追加パッケージがインストールされます: fonts-dejavu fonts-dejavu-extra gir1.2-harfbuzz-0.0 libgraphite2-dev libharfbuzz-dev libharfbuzz-gobject0 libmapbox-variant-dev libmapnik3.0 mapnik-doc python3-gdal python3-numpy 提案パッケージ: libgdal-grass libgraphite2-utils python-numpy-doc python3-pytest python3-numpy-dbg 以下のパッケージが新たにインストールされます: fonts-dejavu fonts-dejavu-extra gdal-bin gir1.2-harfbuzz-0.0 libgraphite2-dev libharfbuzz-dev libharfbuzz-gobject0 libmapbox-variant-dev libmapnik-dev libmapnik3.0 mapnik-doc mapnik-utils python3-gdal python3-mapnik python3-numpy アップグレード: 0 個、新規インストール: 15 個、削除: 0 個、保留: 1 個。 14.1 MB のアーカイブを取得する必要があります。 この操作後に追加で 62.3 MB のディスク容量が消費されます。 続行しますか? [Y/n] Y 取得:1 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 fonts-dejavu-extra all 2.37-1 [1,953 kB] 取得:2 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 fonts-dejavu all 2.37-1 [3,130 B] 取得:3 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 python3-numpy amd64 1:1.17.4-5ubuntu3 [2,725 kB] 取得:4 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 python3-gdal amd64 3.0.4+dfsg-1build3 [527 kB] 取得:5 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 gdal-bin amd64 3.0.4+dfsg-1build3 [256 kB] 取得:6 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 gir1.2-harfbuzz-0.0 amd64 2.6.4-1ubuntu4 [26.3 kB] 取得:7 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 libgraphite2-dev amd64 1.3.13-11build1 [14.7 kB] 取得:8 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 libharfbuzz-gobject0 amd64 2.6.4-1ubuntu4 [20.4 kB] 取得:9 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 libharfbuzz-dev amd64 2.6.4-1ubuntu4 [526 kB] 取得:10 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 libmapbox-variant-dev all 1.1.6-1 [14.8 kB] 取得:11 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 libmapnik3.0 amd64 3.0.23+ds-1build1 [2,488 kB] 取得:12 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 libmapnik-dev amd64 3.0.23+ds-1build1 [665 kB] 取得:13 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 mapnik-doc all 3.0.23+ds-1build1 [2,110 kB] 取得:14 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 mapnik-utils amd64 3.0.23+ds-1build1 [222 kB] 取得:15 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 python3-mapnik amd64 1:0.0~20180723-588fc9062-3ubuntu3 [2,571 kB] 14.1 MB を 44秒 で取得しました (321 kB/s) 以前に未選択のパッケージ fonts-dejavu-extra を選択しています。 (データベースを読み込んでいます ... 現在 230336 個のファイルとディレクトリがインストールされています。) .../00-fonts-dejavu-extra_2.37-1_all.deb を展開する準備をしています ... fonts-dejavu-extra (2.37-1) を展開しています... 以前に未選択のパッケージ fonts-dejavu を選択しています。 .../01-fonts-dejavu_2.37-1_all.deb を展開する準備をしています ... fonts-dejavu (2.37-1) を展開しています... 以前に未選択のパッケージ python3-numpy を選択しています。 .../02-python3-numpy_1%3a1.17.4-5ubuntu3_amd64.deb を展開する準備をしています ... python3-numpy (1:1.17.4-5ubuntu3) を展開しています... 以前に未選択のパッケージ python3-gdal を選択しています。 .../03-python3-gdal_3.0.4+dfsg-1build3_amd64.deb を展開する準備をしています ... python3-gdal (3.0.4+dfsg-1build3) を展開しています... 以前に未選択のパッケージ gdal-bin を選択しています。 .../04-gdal-bin_3.0.4+dfsg-1build3_amd64.deb を展開する準備をしています ... gdal-bin (3.0.4+dfsg-1build3) を展開しています... 以前に未選択のパッケージ gir1.2-harfbuzz-0.0:amd64 を選択しています。 .../05-gir1.2-harfbuzz-0.0_2.6.4-1ubuntu4_amd64.deb を展開する準備をしています ... gir1.2-harfbuzz-0.0:amd64 (2.6.4-1ubuntu4) を展開しています... 以前に未選択のパッケージ libgraphite2-dev:amd64 を選択しています。 .../06-libgraphite2-dev_1.3.13-11build1_amd64.deb を展開する準備をしています ... libgraphite2-dev:amd64 (1.3.13-11build1) を展開しています... 以前に未選択のパッケージ libharfbuzz-gobject0:amd64 を選択しています。 .../07-libharfbuzz-gobject0_2.6.4-1ubuntu4_amd64.deb を展開する準備をしています ... libharfbuzz-gobject0:amd64 (2.6.4-1ubuntu4) を展開しています... 以前に未選択のパッケージ libharfbuzz-dev:amd64 を選択しています。 .../08-libharfbuzz-dev_2.6.4-1ubuntu4_amd64.deb を展開する準備をしています ... libharfbuzz-dev:amd64 (2.6.4-1ubuntu4) を展開しています... 以前に未選択のパッケージ libmapbox-variant-dev を選択しています。 .../09-libmapbox-variant-dev_1.1.6-1_all.deb を展開する準備をしています ... libmapbox-variant-dev (1.1.6-1) を展開しています... 以前に未選択のパッケージ libmapnik3.0 を選択しています。 .../10-libmapnik3.0_3.0.23+ds-1build1_amd64.deb を展開する準備をしています ... libmapnik3.0 (3.0.23+ds-1build1) を展開しています... 以前に未選択のパッケージ libmapnik-dev を選択しています。 .../11-libmapnik-dev_3.0.23+ds-1build1_amd64.deb を展開する準備をしています ... libmapnik-dev (3.0.23+ds-1build1) を展開しています... 以前に未選択のパッケージ mapnik-doc を選択しています。 .../12-mapnik-doc_3.0.23+ds-1build1_all.deb を展開する準備をしています ... mapnik-doc (3.0.23+ds-1build1) を展開しています... 以前に未選択のパッケージ mapnik-utils を選択しています。 .../13-mapnik-utils_3.0.23+ds-1build1_amd64.deb を展開する準備をしています ... mapnik-utils (3.0.23+ds-1build1) を展開しています... 以前に未選択のパッケージ python3-mapnik を選択しています。 .../14-python3-mapnik_1%3a0.0~20180723-588fc9062-3ubuntu3_amd64.deb を展開する準備をしています ... python3-mapnik (1:0.0~20180723-588fc9062-3ubuntu3) を展開しています... mapnik-doc (3.0.23+ds-1build1) を設定しています ... libharfbuzz-gobject0:amd64 (2.6.4-1ubuntu4) を設定しています ... gir1.2-harfbuzz-0.0:amd64 (2.6.4-1ubuntu4) を設定しています ... libgraphite2-dev:amd64 (1.3.13-11build1) を設定しています ... python3-numpy (1:1.17.4-5ubuntu3) を設定しています ... fonts-dejavu-extra (2.37-1) を設定しています ... libmapbox-variant-dev (1.1.6-1) を設定しています ... python3-gdal (3.0.4+dfsg-1build3) を設定しています ... fonts-dejavu (2.37-1) を設定しています ... libharfbuzz-dev:amd64 (2.6.4-1ubuntu4) を設定しています ... libmapnik3.0 (3.0.23+ds-1build1) を設定しています ... python3-mapnik (1:0.0~20180723-588fc9062-3ubuntu3) を設定しています ... gdal-bin (3.0.4+dfsg-1build3) を設定しています ... libmapnik-dev (3.0.23+ds-1build1) を設定しています ... mapnik-utils (3.0.23+ds-1build1) を設定しています ... man-db (2.9.1-1) のトリガを処理しています ... fontconfig (2.13.1-2ubuntu3) のトリガを処理しています ... libc-bin (2.31-0ubuntu9) のトリガを処理しています ...
mapnikが問題なくインストールされたか確認します。
$ python3 Python 3.8.2 (default, Mar 13 2020, 10:14:16) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import mapnik >>> quit()
Switch2OSMの手順からの変更点
apt-get install
するパッケージを変更。- python-mapnik → python3-mapnik
変更点の経緯
以下のエラーが発生しました。
$ sudo apt-get install autoconf apache2-dev libtool libxml2-dev libbz2-dev libgeos-dev libgeos++-dev libproj-dev gdal-bin libmapnik-dev mapnik-utils python-mapnik パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 apache2-dev はすでに最新バージョン (2.4.41-4ubuntu3) です。 autoconf はすでに最新バージョン (2.69-11.1) です。 libbz2-dev はすでに最新バージョン (1.0.8-2) です。 libtool はすでに最新バージョン (2.4.6-14) です。 libxml2-dev はすでに最新バージョン (2.9.10+dfsg-5) です。 libgeos++-dev はすでに最新バージョン (3.8.0-1build1) です。 libgeos-dev はすでに最新バージョン (3.8.0-1build1) です。 libproj-dev はすでに最新バージョン (6.3.1-1) です。 インストールすることができないパッケージがありました。おそらく、あり得 ない状況を要求したか、(不安定版ディストリビューションを使用しているの であれば) 必要なパッケージがまだ作成されていなかったり Incoming から移 動されていないことが考えられます。 以下の情報がこの問題を解決するために役立つかもしれません: 以下のパッケージには満たせない依存関係があります: python-mapnik : 依存: libboost-thread1.65.1 しかし、インストールすることができません 依存: libicu60 (>= 60.1-1~) しかし、インストールすることができません E: 問題を解決することができません。壊れた変更禁止パッケージがあります。
python-mapnikが依存しているlibboost-threadとlibicuの指定のバージョンが、リポジトリに無いのが原因のようです。現在のバージョンからするとだいぶ古いものに依存しています。
$ apt search libboost-thread ソート中... 完了 全文検索... 完了 libboost-thread-dev/focal,now 1.71.0.0ubuntu2 amd64 [インストール済み、自動] portable C++ multi-threading (default version) libboost-thread1.62-dev/bionic 1.62.0+dfsg-5 amd64 portable C++ multi-threading libboost-thread1.62.0/bionic 1.62.0+dfsg-5 amd64 portable C++ multi-threading libboost-thread1.67-dev/focal 1.67.0-17ubuntu8 amd64 portable C++ multi-threading libboost-thread1.67.0/focal 1.67.0-17ubuntu8 amd64 portable C++ multi-threading libboost-thread1.71-dev/focal,now 1.71.0-6ubuntu6 amd64 [インストール済み、自動] portable C++ multi-threading libboost-thread1.71.0/focal,now 1.71.0-6ubuntu6 amd64 [インストール済み、自動] portable C++ multi-threading $ apt search "^libicu" ソート中... 完了 全文検索... 完了 libicu-dev/focal,now 66.1-2ubuntu2 amd64 [インストール済み] Unicode 用の国際化コンポーネントの開発用ファイル libicu-le-hb-dev/focal 1.0.3+git180724-3build2 amd64 ICU Layout Engine API on top of HarfBuzz shaping library (development) libicu-le-hb0/focal 1.0.3+git180724-3build2 amd64 ICU Layout Engine API on top of HarfBuzz shaping library libicu4j-4.2-java/bionic,bionic 4.2.1.1-6fakesync all Library for Unicode support and internationalization libicu4j-4.4-java/focal,focal,bionic,bionic 4.4.2.2-3 all Library for Unicode support and internationalization libicu4j-49-java/bionic,bionic 49.1-3 all Library for Unicode support and internationalization libicu4j-java/focal,focal 62.1-2 all Library for Unicode support and internationalization libicu4j-java-doc/focal,focal 62.1-2 all Library for Unicode support and internationalization - Docs libicu66/focal,now 66.1-2ubuntu2 amd64 [インストール済み、自動] Unicode 用の国際化コンポーネント
python-mapnikですが、python2用とpython3用があります。元々の手順ではpython2用の方をインストールしようとしています。
$ apt search "^python.*mapnik" ソート中... 完了 全文検索... 完了 python-mapnik/bionic 1:0.0~20180130-804a7947d-1 amd64 Python 2 interface to the mapnik library python3-mapnik/focal 1:0.0~20180723-588fc9062-3ubuntu3 amd64 Python 3 interface to the mapnik library
前述のように依存しているパッケージがだいぶ古いですし、pythonも今更2というのも古いので、今回はpython3用のmapnikをインストールすることにします。
mod_tile インストール
$ cd ~/src $ git clone -b switch2osm git://github.com/SomeoneElseOSM/mod_tile.git $ cd mod_tile $ ./autogen.sh $ ./configure $ make $ sudo make install $ sudo make install-mod_tile $ sudo ldconfig
スタイルシートを構成
ここから先の手順は、postgresqlとMapnikで使用することにしたユーザで行っていきます。
今回は前述の通り「renderaccount」というユーザをpostgresqlとMapnikで使用することにしたので、ここからはrenderaccountになって作業を進めます。
最終的な手順
GitHubから「OpenStreetMap Carto」のリポジトリをクローンします。
$ cd ~/src $ git clone git://github.com/gravitystorm/openstreetmap-carto.git $ cd openstreetmap-carto
npmとnodejsをインストールします。
$ sudo apt install npm nodejs
cartoをインストールし、インストールが完了したことを確認知るためにバージョンを表示します。
$ sudo npm install -g carto /usr/local/bin/carto -> /usr/local/lib/node_modules/carto/bin/carto + carto@1.2.0 added 64 packages from 29 contributors in 5.622s $ carto -v 1.2.0
cartoのプロジェクトファイルをMapnik用の形式に変換します。大量にWarningが出ますが無視します。
$ carto project.mml > mapnik.xml
Switch2OSMの手順からの変更点
- 以下の手順をスキップ。
sudo apt-get install nodejs-dev node-gyp libssl1.0-dev
変更点の経緯
$ sudo apt-get install nodejs-dev node-gyp libssl1.0-dev パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 パッケージ libssl1.0-dev は使用できませんが、別のパッケージから参照されます。 これは、パッケージが欠落しているか、廃止されたか、または別のソース からのみ利用可能であることを意味します。 E: パッケージ 'libssl1.0-dev' にはインストール候補がありません
» Ubuntu » パッケージ » パッケージ検索結果によると、libssl1.0-dev は以下のリポジトリにしか存在しているようですが、今回の環境ではbionicのsecurityを既にリストに加えているにも関わらず、ヒットしないようです。
- bionic (18.04LTS) (libdevel): Secure Sockets Layer toolkit – development files
1.0.2n-1ubuntu5.3 [security]: amd64 i386
1.0.2n-1ubuntu5 [ports]: arm64 armhf ppc64el s390x - bionic-updates (libdevel): Secure Sockets Layer toolkit – development files
1.0.2n-1ubuntu5.3: amd64 arm64 armhf i386 ppc64el s390x
$ apt search "^libssl" ソート中... 完了 全文検索... 完了 libssl-dev/focal,now 1.1.1f-1ubuntu2 amd64 [インストール済み、自動] Secure Sockets Layer toolkit - development files libssl-doc/focal,focal 1.1.1f-1ubuntu2 all Secure Sockets Layer toolkit - development documentation libssl-ocaml/focal 0.5.9-1build1 amd64 OCaml bindings for OpenSSL (runtime) libssl-ocaml-dev/focal 0.5.9-1build1 amd64 OCaml bindings for OpenSSL libssl-utils-clojure/focal,focal 0.8.3-2 all library for SSL certificate management on the JVM libssl1.1/focal,now 1.1.1f-1ubuntu2 amd64 [インストール済み、自動] Secure Sockets Layer ツールキット - 共有ライブラリ
libssl1.0-dev
の代わりにlibssl-dev
を指定してみます。
$ sudo apt-get install nodejs-dev node-gyp libssl-dev パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 libssl-dev はすでに最新バージョン (1.1.1f-1ubuntu2) です。 libssl-dev は手動でインストールしたと設定されました。 インストールすることができないパッケージがありました。おそらく、あり得 ない状況を要求したか、(不安定版ディストリビューションを使用しているの であれば) 必要なパッケージがまだ作成されていなかったり Incoming から移 動されていないことが考えられます。 以下の情報がこの問題を解決するために役立つかもしれません: 以下のパッケージには満たせない依存関係があります: node-gyp : 依存: libnode-dev しかし、インストールされようとしていません nodejs-dev : 依存: libssl1.0-dev (>= 1.0.2) しかし、インストールすることができません 依存: nodejs (= 8.10.0~dfsg-2ubuntu0.4) E: 問題を解決することができません。壊れた変更禁止パッケージがあります。
またエラーが発生します。特にnodejs-devがlibssl1.0-devに依存しており、どうしてもこれが必要とされてしまいますが、前述の通りlibssl1.0-devは見当たりません。
ところで、sudo apt-get install nodejs-dev node-gyp libssl1.0-dev
するという手順は、後続のsudo apt install npm nodejs
を行うためのようです。npmとnodejsは今回の環境ではいきなりインストールできてしまうので、sudo apt-get install nodejs-dev node-gyp libssl1.0-dev
はスキップすることにします。
地図データをダウンロードしDBに登録
最初は少量のテストデータのみをロードします。アゼルバイジャン(21MB)を使用します。ちなみに日本は1.4GBもあるため後回しにした方がよいです。
$ mkdir ~/data $ cd ~/data $ wget https://download.geofabrik.de/asia/azerbaijan-latest.osm.pbf
osm2pgsql
コマンドで、OpenStreetMapデータをデータベースに挿入します。オプションの内容は以下のとおりです。
オプション | 説明 |
---|---|
-d gis | 使用するデータベース(「gis」は以前はデフォルトでしたが、現在は指定する必要があります)。 |
–create | 既存のデータベースに追加しようとするのではなく、空のデータベースにデータをロードします。 |
–slim | 地図データを差分アップデートするためには、指定しておく必要があります。 |
-G | マルチポリゴンの処理方法を決定します。 |
–hstore | 明示的なデータベース列がないタグをレンダリングに使用できるようにします。 |
–tag-transform-script | タグ処理に使用されるluaスクリプトを定義します。これは、スタイル自体がタグを処理する前にOSMタグを処理する簡単な方法であり、スタイルロジックを大幅に単純化する可能性があります。 |
-C 2500 | インポートプロセスにosm2pgsqlに2.5 GBのメモリを割り当てます。メモリが少ない場合は、小さい数を試すことができます。また、メモリが不足したためにインポートプロセスが強制終了された場合は、小さい数または小さいOSM抽出を試す必要があります。 |
–number-processes 1 | 1 CPUを使用します。より多くのコアが利用可能な場合、より多くを使用できます。 |
-S | このファイルにデータベース列を作成します(実際には「openstreetmap-carto」から変更されていません) |
$ osm2pgsql -d gis --create --slim -G --hstore --tag-transform-script ~/src/openstreetmap-carto/openstreetmap-carto.lua -C 2500 --number-processes 1 -S ~/src/openstreetmap-carto/openstreetmap-carto.style ~/data/azerbaijan-latest.osm.pbf osm2pgsql version 1.2.0 (1.2.0-396-g5caa410) Allocating memory for dense node cache Allocating dense node cache in one big chunk Allocating memory for sparse node cache Sharing dense sparse Node-cache: cache=2500MB, maxblocks=40000*65536, allocation method=11 Mid: pgsql, cache=2500 Setting up table: planet_osm_nodes Setting up table: planet_osm_ways Setting up table: planet_osm_rels Using lua based tag processing pipeline with script /home/renderaccount/src/openstreetmap-carto/openstreetmap-carto.lua Using projection SRS 3857 (Spherical Mercator) Setting up table: planet_osm_point Setting up table: planet_osm_line Setting up table: planet_osm_polygon Setting up table: planet_osm_roads Reading in file: /home/renderaccount/data/azerbaijan-latest.osm.pbf Using PBF parser. Processing: Node(3002k 107.2k/s) Way(281k 14.05k/s) Relation(2850 2850.0/s) parse time: 49s Node stats: total(3002231), max(7472267093) in 28s Way stats: total(281242), max(798956686) in 20s Relation stats: total(2850), max(11050334) in 1s Sorting data and creating indexes for planet_osm_point Using native order for clustering 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 8s Completed planet_osm_point Sorting data and creating indexes for planet_osm_line Using native order for clustering 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 14s Completed planet_osm_line Sorting data and creating indexes for planet_osm_polygon Using native order for clustering 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 6s Completed planet_osm_polygon Sorting data and creating indexes for planet_osm_roads Using native order for clustering 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 1s Completed planet_osm_roads Stopping table: planet_osm_nodes Stopped table: planet_osm_nodes in 0s Stopping table: planet_osm_ways Building index on table: planet_osm_ways Stopped table: planet_osm_ways in 26s Stopping table: planet_osm_rels Building index on table: planet_osm_rels Stopped table: planet_osm_rels in 2s Osm2pgsql took 108s overall node cache: stored: 3002231(100.00%), storage efficiency: 50.08% (dense blocks: 9, sparse nodes: 2960358), hit rate: 100.00%
シェープファイルをダウンロード
$ scripts/get-shapefiles.py Starting get-shapefiles.py... 1-1. Downloading 'simplified-water-polygons-split-3857'... Bytes: 23858488 23858488 [100%] 1-2. Expanding 'simplified-water-polygons-split-3857'... Done. 1-3. Indexing 'data/simplified-water-polygons-split-3857/simplified_water_polygons.shp'... max tree depth:8 split ratio:0.55 processing data/simplified-water-polygons-split-3857/simplified_water_polygons.shp 9994 length=57870 version=1000 type=5 extent:box2d(-20037508.3399999998509884,-14773407.4192944895476103,20037508.3399999998509884,20037508.3399999998509884) number shapes=14455 number nodes=7435 done! 2-1. Downloading 'ne_110m_admin_0_boundary_lines_land'... Bytes: 45820 45820 [100%] 2-2. Expanding 'ne_110m_admin_0_boundary_lines_land'... Done. 2-3. Indexing 'data/ne_110m_admin_0_boundary_lines_land/ne_110m_admin_0_boundary_lines_land.shp'... max tree depth:8 split ratio:0.55 processing data/ne_110m_admin_0_boundary_lines_land/ne_110m_admin_0_boundary_lines_land.shp 9994 length=794 version=1000 type=3 extent:box2d(-140.9977800000000059,-54.8968100000000021,141.0338517600138175,70.1641900000000049) number shapes=186 number nodes=176 done! 3-1. Downloading 'water-polygons-split-3857'... Bytes: 639139687 639139687 [100%] 3-2. Expanding 'water-polygons-split-3857'... Done. 3-3. Indexing 'data/water-polygons-split-3857/water_polygons.shp'... max tree depth:8 split ratio:0.55 processing data/water-polygons-split-3857/water_polygons.shp 9994 length=58114 version=1000 type=5 extent:box2d(-20037508.3399999998509884,-14773407.4192944895476103,20037508.3399999998509884,20037508.3399999998509884) number shapes=14516 number nodes=7436 done! 4-1. Downloading 'antarctica-icesheet-polygons-3857'... Bytes: 53277428 53277428 [100%] 4-2. Expanding 'antarctica-icesheet-polygons-3857'... Done. 4-3. Indexing 'data/antarctica-icesheet-polygons-3857/icesheet_polygons.shp'... max tree depth:8 split ratio:0.55 processing data/antarctica-icesheet-polygons-3857/icesheet_polygons.shp 9994 length=67578 version=1000 type=5 extent:box2d(-20037508.3427892439067364,-20037508.3427892439067364,20037508.3427892439067364,-8479237.0339447762817144) number shapes=16882 number nodes=1020 done! 5-1. Downloading 'antarctica-icesheet-outlines-3857'... Bytes: 53904810 53904810 [100%] 5-2. Expanding 'antarctica-icesheet-outlines-3857'... Done. 5-3. Indexing 'data/antarctica-icesheet-outlines-3857/icesheet_outlines.shp'... max tree depth:8 split ratio:0.55 processing data/antarctica-icesheet-outlines-3857/icesheet_outlines.shp 9994 length=317942 version=1000 type=3 extent:box2d(-20037508.3427892439067364,-20037508.3427892439067364,20037508.3427892439067364,-8479237.0339447762817144) number shapes=79473 number nodes=1920 done! ...script completed in 696.8 seconds.
フォントをインストール
$ sudo apt-get install fonts-noto-cjk fonts-noto-hinted fonts-noto-unhinted ttf-unifont
ウェブサーバーを設定
renderdを設定
/usr/local/etc/renderd.conf
を確認します。必要であれば内容を編集します。今回はこのままにします。
[renderd] num_threads=4 tile_dir=/var/lib/mod_tile stats_file=/var/run/renderd/renderd.stats [mapnik] plugins_dir=/usr/lib/mapnik/3.0/input font_dir=/usr/share/fonts/truetype font_dir_recurse=1 [ajt] URI=/hot/ TILEDIR=/var/lib/mod_tile XML=/home/renderaccount/src/openstreetmap-carto/mapnik.xml HOST=localhost TILESIZE=256 MAXZOOM=20
Apacheを設定
$ sudo mkdir /var/lib/mod_tile $ sudo chown renderaccount /var/lib/mod_tile $ sudo mkdir /var/run/renderd $ sudo chown renderaccount /var/run/renderd
/etc/apache2/conf-available/mod_tile.conf
に以下の行を追加します。今回の環境ではこのファイルはまだ存在していなかったので新規作成ということになります。
/etc/apache2/conf-available/mod_tile.conf
LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so
Apache2のmod_tileの設定を有効にします。
$ sudo a2enconf mod_tile Enabling conf mod_tile. To activate the new configuration, you need to run: systemctl reload apache2
systemctl reload apache2
はまだ実行しません。
Apacheにレンダリングについて通知するため、/etc/apache2/sites-available/000-default.conf
の「ServerAdmin」行と「DocumentRoot」行の間に以下のように追記します。
/etc/apache2/sites-available/000-default.conf
<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@localhost LoadTileConfigFile /usr/local/etc/renderd.conf ModTileRenderdSocketName /var/run/renderd/renderd.sock # Timeout before giving up for a tile to be rendered ModTileRequestTimeout 0 # Timeout before giving up for a tile to be rendered that is otherwise missing ModTileMissingRequestTimeout 30 DocumentRoot /var/www/html # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
apacheをリロードします。
元々の手順ではsudo service apache2 reload
を2回実行すると書いてありますが、上記で実行したsudo a2enconf mod_tile
の結果ではsystemctl reload apache2
を実行するよう促されているので、今回はこちらを実行します。
$ sudo systemctl reload apache2 $ sudo systemctl reload apache2
ブラウザからhttp://IPアドレス/index.html
へアクセスし、apacheが動作していることを示すページが表示されることを確認します。
rendered をフォアグラウンドで実行
renderedを実行して、いくつかのタイルをレンダリングしてみます。敢えてフォアグラウンドで実行して、発生する警告やエラーを確認できるようにします。
$ renderd -f -c /usr/local/etc/renderd.conf
ブラウザからhttp://IPアドレス/hot/0/0/0.png
へアクセスすると世界地図が表示されます。この時、コマンドラインには以下のログが出力されます。

renderd[32213]: DEBUG: Got incoming connection, fd 7, number 1 renderd[32213]: DEBUG: Got incoming request with protocol version 2 renderd[32213]: DEBUG: Got command RenderPrio fd(7) xml(ajt), z(0), x(0), y(0), mime(image/png), options() renderd[32213]: DEBUG: START TILE ajt 0 0-0 0-0, new metatile renderd[32213]: Rendering projected coordinates 0 0 0 -> -20037508.342800|-20037508.342800 20037508.342800|20037508.342800 to a 1 x 1 tile renderd[32213]: DEBUG: DONE TILE ajt 0 0-0 0-0 in 0.342 seconds debug: Creating and writing a metatile to /var/lib/mod_tile/ajt/0/0/0/0/0/0.meta renderd[32213]: DEBUG: Sending render cmd(3 ajt 0/0/0) with protocol version 2 to fd 7 renderd[32213]: DEBUG: Connection 0, fd 7 closed, now 0 left
Ctrl+Cでrenderdを終了します。
rendered をバックグラウンドで実行
~/src/mod_tile/debian/renderd.init
内の「RUNASUSER」が、Mapnikで使用することにしたユーザ(今回は「renderaccount」)になっていることを確認します。そうでなかった場合は編集します。
$ grep RUNASUSER ~/src/mod_tile/debian/renderd.init RUNASUSER=renderaccount [ -d "$PIDSOCKDIR" ] || mkdir -p $PIDSOCKDIR && chown $RUNASUSER $PIDSOCKDIR start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $RUNASUSER --exec $DAEMON --test > /dev/null \ start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $RUNASUSER --exec $DAEMON -- \
renderd.initとrenderd.serviceをシステムディレクトリにコピーします。
$ sudo cp ~/src/mod_tile/debian/renderd.init /etc/init.d/renderd $ sudo chmod u+x /etc/init.d/renderd $ sudo cp ~/src/mod_tile/debian/renderd.service /lib/systemd/system/
renderdが起動することを確認します。
$ sudo /etc/init.d/renderd start Starting renderd (via systemctl): renderd.service. $ ps -ef | grep renderd rendera+ 37268 1 7 18:15 ? 00:00:00 /usr/local/bin/renderd -c /usr/local/etc/renderd.conf rendera+ 37574 28437 0 18:15 pts/0 00:00:00 grep --color=auto renderd $ sudo /etc/init.d/renderd stop Stopping renderd (via systemctl): renderd.service.
renderdが自動起動するように設定します。
$ sudo systemctl enable renderd Synchronizing state of renderd.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable renderd Created symlink /etc/systemd/system/multi-user.target.wants/renderd.service → /lib/systemd/system/renderd.service.
タイルを表示
renderdを起動しておきます。
$ sudo /etc/init.d/renderd start
タイルを表示するためのサンプルスクリプトが用意されているので、それをウェブサーバ経由で表示できるようコピーします。
コピー先のsample_leaflet.html内の「127.0.0.1」はサーバのドメインまたはIPアドレスに書き換えます。
表示する範囲は北緯40.36629度、東経49.83335度、ズームレベル18になっています。18くらいから始めるのが安全です。ズームレベルが小さいほどタイルのレンダリングに時間がかかるため、小さい値をいきなり指定してしまうと表示までに非常に時間がかかり、動作確認どころではなくなってしまいます。
$ sudo cp -p ~/src/mod_tile/extra/sample_leaflet.html /var/www/html/
<!DOCTYPE html> <html style="height:100%;margin:0;padding:0;"> <title>Leaflet page with OSM render server selection</title> <meta charset="utf-8"> <link rel="stylesheet" href="https://unpkg.com/leaflet@1.3/dist/leaflet.css" /> <script src="https://unpkg.com/leaflet@1.3/dist/leaflet.js"></script> <script src="https://unpkg.com/leaflet-hash@0.2.1/leaflet-hash.js"></script> <style type="text/css"> .leaflet-tile-container { pointer-events: auto; } </style> </head> <body style="height:100%;margin:0;padding:0;"> <div id="map" style="height:100%"></div> <script> //<![CDATA[ var map = L.map('map').setView([40.36629, 49.83335], 18); L.tileLayer('http://127.0.0.1/hot/{z}/{x}/{y}.png', { attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' }).addTo(map); var hash = L.hash(map) //]]> </script> </body> </html>
ログを確認できるようtailしておきます。
$ sudo tail -f /var/log/syslog | grep " TILE "
ブラウザからhttp://サーバのドメインまたはIPアドレス/hot/sample_leaflet.html
にアクセスすると地図が表示されます。

ズームアウトすると新たに地図がレンダリングされ以下のようにログが出力されます。
May 2 18:59:14 ubu-VirtualBox renderd[39884]: DEBUG: START TILE ajt 17 83672-83679 49440-49447, new metatile May 2 18:59:14 ubu-VirtualBox renderd[39884]: DEBUG: START TILE ajt 17 83680-83687 49440-49447, new metatile May 2 18:59:16 ubu-VirtualBox renderd[39884]: DEBUG: DONE TILE ajt 17 83672-83679 49440-49447 in 2.261 seconds May 2 18:59:16 ubu-VirtualBox renderd[39884]: DEBUG: DONE TILE ajt 17 83680-83687 49440-49447 in 2.516 seconds May 2 18:59:16 ubu-VirtualBox renderd[39884]: DEBUG: START TILE ajt 17 83680-83687 49448-49455, new metatile May 2 18:59:16 ubu-VirtualBox renderd[39884]: DEBUG: START TILE ajt 17 83672-83679 49448-49455, new metatile May 2 18:59:17 ubu-VirtualBox renderd[39884]: DEBUG: DONE TILE ajt 17 83680-83687 49448-49455 in 1.271 seconds May 2 18:59:17 ubu-VirtualBox renderd[39884]: DEBUG: DONE TILE ajt 17 83672-83679 49448-49455 in 1.516 seconds
補足
pgAdmin 4 から postgresql へ接続する
デフォルトの状態ではサーバ外部から直接DBにアクセスすることはできません。
DBの中身がどのようになったのかをpgAdminから見てみたいので、セキュリティ的に良くないですがとりあえず以下を設定します。
- /etc/postgresql/12/main/postgresql.conf
listen_addresses = '*'
- /etc/postgresql/12/main/pg_hba.conf
host all all 0.0.0.0/0 trust
- DBを再起動
sudo systemctl restart postgresql
DBのレコード数
以上の手順で構築を完了させた後、DBのレコード数は以下のようになっていました。アゼルバイジャンの地図データも含まれています。
$ sudo su - postgres $ psql gis psql (12.2 (Ubuntu 12.2-4)) Type "help" for help. gis=# select relname, n_live_tup from pg_stat_user_tables where schemaname='public'; relname | n_live_tup --------------------+------------ planet_osm_roads | 9904 planet_osm_nodes | 3002231 planet_osm_ways | 281242 spatial_ref_sys | 8500 planet_osm_polygon | 108666 planet_osm_point | 52271 planet_osm_line | 171374 planet_osm_rels | 2850 (8 rows)
データベースの構成は以下のようになっています。