Centos6使用yum安装PostGres以及PostGis

一.安装Postgresql 9.4

1.安装命令:

yum install http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-redhat94-9.4-1.noarch.rpm
yum install postgresql94-server postgresql94-contrib
2.初始化PostGres数据库

service postgresql-9.4 initdb

3.添加到自启动服务

chkconfig postgresql-9.4 on
4.修改配置文件
查找pg_hba.conf文件并修改
 [root@localhost ~]#  find /  -name pg_hba.conf
  /var/lib/pgsql/9.4/data/pg_hba.conf

 [root@localhost ~]# vi /var/lib/pgsql/9.4/data/pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD
# “local” is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             0.0.0.0/0            md5
# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            ident
#host    replication     postgres        ::1/128                 ident

查找postgresql.conf

[root@localhost ~]#  find /  -name postgresql.conf

find /  -name postgresql.conf
[root@localhost ~]# vi /var/lib/pgsql/9.4/data/postgresql.conf
将监听的ip改为’*’,取消之前的#注释,注意要取消注释。 

# – Connection Settings –
listen_addresses = ‘*’          # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to ‘localhost’; use ‘*’ for all
                                        # (change requires restart)
#port = 5432                            # (change requires restart)
max_connections = 100                   # (change requires restart)

5.修改环境变量
找到安装主目录
[root@localhost ~]# find / -name pgsql-9.4
/usr/pgsql-9.4
设置环境变量
[root@localhost ~]# vi /etc/profile

增加以下环境变量

export PGHOME=/usr/pgsql-9.4
export PGDATA=/var/lib/pgsql/9.4/data
export PATH=$PGHOME/bin:$PATH

重新启用profile文件,对更改生效。
source /etc/profile
6.服务启动

service postgresql-9.4 start  #初始化启动了一次,所以是restart
8.账户登录
[root@localhost ~]# useradd postgres #新增postgres账户,已有的话,跳过本句,直接执行下一句设置密码
[root@localhost ~]# passwd 123456
#切换到postgres账户
[root@localhost ~]# su – postgres
Last login: Mon Aug 10 10:45:32 CST 2015 on pts/0
#执行psql语句
-bash-4.2$ psql
psql (9.4.4)
Type “help” for help.
postgres=#         #这里输入psql命令

二.安装PostGis
yum install postgis2_94
1.如果出现以下情况
Error: Package: gdal-libs-1.9.2-4.el6.x86_64 (pgdg93)
           Requires: libcfitsio.so.0()(64bit)
Error: Package: gdal-libs-1.9.2-4.el6.x86_64 (pgdg93)
           Requires: libspatialite.so.2()(64bit)
Error: Package: gdal-libs-1.9.2-4.el6.x86_64 (pgdg93)
           Requires: libnetcdf.so.6()(64bit)
Error: Package: gdal-libs-1.9.2-4.el6.x86_64 (pgdg93)
           Requires: libfreexl.so.1()(64bit)
Error: Package: postgis2_93-client-2.1.1-1.rhel6.x86_64 (pgdg93)
           Requires: libjson.so.0()(64bit)
Error: Package: gdal-libs-1.9.2-4.el6.x86_64 (pgdg93)
           Requires: libarmadillo.so.3()(64bit)
Error: Package: postgis2_93-2.1.1-1.rhel6.x86_64 (pgdg93)
           Requires: hdf5
Error: Package: postgis2_93-2.1.1-1.rhel6.x86_64 (pgdg93)
           Requires: json-c
Error: Package: gdal-libs-1.9.2-4.el6.x86_64 (pgdg93)
           Requires: libhdf5.so.6()(64bit)
Error: Package: gdal-libs-1.9.2-4.el6.x86_64 (pgdg93)
           Requires: libdap.so.11()(64bit)
Error: Package: gdal-libs-1.9.2-4.el6.x86_64 (pgdg93)
           Requires: libCharLS.so.1()(64bit)
Error: Package: gdal-libs-1.9.2-4.el6.x86_64 (pgdg93)
           Requires: libdapserver.so.7()(64bit)
Error: Package: gdal-libs-1.9.2-4.el6.x86_64 (pgdg93)
           Requires: libdapclient.so.3()(64bit)
Error: Package: postgis2_93-2.1.1-1.rhel6.x86_64 (pgdg93)
           Requires: libjson.so.0()(64bit)
Error: Package: gdal-libs-1.9.2-4.el6.x86_64 (pgdg93)
           Requires: libgta.so.0()(64bit)
2.请先安装以下rpm
#CentOS 7, RHEL 7 64-bit:
sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
# CentOS 6, RHEL 6 64-bit:(这里根据自已的系统版本作选择)
sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# CentOS 6, RHEL 6 32-bit:
sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# CentOS 5, RHEL 5 64-bit:
sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
# CentOS 5, RHEL 5 32-bit:
sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
3.然后重新安装PostGis
yum install postgis2_94

三。安装pgrouting
yum install pgrouting_94

转载自:https://blog.csdn.net/doegoo/article/details/50704365

You may also like...