Postgresql+postgis安装部署

一、环境介绍
系统平台:CentOS release 6.6 (Final)

Postgresql:postgresql-9.6.6

二、安装过程

1.安装依赖包

yum -y install gcc*
yum -y install readline-devel
2.	源码包获取
wget http://ftp.postgresql.org/pub/source/v9.6.6/postgresql-9.6.6.tar.gz
3.	解压
tar zxf postgresql-9.6.6.tar.gz
5.创建用户、设置密码
adduser postgres
passwd postgres
6.	编译安装
cd postgresql-9.6.6
./configure --prefix=/home/postgres/pgsql
gmake
gmake install
7.设置环境变量
vim /etc/profile
添加一行
PATH=$PATH:$HOME/bin:/home/postgres/pgsql/bin
source /etc/profile
8.创建数据库目录
mkdir /home/postgres/pgsql/data
创建数据库操作历史记录文件
touch /home/postgres/pgsql/.pgsql_history
更改所属组
chown -R postgres:postgres /home/postgres/pgsql/*
9.切换到postgre用户,初始化数据库
su - postgres
/home/postgres/pgsql/bin/initdb -D /home/postgres/pgsql/data
exit
10.编译启动命令
从postgres解压后的文件夹里拷贝linux到/etc/init.d/
cp /root/postgresql-9.6.6/contrib/start-scripts/linux /etc/init.d/postgresql
vim /etc/init.d/postgresql
修改下面两行:
prefix=/home/postgres/pgsql
PGDATA="/home/postgres/pgsql/data"
保存退出
添加可执行权限
chmod +x /etc/init.d/postgresql
11.启动postgres数据库
/etc/init.d/postgresql start
12.测试使用
[root@MidApp ~]#su - postgres
[postgres@MidApp ~]$ psql
psql (9.6.6)
Type "help" for help.
postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.utf-8 | en_US.utf-8 | 
 template0 | postgres | UTF8     | en_US.utf-8 | en_US.utf-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.utf-8 | en_US.utf-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)
postgres=# \q


13.安装PostGis的前提库
1.Proj4
tar xzvf proj-4.7.0.tar.gz  
cd proj-4.7.0  
./configure --prefix=/home/users/yourname/local/proj-4.9.3 --without-jni
make  
make install  
 
2.GEOS
tar jxvf geos-3.4.2.tar.bz2  
cd geos-3.4.2  
./configure --prefix=/home/users/yourname/local/geos-3.6.2
make  
make install  
 

3.libxml2
tar xzvf libxml2-2.9.0.tar.gz  
cd libxml2-2.9.0  
./configure  
make  
make install  
 如果在libxml2的configure中出现的错误:cannot remove 'libtoolT':No such file or directory

解决方法:
修改configure文件
$vim configure

删除这一行:$RM "$cfgfile"
保存再运行 ./configure
安装默认路径/usr/local
安装后可能需要重新定义:
export LD_LIBRARY_PATH=/usr/local/lib
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

4.cmake-3.10.2
tar  -zxvf
./configure
make
make install

5.JsonCpp
sudo yum install cmake
git clone https://github.com/open-source-parsers/jsoncpp.git
cd jsoncpp
mkdir -p build/debug
cd build/debug
cmake -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_SHARED=OFF -G "Unix Makefiles" ../../
make
sudo make install

6.python-devel-2.7.5-16.el7.x86_64.rpm
7.json-c
tar xzvf json-c-json-c-0.11-20130402.tar.gz  
cd ./json-c-json-c-0.11-20130402  
./configure  
make  
make install  
 

8.GDAL
tar xzvf gdal-1.9.2.tar.gz  
cd gdal-1.9.2  
./configure --prefix=/home/users/yourname/local/gdal-2.2.1 --with-geos=/home/users/yourname/local/geos-3.6.2/bin/geos-config
make make install 
9.修改该etc下面ld.so.conf文件
/home/postgres/pgsql/lib
/home/users/yourname/local/gdal-2.2.1/lib

八、安装PostGis

Shell代码  收藏代码
tar zxvf postgis-2.1.2.tar.gz  
cd postgis-2.1.2  
./configure --with-pgconfig=/home/postgres/pgsql/bin/pg_config  --with-geosconfig=/home/users/yourname/local/geos-3.6.2/bin/geos-config  --with-projdir=/home/users/yourname/local/proj-4.9.3 --with-gdalconfig=/home/users/yourname/local/gdal-2.2.1/bin/gdal-config
make  
make install  
 

九、检查postgis安装是否正确

连接数据库执行:

select * from pg_available_extensions where name like 'postgis%';



 

有以上3条就说明PostGis安装成功了。

 

 十、为数据库增加PostGis插件

psql -d [yourdatabase] -c "CREATE EXTENSION postgis;"

psql -d [yourdatabase] -c "CREATE EXTENSION postgis_topology;"

 

 安装客户端插件(不必须):

psql -p 5432 -c "CREATE EXTENSION adminpack;"

 

十一、简单备份

备份

pg_dump dbname | gzip > filename.gz

还原

gunzip -c filename.gz | psql dbname

或者

cat filename.gz | gunzip | psql dbname

 

 分文件备份

pg_dump dbname | split -b 1m - filename

还原

cat filename* | psql dbname

http://blog.51cto.com/qingmiao/2046357
http://toplchx.iteye.com/blog/2090908
欢迎咨询QQ416534633

转载自:https://blog.csdn.net/u010073055/article/details/80578176

You may also like...