`
kabuto_v
  • 浏览: 12647 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

在linux(centos)下安装postgresql+postGSI(亲测可行)

阅读更多

http://www.postgresonline.com/journal/archives/362-An-almost-idiots-guide-to-install-PostgreSQL-9.5,-PostGIS-2.2-and-pgRouting-2.1.0-with-Yum.html

 

如果要安装postgrtSql

 

第一步 :

确定你的操作系统,是red hat系列还是,dabin系统,还是其他什么发行版的linux。

uname -a 通过这个命令看linux发型版本

lsb_release -a 其实用命令这个更加好

结果如下

 

LSB Version::base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch

Distributor ID:CentOS

Description:CentOS release 6.5 (Final)

Release:6.5

Codename:Final

 

确定要装什么版本的postgerSql 以后就开始装了。

 

http://yum.postgresql.org/repopackages.php在这个网站上面下载,相应的rpm包。

rpm -ivh (你下载的RPM包)

 

 

yum install postgresql9x postgresql9x-server postgresql9x-libs postgresql9x-contrib postgresql9x-deve

然后输入这些命令下载相关服务.

x是用来替换你想要的版本的94,95....之类的。替换一个数字就好了

 

#=================================================================

中间的这一段是用来给:想在同一台服务器上安装不同版本的postgresql看的。如果你只是想安装一个版本的就可以跳过了。

 

首先变成root 

su root
vi /etc/sysconfig/pgsql/postgresql-9.5# 解析一下,这个是系统的配置文件
优先级很高,里面的配置的信息是会在后面的安装过程中起关键作用的。如果你还没安装过
postgreSql 的话,这个文件是不存在的,当然vi会帮里创建的。里面是没有内容的。
你可以输入一下信息:
PGPORT=5440 #设定一个端口不是5432
PGDATA=/pgdata95 #设定初始化数据库所在路径。安装完成后核心的配置文件将放在这个目录中。
输入:wq保存退出。
#======================================================================
在postgresql安装的过程中,会自动帮你创建一个用户。
postgres
你要为他设置一个密码:sudo passwd postgres
现在重启服务:
su root
service postgresql-9.5 initdb 

If you get an error:

The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
 
如果不行就
/usr/pgsql-9.5/bin/postgresql95-setup initdb #初始化数据库
service postgresql-9.5 start #启动服务
chkconfig --list #(to see list of services)
chkconfig postgresql-9.5 on #(to have start on bootup)#设置开机启动
经过以上的初始化过程以后。
默认情况下。
数据文件会在/var/lib/pgsql/9.5/data (里面包含控制postgresql的配置文件)
扩展的文件会在这里:/usr/pgsql-9.5/share/extension/ (这个我也不知道做什么的)
二进制文件/usr/pgsql-9.5/bin.
 
Installing adminpack
To install the adminpack useful for viewing logs and editing 
postgresql.conf from the comfort of PgAdmin, don't forget to install the
 admin pack。
一个方便配置的工具(其实我也没用过,可能用过也不知道)
su postgres
cd ~/
/usr/pgsql-9.5/bin/psql -p 5432(这个是默认端口) -c "CREATE EXTENSION adminpack;"
接下来就要安装这个吊炸天的软件了,空间数据库扩展。PostGIS 
sudo yum install postgis2_9x #x要替换为你要的版本。
如果出现这些错误了
--> Finished Dependency Resolution
Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg95)
           Requires: libdapclient.so.3()(64bit)
Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg95)
           Requires: libdap.so.11()(64bit)
Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg95)
           Requires: libspatialite.so.2()(64bit)
Error: Package: postgis2_95-2.2.0-1.rhel6.x86_64 (pgdg95)
           Requires: hdf5
Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg95)
           Requires: libarmadillo.so.4()(64bit)
Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg95)
           Requires: libCharLS.so.1()(64bit)
Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg95)
           Requires: libgta.so.0()(64bit)
Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg95)
           Requires: libgeotiff.so.1.2()(64bit)
Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg95)
           Requires: libfreexl.so.1()(64bit)
Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg95)
           Requires: libdapserver.so.7()(64bit)
Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg95)
           Requires: libcfitsio.so.0()(64bit)
Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg95)
           Requires: libnetcdf.so.6()(64bit)
Error: Package: gdal-libs-1.9.2-7.rhel6.x86_64 (pgdg95)
           Requires: libhdf5.so.6()(64bit)
尝试:yum -y install epel-release
如果还不行就照着以下方法进行。

  • If that doesn't work, you might have to find the explicit epel repo

    For CentOS 6, RHEL 6 64-bit/32-bit (you may need to find the version with

    sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

    For CentOS 5, RHEL 5 64-bit use:

    sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-5.noarch.rpm
  • Since we are on CentOS 6 64-bit we went with the second set.

    sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

    You should get a screen that looks something like this if successful

    ..
    ..
    Preparing...                ########################################### [100%]
       1:epel-release           ########################################### [100%]
    
    接着从新来一次sudo yum install postgis2_9x
    接下来安装一下这个外键数据包装工具
    yum install ogr_fdw95
     

    Installing pgRouting binaries(安装路径分析工具pgRouting )

    yum install pgrouting_95
     
    确保对数据库能进行空间扩展
    Enabling Extensions in a database
    su postgres
    /usr/pgsql-9.5/bin/psql -p 5432
    CREATE DATABASE gistest;
    \connect gistest;
    连接到这个测试用数据库
    Should give you message: 
    You are now connected to database "gistest" as user "postgres".

    Next install the extensions

    CREATE EXTENSION postgis;
    CREATE EXTENSION postgis_topology;
    CREATE EXTENSION ogr_fdw;

    To verify the install do:

    SELECT postgis_full_version();
    接下来查询出这种结果。
                              postgis_full_version
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     POSTGIS="2.2.1 r14555" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.11.2, released 2015/02/10" LIBXML="2.9.1" LIBJSON="0.11" TOPOLOGY RASTER
    退出数据库
    \q
    exit
    用这个命令更新版本:
yum update postgis2_95
跟新了这个软件以后要跟新数据库扩展,请事先一下步骤。

Now connect back as postgres and upgrade your database by doing the following

su postgres
/usr/pgsql-9.5/bin/psql -p 5432 -d gistest 

#once in psql console do the following
ALTER EXTENSION postgis UPDATE;
-- repeat for each extension so for example
-- if you installed postgis_topology
ALTER EXTENSION postgis_topology UPDATE;
-- then run to check version
SELECT postgis_full_version();

You should now see 2.2.1 listed

To install pgRouting and verify install

CREATE EXTENSION pgrouting;
SELECT * FROM pgr_version();

Should output

 version |       tag       | build |  hash   | branch | boost
---------+-----------------+-------+---------+--------+--------
 2.1.0   | pgrouting-2.1.0 | 1     | b38118a | master | 1.53.0
 
========================================================================
以上的东西你做完以后,就恭喜你安装成功了。不过这样是不够的。因为你要别人要能访问。
具体也是参考这个博客的。http://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html
第一步修改配置文件
# vi /var/lib/pgsql/9.2/data/postgresql.conf 这个版本你自己设定吧。
#如果你在刚刚第一步vi /etc/sysconfig/pgsql/postgresql-9.5进行了设定。
那么配置文件就在你刚刚设定的目录下面、
/pgdata95/data/postgresql.conf

如果想让PostgreSQL 监听整个网络的话,将listen_addresses 前的#去掉,并将 listen_addresses = 'localhost' 改成 listen_addresses = '*' (图片来自于http://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html

10.2 修改客户端认证配置文件pg_hba.conf

将需要远程访问数据库的IP地址或地址段加入该文件。

# vi /var/lib/pgsql/9.2/data/pg_hba.conf (/pgdata95/data/pg_hba.conf)也有可能在这里

这里说一句(我不知道为什么要设置成md5我设置了不成功。要改成trust

这里是你想开放的网段的。

 

11. 重启服务以使设置生效

# service postgresql-9.2 restart

这个就算是能外网访问了。

 

本文章主要参考了

http://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html

http://www.postgresonline.com/journal/archives/362-An-almost-idiots-guide-to-install-PostgreSQL-9.5,-PostGIS-2.2-and-pgRouting-2.1.0-with-Yum.html

这两个博客。(我已经标明出处了,应该没问题吧)

 

最后分享一本讲postgresql的书。

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics