Install postgresql+postGSI under linux (centos) (pro-test feasible)

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

 

If you want to install postgrtSql

 

first step:

Determine your operating system, whether it is a red hat series or a dabin system, or some other distribution of 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....之类的。替换一个数字就好了

 

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

The middle section is for: want to install different versions of postgresql on the same server. You can skip it if you just want to install one version.

 

become root first 

su root
vi /etc/sysconfig/pgsql/postgresql-9.5# Analyze, this is the system configuration file
The priority is very high, and the configuration information inside will play a key role in the subsequent installation process. If you haven't installed it yet
For postgreSql, this file does not exist, of course, vi will help create it. There is no content in it.
You can enter the following information:
PGPORT=5440 #Set a port other than 5432
PGDATA=/pgdata95 #Set the path where the initialized database is located. The core configuration files will be placed in this directory after the installation is complete.
Enter: wq save and exit.
#======================================================================
During the postgresql installation process, it will automatically create a user for you.
postgres
You have to set a password for him: sudo passwd postgres
Now restart the service:
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.
 
If not then
/usr/pgsql-9.5/bin/postgresql95-setup initdb #Initialize the database
service postgresql-9.5 start #Start service
chkconfig --list #(to see list of services)
chkconfig postgresql-9.5 on #(to have start on bootup)#Set boot up
After the above initialization process.
by default.
The data file will be in : /var/lib/pgsql/9.5/data (which contains the configuration file that controls postgresql)
The extension file will be here: /usr/pgsql-9.5/share/extension/ (I don't know what to do with this)
Binaries : /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。
A tool that is easy to configure (in fact, I haven't used it, maybe I don't know it)
with postgres
cd ~/
/usr/pgsql-9.5/bin/psql -p 5432 (this is the default port) -c "CREATE EXTENSION adminpack;"
The next step is to install this software, the expansion of the spatial database. 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)
try: yum -y install epel-release
If not, proceed as follows.
 
 
  • 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 ###################################### %]
    
    Then do a sudo yum install postgis2_9x again
    Next, install this foreign key data wrapper tool
    yum install ogr_fdw95
     

    Installing pgRouting binaries

    yum install pgrouting_95
     
    确保对数据库能进行空间扩展
    Enabling Extensions in a database
    with postgres
    /usr/pgsql-9.5/bin/psql -p 5432
    CREATE DATABASE gistest;
    \connect gistest;
    Connect to this test database
    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();
    Next, look for this result.
                              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
    Exit the database
    \q
    exit
    Update the version with this command:
yum update postgis2_95
After updating this software, if you want to expand with the new database, please follow the steps in advance.

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

with 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
 
========================================================================
After you have done the above things, congratulations on your successful installation. But this is not enough. Because you want others to be able to access.
Refer to this blog for details. http://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html
The first step is to modify the configuration file
# vi /var/lib/pgsql/9.2/data/postgresql.conf Set this version by yourself.
#If you set it in the first step vi /etc/sysconfig/pgsql/postgresql-9.5.
Then the configuration file is under the directory you just set,
/pgdata95/data/postgresql.conf

If you want PostgreSQL to monitor the entire network, remove the # before listen_addresses and change listen_addresses = 'localhost' to listen_addresses = '*' (picture from http://www.cnblogs.com/mchina/archive/2012/ 06/06/2539003.html )

10.2 Modify the client authentication configuration file pg_hba.conf

Add the IP addresses or address segments that need to remotely access the database to this file.

# vi /var/lib/pgsql/9.2/data/pg_hba.conf ( /pgdata95/ data/ pg_hba.conf ) may also be here

Here's a word (I don't know why I want to set it to md5, I set it up unsuccessfully. I have to change it to trust )

Here is the network segment you want to open.

 

11. Restart the service for the settings to take effect

# service postgresql-9.2 restart

This is even accessible from the Internet.

 

This article mainly refers to

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

Both blogs. (I have marked the source, it should be fine)

 

最后分享一本讲postgresql的书。

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326946623&siteId=291194637