Skip to content

Instantly share code, notes, and snippets.

@Synashida
Last active June 7, 2017 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Synashida/193eb3fc2e2f5107d73d3bdc79d09710 to your computer and use it in GitHub Desktop.
Save Synashida/193eb3fc2e2f5107d73d3bdc79d09710 to your computer and use it in GitHub Desktop.
OpenStreetMapのタイルサーバを構築する (CentOS7) ref: http://qiita.com/Syn256/items/633aef930455bfd4be0d
#[base]の最後に行追加
exclude=postgresql*
#[updates]の最後に行追加
exclude=postgresql*
#[extras]の最後に行追加
exclude=postgresql*
#SELINUX=enforcing
SELINUX=disabled
# 再起動する
reboot
getenforce
Disabledになっていることを確認
cd ~
wget http://download.geofabrik.de/asia/japan/kanto-latest.osm.bz2
# cacheはMB単位です。実メモリの75%くらいまでは指定しても大丈夫だと思います。
osm2pgsql -m -d gis kanto-latest.osm.bz2 -U postgres --cache 6000
yum -y install gdal-python gdal-devel icu libicu libicu-devel
yum -y install python-pip
pip install --upgrade pip
cd /usr/local/src
# v2.0系
wget https://github.com/downloads/mapnik/mapnik/mapnik-v2.0.2.tar.bz2
tar -jxvf mapnik-v2.0.2.tar.bz2
cd mapnik-v2.0.2
python scons/scons.py PG_CONFIG=/usr/pgsql-9.6/bin/pg_config
make install
ldconfig
ldconfig -v
ln -s /usr/local/lib64/libmapnik.so.2.0 /usr/lib64/libmapnik.so.2.0
cd /usr/local/src/mapnik-v2.0.2
git clone https://github.com/openstreetmap/mapnik-stylesheets.git
cd mapnik-stylesheets
wget http://tile.openstreetmap.org/world_boundaries-spherical.tgz
wget http://tile.openstreetmap.org/processed_p.tar.bz2
wget http://tile.openstreetmap.org/shoreline_300.tar.bz2
tar xzf world_boundaries-spherical.tgz
tar xjf processed_p.tar.bz2 -C world_boundaries
tar xjf shoreline_300.tar.bz2 -C world_boundaries
cd world_boundaries
wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places.zip
wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_boundary_lines_land.zip
unzip ne_10m_populated_places.zip
unzip ne_110m_admin_0_boundary_lines_land.zip
cd ../../mapnik-stylesheets
./generate_xml.py --host localhost --user postgres --dbname gis --symbols ./symbols/ --world_boundaries=./world_boundaries/ --accept-none
yum -y install httpd httpd-devel
mkdir -p /var/run/renderd
mkdir -p /var/lib/mod_tile
chmod 777 /var/run/renderd
chmod 777 /var/lib/mod_tile
vi /etc/renderd.conf
cd /usr/local/src
git clone https://github.com/openstreetmap/mod_tile.git
cd mod_tile
./autogen.sh
./configure --with-apxs=/usr/bin/apxs
make
make install
make install-mod_tile
ldconfig
vi /etc/httpd/conf/httpd.conf
# Include conf.modules.d/*.confの直下あたりに追記
LoadModule tile_module modules/mod_tile.so
LoadTileConfigFile /etc/renderd.conf
ModTileRenderdSocketName /var/run/renderd/renderd.sock
ModTileRequestTimeout 30
ModTileMissingRequestTimeout 30
cd /var/www/html
vi index.html
systemctl disabled firewalld
systemctl stop firewalld
systemctl enable httpd
systemctl start httpd
/usr/local/bin/renderd -f > /var/log/renderd.log 2> /var/log/renderd.log &
systemctl disabled firewalld
systemctl stop firewalld
systemctl enable httpd
systemctl start httpd
/usr/local/bin/renderd -f > /var/log/renderd.log 2> /var/log/renderd.log &
yum -y upgrade
yum -y install epel-release
yum -y install wget git freetype-devel libxml2-devel bzip2-devel freetype-devel libtool-ltdl-devel libpng-devel libtiff-devel libjpeg-devel gcc-c++ bzip2 bzip2-devel libcurl-devel libpng-devel libtiff-devel libtool-ltdl-devel pycairo-devel cairomm-devel libjpeg-turbo-devel zip unzip libtool autoconf automake
vi /etc/yum.repos.d/CentOS-Base.repo
cd /usr/local/src
wget https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
rpm -ivh pgdg-centos96-9.6-3.noarch.rpm
yum -y install postgresql96 postgresql96-contrib postgresql96-devel postgresql96-libs postgresql96-server
/usr/pgsql-9.6/bin/postgresql96-setup initdb
systemctl start postgresql-9.6
systemctl enable postgresql-9.6
vi /var/lib/pgsql/9.6/data/pg_hba.conf
systemctl restart postgresql-9.6
psql -Upostgres
yum -y install postgis2_96 postgis2_96-client postgis2_96-devel postgis2_96-utils ogr_fdw96 pgrouting_96
yum -y install cmake libpqxx libpqxx-devel boost boost-devel proj proj-devel proj-epsg lua lua-devel geos-devel protobuf-c protobuf-c-devel
cd /usr/local/src
git clone https://github.com/openstreetmap/osm2pgsql
cd osm2pgsql
mkdir build && cd build
cmake ..
make
make install
ldconfig
su postgres
createdb template_postgis
psql -d template_postgis -c "UPDATE pg_database SET datistemplate=true WHERE datname='template_postgis'"
psql -d template_postgis -f /usr/pgsql-9.6/share/contrib/postgis-2.3/postgis.sql
psql -d template_postgis -f /usr/pgsql-9.6/share/contrib/postgis-2.3/spatial_ref_sys.sql
psql -d template_postgis -f /usr/pgsql-9.6/share/contrib/postgis-2.3/postgis_comments.sql
psql -d template_postgis -f /usr/pgsql-9.6/share/contrib/postgis-2.3/rtpostgis.sql
psql -d template_postgis -f /usr/pgsql-9.6/share/contrib/postgis-2.3/raster_comments.sql
psql -d template_postgis -f /usr/pgsql-9.6/share/contrib/postgis-2.3/topology.sql
psql -d template_postgis -f /usr/pgsql-9.6/share/contrib/postgis-2.3/topology_comments.sql
createdb gis
psql -d gis -f /usr/pgsql-9.6/share/contrib/postgis-2.3/postgis.sql
psql -d gis -f /usr/pgsql-9.6/share/contrib/postgis-2.3/spatial_ref_sys.sql
<html>
<head>
<title>OpenLayers Demo</title>
<style type="text/css">
html, body, #basicMap {
width: 100%;
height: 100%;
margin: 0;
}
</style>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script>
function init() {
var options = {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
units: "m",
maxResolution: 156543.0339,
maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
20037508.34, 20037508.34),
numZoomLevels: 20,
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.Permalink(),
new OpenLayers.Control.ScaleLine(),
new OpenLayers.Control.MousePosition(),
new OpenLayers.Control.KeyboardDefaults()
]
};
map = new OpenLayers.Map("basicMap",options);
var newL = new OpenLayers.Layer.OSM("Default", "/osm_tiles2/${z}/${x}/${y}.png", {numZoomLevels: 19});
map.addLayer(newL);
map.zoomIn();
}
</script>
</head>
<body onload="init();">
<div id="basicMap"></div>
</body>
</html>
# peerをtrustに(開発用)
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
[renderd]
socketname=/var/run/renderd/renderd.sock
num_threads=8
tile_dir=/var/lib/mod_tile
stats_file=/var/run/renderd/renderd.stats
[mapnik]
plugins_dir=/usr/local/lib64/mapnik/input
font_dir=/usr/local/lib64/mapnik/fonts
font_dir_recurse=1
[default]
URI=/osm_tiles2/
XML=/usr/local/src/mapnik-stylesheets/osm.xml # mapnik-style内のosm.xmlを指定
HOST=localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment