`
hulianwang2014
  • 浏览: 690575 次
文章分类
社区版块
存档分类
最新评论
  • bcworld: 排版成这样,一点看的欲望都没有了
    jfinal

CentOS安装PostGIS

 
阅读更多
CentOS安装PostGIS最方便的方法是用PostgreSQL源加上EPEL源,直接yum安装,无痛解决依赖问题(源码安装时遇到的依赖问题会让人抓狂的)。

系统环境:
CentOS 6.4 x64

要求:
PostgreSQL安装到 /postgresql 目录,数据目录为 /postgresql/data。

1.使用PostgreSQL源
参考http://wiki.postgresql.org/wiki/YUM_Installation
http://yum.postgresql.org/repopackages.php页面选择相应系统的rpm包,CentOS 6.x 可直接 wget http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm
rpm -ivh pgdg-centos93-9.3-1.noarch.rpm
vim /etc/yum.repos.d/CentOS-Base.repo
在 [base] 和 [updates] 区域中加入一行
exclude=postgresql*

yum makecache

2.使用EPEL源
由于PostGIS所依赖的包比较多,有些在CentOS官方源中没有,所以需要使用EPEL源。
具体步骤参考上一篇blog。

3.安装PostgreSQL
yum list postgres*

由于yum安装无法指定软件安装目录,这里使用软链接来实现指定PostgreSQL安装目录。
yum安装PostgreSQL的默认路径为/usr/pgsql-9.3
mkdir /postgresql
mkdir /postgresql/data
ln -s /postgresql /usr/pgsql-9.3
yum install postgresql93-server

4.配置PostgreSQL参数,初始化数据库
vim ~/.bash_profile
PGHOME=/postgresql
PGDATA=/postgresql/data
PGPORT=5432
export PGHOME PGDATA PGPORT

$PGHOME/bin/initdb -D $PGDATA

5.安装PostGIS
yum list postgis*

yum install postgis2_93.x86_64 postgis2_93-client.x86_64pos postgis2_93-devel.x86_64 postgis2_93-docs.x86_64 postgis2_93-utils.x86_64

6.修改pg_hba.conf和postgresql.conf配置

7.加载PostGIS插件
查看PostGIS相关文件

# ll $PGHOME/share/extension/
总用量 25936
-rw-r--r--. 1 root root 332 10月 9 17:11 plpgsql--1.0.sql
-rw-r--r--. 1 root root 179 10月 9 17:11 plpgsql.control
-rw-r--r--. 1 root root 381 10月 9 17:11 plpgsql--unpackaged--1.0.sql
-rw-r--r--. 1 root root 597783 11月 9 04:02 postgis--2.0.0--2.1.1.sql
-rw-r--r--. 1 root root 597783 11月 9 04:02 postgis--2.0.1--2.1.1.sql
-rw-r--r--. 1 root root 597783 11月 9 04:02 postgis--2.0.2--2.1.1.sql
-rw-r--r--. 1 root root 597783 11月 9 04:02 postgis--2.0.3--2.1.1.sql
-rw-r--r--. 1 root root 597783 11月 9 04:02 postgis--2.0.4--2.1.1.sql
-rw-r--r--. 1 root root 597783 11月 9 04:02 postgis--2.1.0--2.1.1.sql
-rw-r--r--. 1 root root 597783 11月 9 04:02 postgis--2.1.0rc1--2.1.1.sql
-rw-r--r--. 1 root root 597783 11月 9 04:02 postgis--2.1.0rc2--2.1.1.sql
-rw-r--r--. 1 root root 597783 11月 9 04:02 postgis--2.1.0rc3--2.1.1.sql
-rw-r--r--. 1 root root 597783 11月 9 04:02 postgis--2.1.1--2.1.1next.sql
-rw-r--r--. 1 root root 597783 11月 9 04:02 postgis--2.1.1next--2.1.1.sql
-rw-r--r--. 1 root root 4211501 11月 9 04:02 postgis--2.1.1.sql
-rw-r--r--. 1 root root 185 11月 9 04:02 postgis.control
-rw-r--r--. 1 root root 979837 11月 9 04:02 postgis_tiger_geocoder--2.0.0--2.1.1.sql
-rw-r--r--. 1 root root 979837 11月 9 04:02 postgis_tiger_geocoder--2.0.1--2.1.1.sql
-rw-r--r--. 1 root root 979837 11月 9 04:02 postgis_tiger_geocoder--2.0.2--2.1.1.sql
-rw-r--r--. 1 root root 979837 11月 9 04:02 postgis_tiger_geocoder--2.0.3--2.1.1.sql
-rw-r--r--. 1 root root 979837 11月 9 04:02 postgis_tiger_geocoder--2.0.4--2.1.1.sql
-rw-r--r--. 1 root root 979837 11月 9 04:02 postgis_tiger_geocoder--2.1.0--2.1.1.sql
-rw-r--r--. 1 root root 979837 11月 9 04:02 postgis_tiger_geocoder--2.1.0rc1--2.1.1.sql
-rw-r--r--. 1 root root 979837 11月 9 04:02 postgis_tiger_geocoder--2.1.0rc2--2.1.1.sql
-rw-r--r--. 1 root root 979837 11月 9 04:02 postgis_tiger_geocoder--2.1.0rc3--2.1.1.sql
-rw-r--r--. 1 root root 979837 11月 9 04:02 postgis_tiger_geocoder--2.1.1--2.1.1next.sql
-rw-r--r--. 1 root root 979837 11月 9 04:02 postgis_tiger_geocoder--2.1.1next--2.1.1.sql
-rw-r--r--. 1 root root 1073180 11月 9 04:02 postgis_tiger_geocoder--2.1.1.sql
-rw-r--r--. 1 root root 193 11月 9 04:02 postgis_tiger_geocoder.control
-rw-r--r--. 1 root root 8558 11月 9 04:02 postgis_tiger_geocoder--unpackaged--2.1.1.sql
-rw-r--r--. 1 root root 309299 11月 9 04:02 postgis_topology--2.0.0--2.1.1.sql
-rw-r--r--. 1 root root 309299 11月 9 04:02 postgis_topology--2.0.1--2.1.1.sql
-rw-r--r--. 1 root root 309299 11月 9 04:02 postgis_topology--2.0.2--2.1.1.sql
-rw-r--r--. 1 root root 309299 11月 9 04:02 postgis_topology--2.0.3--2.1.1.sql
-rw-r--r--. 1 root root 309299 11月 9 04:02 postgis_topology--2.0.4--2.1.1.sql
-rw-r--r--. 1 root root 309299 11月 9 04:02 postgis_topology--2.1.0--2.1.1.sql
-rw-r--r--. 1 root root 309299 11月 9 04:02 postgis_topology--2.1.0rc1--2.1.1.sql
-rw-r--r--. 1 root root 309299 11月 9 04:02 postgis_topology--2.1.0rc2--2.1.1.sql
-rw-r--r--. 1 root root 309299 11月 9 04:02 postgis_topology--2.1.0rc3--2.1.1.sql
-rw-r--r--. 1 root root 309299 11月 9 04:02 postgis_topology--2.1.1--2.1.1next.sql
-rw-r--r--. 1 root root 309299 11月 9 04:02 postgis_topology--2.1.1next--2.1.1.sql
-rw-r--r--. 1 root root 303625 11月 9 04:02 postgis_topology--2.1.1.sql
-rw-r--r--. 1 root root 169 11月 9 04:02 postgis_topology.control
-rw-r--r--. 1 root root 9775 11月 9 04:02 postgis_topology--unpackaged--2.1.1.sql
-rw-r--r--. 1 root root 93819 11月 9 04:02 postgis--unpackaged--2.1.1.sql

# ll $PGHOME/share/contrib/postgis-2.1/
总用量 5972
-rw-r--r--. 1 root root 1214 11月 9 04:02 legacy_gist.sql
-rw-r--r--. 1 root root 2556 11月 9 04:02 legacy_minimal.sql
-rw-r--r--. 1 root root 54475 11月 9 04:02 legacy.sql
-rw-r--r--. 1 root root 65668 11月 9 04:02 postgis_comments.sql
-rwxr-xr-x. 1 root root 147813 11月 9 04:02 postgis_restore.pl
-rw-r--r--. 1 root root 206659 11月 9 04:02 postgis.sql
-rw-r--r--. 1 root root 161237 11月 9 04:02 postgis_upgrade_20_21.sql
-rw-r--r--. 1 root root 161237 11月 9 04:02 postgis_upgrade_21_minor.sql
-rw-r--r--. 1 root root 67301 11月 9 04:02 raster_comments.sql
-rw-r--r--. 1 root root 5775 11月 9 04:02 rtpostgis_legacy.sql
-rw-r--r--. 1 root root 269778 11月 9 04:02 rtpostgis.sql
-rw-r--r--. 1 root root 299364 11月 9 04:02 rtpostgis_upgrade_20_21.sql
-rw-r--r--. 1 root root 299364 11月 9 04:02 rtpostgis_upgrade_21_minor.sql
-rw-r--r--. 1 root root 3593962 11月 9 04:02 spatial_ref_sys.sql
-rw-r--r--. 1 root root 14395 11月 9 04:02 topology_comments.sql
-rw-r--r--. 1 root root 289150 11月 9 04:02 topology.sql
-rw-r--r--. 1 root root 289010 11月 9 04:02 topology_upgrade_21_minor.sql
-rw-r--r--. 1 root root 14401 11月 9 04:02 uninstall_legacy.sql
-rw-r--r--. 1 root root 38592 11月 9 04:02 uninstall_postgis.sql
-rw-r--r--. 1 root root 68405 11月 9 04:02 uninstall_rtpostgis.sql
-rw-r--r--. 1 root root 1451 11月 9 04:02 uninstall_sfcgal.sql
-rw-r--r--. 1 root root 10684 11月 9 04:02 uninstall_topology.sql



加载PostGIS插件
# psql -d postgres -U postgres
psql (9.3.1)
输入 "help" 来获取帮助信息.

postgres=# \l
资料库列表
名称 | 拥有者 | 字元编码 | 校对规则 | Ctype | 存取权限
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 |
template0 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 行记录)

postgres=# create database postgis ;
CREATE DATABASE
postgres=# \c postgis
您现在已经连线到数据库 "postgis",用户 "postgres".
postgis=# select * from pg_extension;
extname | extowner | extnamespace | extrelocatable | extversion | extconfig | extcondition
---------+----------+--------------+----------------+------------+-----------+--------------
plpgsql | 10 | 11 | f | 1.0 | |
(1 行记录)

postgis=# create extension postgis;
CREATE EXTENSION
postgis=# \dt
关联列表
架构模式 | 名称 | 型别 | 拥有者
----------+-----------------+--------+----------
public | spatial_ref_sys | 资料表 | postgres
(1 行记录)

postgis=# select count(*) from spatial_ref_sys ;
count
-------
3911
(1 行记录)

postgis=# \dn
架构模式列表
名称 | 拥有者
--------+----------
public | postgres
(1 行记录)

postgis=# create extension postgis_topology;
CREATE EXTENSION
postgis=# \dn
架构模式列表
名称 | 拥有者
----------+----------
public | postgres
topology | postgres
(2 行记录)

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics