Help us understand the problem. What is going on with this article?

CentOS7にOpenStreetMap入れる

More than 3 years have passed since last update.

本ポストは
 https://switch2osm.org/serving-tiles/manually-building-a-tile-server-14-04/
の焼き直しです。
とりあえず私はコレで動きましたってことで。

OSについて

CentOS7で適当にセットアップしました
※ユーザー名はosmとしています

必要なソフトウエア群をインストール

yum -y install epel-release
yum -y update
yum -y install postgresql-server postgresql-contrib postgresql-devel postgis postgis-utils git make automake gcc gcc-c++ libtool policycoreutils-python php-pgsql php php-pear php-pear-DB libpqxx-devel proj-epsg bzip2-devel bzip2 proj-devel geos-devel libxml2-devel protobuf-c-devel lua-devel boost-devel expat-devel cmake httpd-devel freetype-devel libtool-ltdl-devel libpng-devel libtiff-devel libicu-devel libjpeg-devel libcurl-devel cairo-devel pycairo-devel harfbuzz-devel ipa*fonts vlgothic*fonts unzip npm wget
npm -g install carto

DBのセットアップ

sudo postgresql-setup initdb
sudo systemctl enable postgresql
sudo systemctl start postgresql
sudo -u postgres createuser -s osm
sudo -u postgres createuser apache
sudo -u postgres createdb -E UTF8 -O osm gis
sudo -u postgres psql
\c gis
CREATE EXTENSION postgis;
ALTER TABLE geometry_columns OWNER TO osm;
ALTER TABLE spatial_ref_sys OWNER TO osm;
\q

nominatimのmake

su -
cd /srv
tar xvf /home/osm/Nominatim-2.4.0.tar.bz2
mv Nominatim-2.4.0 Nominatim && cd Nominatim && ./configure && make

vi setting/setting.php

下記に変えた

   @define('CONST_Database_DSN', 'pgsql://@/osm');
   @define('CONST_Database_Web_User', 'apache');
   @define('CONST_Postgresql_Version', '9.2');
   @define('CONST_Postgis_Version', '2.0');
   @define('CONST_Website_BaseURL', 'http://'.php_uname('n').'/osm/');

semanage fcontext -a -t httpd_sys_content_t "/srv/Nominatim/(website|lib|settings)(/.*)?"
semanage fcontext -a -t lib_t "/srv/Nominatim/module/nominatim.so"
restorecon -R -v /srv/Nominatim

osmユーザーで
nohup /srv/Nominatim/utils/setup.php --osm-file /tmp/japan-latest.osm.pbf --all --osm2pgsql-cache 6400 &

sudo mkdir -m 755 /var/www/html/osm
sudo chown osm /var/www/html/osm
/srv/Nominatim/utils/setup.php --create-website /var/www/html/osm

/etc/httpd/conf.d/osm.conf

  <Directory "/var/www/html/osm/">
    Options FollowSymLinks MultiViews
    AddType text/html   .php     
  </Directory>

systemctl restart httpd

各種ソフトをcloneしておく

git clone https://github.com/openstreetmap/osm2pgsql.git
git clone https://github.com/mapnik/mapnik
git clone https://github.com/openstreetmap/mod_tile.git

osm2pgsqlのmake

cd osm2pgsql
mkdir build && cd build && cmake .. && make && sudo make install

mapnikのmake

cd mapnik
git checkout -b 2.3 origin/2.3.x
python scons/scons.py configure INPUT_PLUGINS=all OPTIMIZATION=3 SYSTEM_FONTS=/usr/share/fonts/ PREFIX=/usr
sudo make install
sudo ldconfig

pythonにて

import mapnik

でエラーが出ないことを確認する

module_tileのmake

cd mod_tile
./autogen.sh
./configure
sudo make install
sudo make install-mod_tile
sudo ldconfig

vi /etc/httpd/conf/httpd.conf

LoadModule tile_module modules/mod_tile.so
LoadTileConfigFile /usr/local/etc/renderd.conf
ModTileRenderdSocketName /var/run/renderd/renderd.sock
ModTileRequestTimeout 0
ModTileMissingRequestTimeout 30

地図styleの作成

sudo mkdir -p /usr/local/share/maps/style
sudo chown osm /usr/local/share/maps/style
cd /usr/local/share/maps/style
mkdir ne_10m_populated_places_simple
cd ne_10m_populated_places_simple
unzip ~/ne_10m_populated_places_simple.zip
cd ..
unzip ~/master.zip
unzip ~/simplified-land-polygons-complete-3857.zip
unzip ~/land-polygons-split-3857.zip
mkdir osm-bright-master/shp
mv land-polygons-split-3857 osm-bright-master/shp/
mv simplified-land-polygons-complete-3857 osm-bright-master/shp/
mv ne_10m_populated_places_simple osm-bright-master/shp/

cd osm-bright-master/shp/land-polygons-split-3857
shapeindex land_polygons.shp
cd ../simplified-land-polygons-complete-3857/
shapeindex simplified_land_polygons.shp
cd ../..

vi osm-bright/osm-bright.osm2pgsql.mml

cp ~/configure.py .
./make.py
cd ../OSMBright/
carto project.mml > OSMBright.xml

OSMBright.xmlのフォントグループに

とかを追加する

vi /usr/loca/etc/re

XML=/usr/local/share/maps/style/OSMBright/OSMBright.xml
HOST=localhost

sudo mkdir -p /var/run/renderd
sudo chown osm /var/run/renderd
sudo mkdir -p /var/lib/mod_tile
sudo chown osm /var/lib/mod_tile

convert data

時間がかかるのでnohupで実行。
nohup time osm2pgsql --slim -S /usr/local/share/osm2pgsql/default.style -d gis -C 4000 /tmp/japan.osm.bz2 &

SELINUXを切る

setenforce 0
※気をつける

実行

renderd -f -c /usr/local/etc/renderd.conf

test

http://192.168.1.xxx/osm_tiles/0/0/0.png
http://192.168.1.xxx/osm/reverse.php?format=json&lat=35.905207&lon=139.620168

ubuntuの場合

yumじゃなくてapt-getで

sudo apt-get install libboost-all-dev subversion 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 libpng12-dev libtiff4-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 node-carto postgresql postgresql-contrib postgis postgresql-9.3-postgis-2.1

とかすればよい。

nkmrtkhd
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away