lundi 13 septembre 2010
PostgreSQL 8.4 / PostGIS 1.5.1 / PgRouting 1.0.3/ Osm2PgRouting sous Debian Lenny
Par david techer, lundi 13 septembre 2010 à 12:07 :: PostGIS et PostgreSQL
REMARQUE: Les paquets .deb fournis sous Debian Lenny n'étant pas très à jour, notamment pour PostGIS (comme pour des projets pour ffmpeg ou mplayer), et au lieu de me tourner vers les backports de Debian, je propose ici de recompiler les sources afin de valider une installation assez récente.
de recompiler0. Création d'un domU Debian Lenny sous Xen (facultatif)
Cette section est utile uniquement pour avoir une Debian Lenny vierge afin de valider l'installation. Si vous possédez une Debian Lenny fraà®chement installé, vous pouvez passer à la prochaine section. Les tests sont ici effectués sur une machine minimale avec juste 512M de RAMFichier xen-tools.conf
melina:~# grep -vE '^(#|$)' /etc/xen-tools/xen-tools.conf lvm = xen-vm install-method = debootstrap size = 20Gb # Disk image size. memory = 512Mb # Memory size swap = 128Mb # Swap size fs = ext3 # use the EXT3 filesystem for the disk image. dist = lenny # Default distribution to install. image = sparse # Specify sparse vs. full disk images. gateway = 192.168.2.253 netmask = 255.255.255.0 broadcast = 192.168.2.255 passwd = 1 accounts = 1 kernel = /boot/vmlinuz-`uname -r` initrd = /boot/initrd.img-`uname -r` arch = i386 mirror = http://ftp.us.debian.org/debian/ ext3_options = noatime,nodiratime,errors=remount-ro ext2_options = noatime,nodiratime,errors=remount-ro xfs_options = defaults reiser_options = defaults serial_device = hvc0 disk_device = xvda output = /etc/xen/machines extension = .cfg
Création du domU
melina:~# xen-create-image --force --hostname=melina-xen08 --ip=192.168.2.233 \ --mac=00:e3:ad:76:c7:8b --config=/etc/xen-tools/xen-tools.conf --role=udev General Information -------------------- Hostname : melina-xen08 Distribution : lenny Partitions : swap 128Mb (swap) / 20Gb (ext3) Image type : full Memory size : 512Mb Kernel path : /boot/vmlinuz-2.6.32-bpo.5-xen-686 Initrd path : /boot/initrd.img-2.6.32-bpo.5-xen-686 Networking Information ---------------------- IP Address 1 : 192.168.2.233 [MAC: 00:e3:ad:76:c7:8b] Netmask : 255.255.255.0 Broadcast : 192.168.2.255 Gateway : 192.168.2.253 Removing /dev/xen-vm/melina-xen08-swap - since we're forcing the install Removing /dev/xen-vm/melina-xen08-disk - since we're forcing the install Creating swap on /dev/xen-vm/melina-xen08-swap Done Creating ext3 filesystem on /dev/xen-vm/melina-xen08-disk Done Installation method: debootstrap Done Running hooks Done Role: udev File: /etc/xen-tools/role.d/udev Role script completed. Creating Xen configuration file Done Setting up root password Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully All done Logfile produced at: /var/log/xen-tools/melina-xen08.log
Démarrage du domU
On démarre en mode consolexm create /etc/xen/machines/melina-xen08.cfg -c
1. Répertoire pour les sources et paquets .deb requis
C'est dans le répertoire/opt/sources_gis
que je mettrais les sources téléchargées
melina-xen08:~# mkdir -pv /opt/sources_gis mkdir: création du répertoire `/opt/sources_gis'
apt-get install bzip2 gcc bison flex libreadline5-dev zlib1g-dev make g++ libbz2-dev python patch \ cmake libxml2-dev libexpat1-dev subversion-toolsavec
libexpat1-dev
,subversion-tools
: pour la compilation de osm2pgrouting- l
ibxml2-dev
pour la compilation de PostGIS
2. PostgreSQL 8.4.4
cd /opt/sources_gis/ wget http://wwwmaster.postgresql.org/redir/357/h/source/v8.4.4/postgresql-8.4.4.tar.bz2 tar xvjf postgresql-8.4.4.tar.bz2 cd postgresql-8.4.4 ./configure --prefix=/opt/postgresql/8.4 && make && make install echo /opt/postgresql/8.4/lib >> /etc/ld.so.conf.d/postgresql-8.4.conf
2. Geos 3.2
cd /opt/sources_gis/ wget http://download.osgeo.org/geos/geos-3.2.2.tar.bz2 tar xvjf geos-3.2.2.tar.bz2 cd geos-3.2.2 ./configure --prefix=/opt/postgresql/8.4 && make && make install
3. Proj 4.7.0
cd /opt/sources_gis/ wget http://download.osgeo.org/proj/proj-4.7.0.tar.gz tar xvzf proj-4.7.0.tar.gz cd proj-4.7.0 ./configure --prefix=/opt/postgresql/8.4 && make && make install
4. PostGIS 1.5.1
cd /opt/sources_gis wget http://postgis.org/download/postgis-1.5.1.tar.gz tar xvzf postgis-1.5.1.tar.gz cd postgis-1.5.1 ./configure --with-pgconfig=/opt/postgresql/8.4/bin/pg_config \ --with-geosconfig=/opt/postgresql/8.4/bin/geos-config --with-projdir=/opt/postgresql/8.4 make make installRemarque: Ici on aurait pu simplifier les options pour la compilation (configure) en mettant à jour la variable PATH
PATH=/opt/postgresql/8.4/bin:$PATHce qui éviterait de passer les différentes options à
configure
5. PgRouting 1.03
5.1 GAUL
cd /opt/sources_gis wget http://prdownloads.sourceforge.net/gaul/gaul-devel-0.1849-0.tar.gz?download tar xvzf gaul-devel-0.1849-0.tar.gz\?download cd gaul-devel-0.1849-0 ./configure --enable-slang=no make && make install
5.2 Cmake et BOOST
cd /opt/sources_gis wget http://kent.dl.sourceforge.net/sourceforge/boost/boost_1_33_1.tar.bz2 tar xvjf boost_1_33_1.tar.bz2 cd boost_1_33_1 ./configure make make install
5.3 CGAL
Il faut depuis un navigateur Web récupérer l'archive https://gforge.inria.fr/frs/download.php/10694/CGAL-3.3.1.tar.gz puis la copier sur la machine (par scp par exemple...)cd /opt/sources_gis tar xvzf CGAL-3.3.1.tar.gz cd CGAL-3.3.1 ./install_cgal --prefix=/usr/local/cgal --with-boost=n --without-autofind -ni /usr/bin/g++
5.4 PGROUTING
Pour la version 8.4 de PostgreSQL, il est nécessaire de patcher pgRouting. J'ai fait un patch (assez rapide pas trop soigné) disponible à http://www.davidgis.fr/download/patch-postgresql-8.4.pgroutingcd /opt/sources_gis wget http://files.postlbs.org/pgrouting/source/pgRouting-1.03.tgz wget http://www.davidgis.fr/download/patch-postgresql-8.4.pgrouting tar xvzf pgRouting-1.03.tgz cd pgrouting patch -N -p1 < ../patch-postgresql-8.4.pgrouting patching file extra/driving_distance/src/alpha.c patching file extra/driving_distance/src/drivedist.c patching file extra/driving_distance/src/alpha.c Reversed (or previously applied) patch detected! Skipping patch. 1 out of 1 hunk ignored -- saving rejects to file extra/driving_distance/src/alpha.c.rej patching file core/src/dijkstra.c patching file core/src/astar.c patching file core/src/shooting_star.c ln -s /usr/local/include/boost-1_33_1/boost /usr/include/boost cmake -DWITH_TSP=ON -DWITH_DD=ON -DPOSTGRESQL_LIBRARIES=/opt/postgresql/8.4/lib/libpq.so \ -DPOSTGRESQL_INCLUDE_DIR=/opt/postgresql/8.4/include/server \ -DBoost_INCLUDE_DIR=/usr/include/boost/ \ -DCGAL_INCLUDE_DIR=/usr/local/cgal/include -DCGAL_LIBRARIES=/usr/local/cgal/lib/libCGAL.so \ -DGAUL_INCLUDE_DIR=/usr/local/include -DGAUL_LIBRARIES=/usr/local/lib/libgaul.so .so -DGAUL_UTIL_LIBRARIES=/usr/local/lib/libgaul_util.so && make -- The C compiler identification is GNU -- The CXX compiler identification is GNU -- Check for working C compiler: /usr/bin/gcc -- Check for working C compiler: /usr/bin/gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - 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 Boost headers were found here: /usr/local/include/boost-1_33_1/boost/ Output directory for libraries is set to /opt/postgresql/8.4/lib -- Found PGROUTING_CORE core: /opt/sources_gis/pgrouting/core/src Installation directory for libraries is set to /opt/postgresql/8.4/lib and for SQL files is set to /usr/share/postlbs Installation directory for libraries is set to /opt/postgresql/8.4/lib -- Configuring done -- Generating done -- Build files have been written to: /opt/sources_gis/pgrouting Scanning dependencies of target routing_tsp [ 8%] Building C object extra/tsp/src/CMakeFiles/routing_tsp.dir/tsp.o [ 16%] Building CXX object extra/tsp/src/CMakeFiles/routing_tsp.dir/tsp_solver.o Linking CXX shared library ../../../lib/librouting_tsp.so [ 16%] Built target routing_tsp Scanning dependencies of target routing_dd [ 25%] Building C object extra/driving_distance/src/CMakeFiles/routing_dd.dir/alpha.o [ 33%] Building CXX object extra/driving_distance/src/CMakeFiles/routing_dd.dir/alpha_drivedist.o [ 41%] Building CXX object extra/driving_distance/src/CMakeFiles/routing_dd.dir/boost_drivedist.o [ 50%] Building C object extra/driving_distance/src/CMakeFiles/routing_dd.dir/drivedist.o Linking CXX shared library ../../../lib/librouting_dd.so [ 50%] Built target routing_dd Scanning dependencies of target routing [ 58%] Building C object core/src/CMakeFiles/routing.dir/dijkstra.o [ 66%] Building C object core/src/CMakeFiles/routing.dir/astar.o [ 75%] Building C object core/src/CMakeFiles/routing.dir/shooting_star.o [ 83%] Building CXX object core/src/CMakeFiles/routing.dir/boost_wrapper.o [ 91%] Building CXX object core/src/CMakeFiles/routing.dir/astar_boost_wrapper.o [100%] Building CXX object core/src/CMakeFiles/routing.dir/shooting_star_boost_wrapper.o Linking CXX shared library ../../lib/librouting.so [100%] Built target routing melina-xen08:/opt/sources_gis/pgrouting# echo /usr/local/cgal/lib/ >> /etc/ld.so.conf.d/cgal.conf melina-xen08:/opt/sources_gis/pgrouting# ldconfig melina-xen08:/opt/sources_gis/pgrouting# make install [ 16%] Built target routing_tsp [ 50%] Built target routing_dd [100%] Built target routing Install the project... -- Install configuration: "" -- Installing: /opt/postgresql/8.4/lib/librouting.so -- Up-to-date: /usr/share/postlbs/routing_core.sql -- Up-to-date: /usr/share/postlbs/routing_core_wrappers.sql -- Up-to-date: /usr/share/postlbs/routing_topology.sql -- Installing: /opt/postgresql/8.4/lib/librouting_tsp.so -- Up-to-date: /usr/share/postlbs/routing_tsp.sql -- Up-to-date: /usr/share/postlbs/routing_tsp_wrappers.sql -- Installing: /opt/postgresql/8.4/lib/librouting_dd.so -- Up-to-date: /usr/share/postlbs/routing_dd.sql -- Up-to-date: /usr/share/postlbs/routing_dd_wrappers.sql
5.5 OSM2PGROUTING
Ici on pourra consulter le détail de cet outil à http://pgrouting.postlbs.org/wiki/tools/osm2pgroutingcd /opt/sources_gis/ svn checkout http://pgrouting.postlbs.org/svn/pgrouting/tools/osm2pgrouting/trunk osm2pgrouting cd osm2pgrouting/Il faut ensuite adapter le script Makefile. Voici un petit facile patch pour ce Makefile
melina-xen13:/opt/sources_gis/osm2pgrouting# cat ../patch.Makefile.osm2pgrouting --- osm2pgrouting/Makefile 2010-09-17 22:39:46.000000000 +0000 +++ osm2pgrouting_orig/Makefile 2010-09-17 22:39:16.000000000 +0000 @@ -1,17 +1,18 @@ CC = g++ +POSTGRESQL_DIR = /opt/postgresql/8.4 SRC = src/Export2DB.cpp src/math_functions.cpp src/Node.cpp src/OSMDocumentParserCallback.cpp src/Way.cpp src/OSMDocument.cpp src/Type.cpp src/Class.cpp src/Configuration.cpp src/ConfigurationParserCallback.cpp DEPS = src/XMLParser.cpp -INC = -I./ -Isrc -I/usr/include/pgsql -I/usr/include/postgresql +INC = -I./ -Isrc -I$(POSTGRESQL_DIR)/include -I/usr/include/boost MAIN = src/osm2pgrouting.cpp all: $(CC) -c $(SRC) $(INC) -ggdb3 $(CC) -c $(DEPS) $(INC) -ggdb3 - $(CC) -o osm2pgrouting $(MAIN) *.o $(INC) -lexpat -ggdb3 -lpq + $(CC) -o osm2pgrouting $(MAIN) *.o $(INC) -lexpat -ggdb3 -L$(POSTGRESQL_DIR)/lib -lpq rm *.o clean: rm osm2pgroutingOn modifie directement le Makefile ou on applique le patch
patch -p1 < ../patch.Makefile.osm2pgrouting make
6. Mise en place de la base de données et tests
6.1 Création de l'utilisateur postgres
adduser postgresOn ajoute ensuite ces deux lignes dans le fichier
/home/postgres/.bashrc
export PATH=/opt/postgresql/8.4/bin:$PATH export PGDATA=/opt/postgresql/data
Création de la base de données testgis
melina-xen08:~# chmod 777 -R /opt/postgresql/ melina-xen08:~# su postgres postgres@melina-xen08:/root$ initdb -A trust 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 fr_FR.UTF-8. The default database encoding has accordingly been set to UTF8. The default text search configuration will be set to "french". creating directory /opt/postgresql/data ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 28MB creating configuration files ... ok creating template1 database in /opt/postgresql/data/base/1 ... ok initializing pg_authid ... ok initializing dependencies ... ok creating system views ... ok loading system objects' descriptions ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok creating information schema ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... ok Success. You can now start the database server using: postgres -D /opt/postgresql/data or pg_ctl -D /opt/postgresql/data -l logfile startOn démarre le serveur
postgres@melina-xen08:~$ pg_ctl start server starting postgres@melina-xen08:~$ LOG: database system was shut down at 2010-09-13 13:54:50 UTC LOG: database system is ready to accept connections LOG: autovacuum launcher started postgres@melina-xen08:~$On crée la base
createdb testgis
6.3 Ajouts des fonctionnalités de PostGIS et de PgRouting
createlang plpgsql testgis psql -d testgis -f /opt/postgresql/8.4/share/contrib/postgis-1.5/postgis.sql psql -d testgis -f /opt/postgresql/8.4/share/contrib/postgis-1.5/spatial_ref_sys.sql psql -d testgis -f /usr/share/postlbs/routing_core.sql psql -d testgis -f /usr/share/postlbs/routing_core_wrappers.sql psql -d testgis -f /usr/share/postlbs/routing_tsp.sql psql -d testgis -f /usr/share/postlbs/routing_tsp_wrappers.sql psql -d testgis -f /usr/share/postlbs/routing_dd.sql psql -d testgis -f /usr/share/postlbs/routing_dd_wrappers.sql psql -d testgis -f /usr/share/postlbs/routing_topology.sql