软件包下载

wgethttp://download.osgeo.org/postgis/source/postgis-2.2.2.tar.gz

wgethttps://ftp.postgresql.org/pub/source/v9.4.8/postgresql-9.4.8.tar.gz

wgethttp://download.osgeo.org/gdal/2.0.0/gdal-2.0.0.tar.gz

wgethttp://download.osgeo.org/geos/geos-3.5.0.tar.bz2

 相关依赖包安装

#yum install -y gcc gdb strace gcc-c++ autoconf libjpeglibjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-develzlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel

#yum install ncurses ncurses-devel curl curl-devel e2fsprogs patche2fsprogs-devel krb5-devel libidn libidn-devel openldap-devel nss_ldapopenldap-clients openldap-servers libevent-devel libevent uuid-devel uuidmysql-devel

#yum install make cmake lrzsz perl perl-ExtUtils-Embed readlinereadline-devl python-devel proj proj-devel screen gmp gmp-devel mpfr mpfr-develdevtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++ boost boost-develcmake3 cmake3-gui cmake3-data

--downloadonly--downloaddir=/mnt/yilaibao -y

安装部署

 postgresql安装

 

创建软件包存放目录:

#mkdir  /data

进入目录按上面的链接下载软件包

#cd  /data

解压安装包

#tar zxvf postgresql-9.4.8

#cd postgresql-9.4.8

#./configure --prefix=/usr/local/pgsql9_4_8  --with-python --with-perl

#make

#make install

添加数据库账户

#adduser postgres

添加数据存放路径

#mkdir  -p /usr/local/pgsql9_4_8/data

#chown postgres /usr/local/pgsql9_4_8/datachown postgres /usr/local chmod 777 /usr/local/pgsql9_4_8/

chown postgres /usr/local/pgsql9_4_8/bin

进入普通账号

su - postgres

/usr/local/pgsql9_4_8/bin/initdb -D /usr/local/pgsql9_4_8/data

 

启动

/usr/local/pgsql9_4_8/bin/postgres -D /usr/local/pgsql9_4_8/data>logfile 2>&1 &

停止

cd /usr/local/pgsql9_4_8/bin/

./pg_ctl stop -D /usr/local/pgsql9_4_8/data/ -m {smart| fast}

postgres账号下添加环境变量

export LD_LIBRARY_PATH=/usr/local/pgsql9_4_8/lib

export PATH=/usr/local/pgsql9_4_8/bin:$PATH

---------------------------------------------------------------------------------------------------------------------

//注意:永久添加方法

进入普通账户:su - postgres

#vi ~/.bash_profile

export LD_LIBRARY_PATH=/usr/local/pgsql9_4_8/lib

export PATH=/usr/local/pgsql9_4_8/bin:$PATH

查看环境变量#echo $PATH

保存退出,这样既可永久添加。

 ---------------------------------------------------------------------------------------------------------------

注意在root下要再添加一次环境变量,最好上述的环境变量在普通账户和root账户下都添加。

退出普通账号安装fuzzystrmatch扩展包

cd contrib

make

make install

安装gdalgeos

cd /data

tar zxvf gdal-2.0.0.tar.gz

cd gdal-2.0.0

./configure --prefix=/usr/local/gdal --with-xml2=/usr/bin/xml2-config --with-static-proj4=/usr/bin/proj  (编译安装proj

 

make

make install

 

cd /data

tar jxvf geos-3.5.0.tar.bz2

cd geos-3.5.0

./configure --prefix=/usr/local/geos3

make

make install

 

vi /etc/ld.so.conf

/usr/local/pgsql9_4_8/lib(根据自己安装的路径改动)

/usr/local/gdal/lib  (根据自己安装的路径改动)

/usr/local/geos3/lib (根据自己安装的路径改动)

/usr/local/lib

PG数据库部署_第1张图片

等最后安装好后要以 root 的身份运行 #ldconfig

 

 postgis安装

#cd /data

#tar zxvfpostgis-2.2.2.tar.gz

# cdpostgis-2.2.2/

./configure--with-pgconfig=/usr/local/pgsql9_4_8/bin/pg_config--with-gdalconfig=/usr/local/gdal/bin/gdal-config--with-geosconfig=/usr/local/geos3/bin/geos-config

 

make

 

cd extensions

cd postgis

make clean

make

make install

 

cd ..

cdpostgis_topology

make clean

make

make install

 

cd ..

cd postgis_tiger_geocoder

make clean

make

make install

 

cd ../..

make install

 

进入控制台执行以下语句:

CREATE EXTENSIONpostgis;

CREATE EXTENSIONfuzzystrmatch;

CREATE EXTENSIONpostgis_tiger_geocoder;

CREATE EXTENSIONpostgis_topology;

pgrouting安装

yum -y install bzip2

cd /data

tar xvJf CGAL-4.8.1.tar.xz

cd CGAL-4.8.1

yum install gmp gmp-devel

yum install mpfr mpfr-devel

cmake .

make

make install

 

wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O/etc/yum.repos.d/devtools-2.repo

yum install devtoolset-2-gcc devtoolset-2-binutilsdevtoolset-2-gcc-c++

PATH=/opt/rh/devtoolset-2/root/usr/bin/:$PATH

 

cd ..

tar zxvf pgrouting-2.2.0.tar.gz

cd pgrouting-pgrouting-2.2.0/

mkdir build

cd build/

cmake3 ..

make

make install

 

su - postgres

psql

CREATE EXTENSION pgrouting;

postgres用户设置密码:

alter user postgres with password 'postgres';

test!@#

Pg数据库设置远程连接:

1、#cd /usr/local/pgsql9_4_8/data

 #vi pg_hba.conf

PG数据库部署_第2张图片

2、#vipostgresql.conf

PG数据库部署_第3张图片

3、设置防火墙(在root下)

#vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT

4、停止,再启动(在postgres账户)

$pg_ctl stop -D /usr/local/pgsql9_4_8/data/ -m  fast

$/usr/local/pgsql9_4_8/bin/postgres -D /usr/local/pgsql9_4_8/data>logfile 2>&1 &

 

Pg数据库设置开机自启动:

 

 

设置PostgreSQL开机自启动

PostgreSQL的开机自启动脚本位于PostgreSQL源码目录的contrib/start-scripts路径下

wKiom1hiLfKg87NDAAAPK2tWRZg691.png-wh_50


linux文件即为linux系统上的启动脚本

1)修改linux文件属性,添加X属性

#chmod a+x linux

2) 复制linux文件到/etc/init.d目录下,更名为postgresql

#cp linux/etc/init.d/postgresql

3)修改/etc/init.d/postgresql文件的两个变量

prefix设置为postgresql的安装路径:/opt/pgsql-9.1.2

PGDATA设置为postgresql的数据目录路径:

wKiom1hiLfLCOClJAAAPFgHXRFo475.png-wh_50


4) 执行service postgresqlstart,就可以启动PostgreSQL服务

#service postgresqlstart

 

wKioL1hiLfOhbkJFAAAWI_9jhVk731.png-wh_50


5)设置postgresql服务开机自启动

#chkconfig --addpostgresql

执行上面的命令,就可以实现postgresql服务的开机自启动。

 

 注意事项

在部署前请检查系统是否安装了postgresqlpostgis等上述软件,如果有请先卸载、不同Linux发行版本在安装过程中可能会遇到其他软件依赖关系需要根据安装过程中提示的问题解决。