安装环境
操作系统 Cenos7
软件 postgresSQL postgressql9.4.9.tar,
Postgregis proj-4.9.2.tar.gz
gdal-1.11.0.tar,
geos-3.5.0.tar,
postgis-2.2.4dev.tar,
postgresSQL
安装
- 解压文件
tar jxvf postgresql- 9.4.9.tar.bz2 - 进入解压后的postgresql- 9.4.9目录
cd postgresql-9.4.9 - 编译postgresql源码
./source -prefix=/opt/pgsql-9.4.9
其中可能会报错:
A. configure: error: no acceptable C compiler found in $PATH
yum install gcc
B. configure: error: readline library notfound
yum install readline
yum install readline-devel
C. configure: error: zlib library not found
yum install zlib-devel;
可能出现的错误进行安装缺失的依赖包后重新进行
./source -prefix=/opt/pgsql-9.4.9 - 执行make
- 执行make install
至此postgressql安装成功。
用户设置
- 增加 postgres用户
useradd postgres
修改postgres密码
passwd postgres - 设置postgres用户的环境变量
切换到postgres用户
#su - postgres - 进入postgres的主目录
#cd ~
编辑~/.bash_profile文件
#vi ~/.bash_profile
增加以下的环境变量
export PGHOME=/opt/pgsql-9.4.9
export PGDATA=~/data
export PATH= P A T H : PATH: PATH:HOME/bin:$PGHOME/bin
保存,退出vi。执行以下命令,使环境变量生效
#source ~/.bash_profile - 初始化postgres数据库
- 安装实例
initdb - 创建数据库
Created postgis
启动postgres实例
#pg_ctl start
12. 可以看到postgresql数据库实例已经启动,通过下面的命令可以查看系统中运行的postgres进程
13. #ps -ef | grep postgres
停止postgresql实例
#pg_ctl stop
#ps -ef | grep postgres
开启远程连接
找到 /home/postgres/data 文件夹下的
postgresql.conf
修改 listen_addresses = ‘localhost’
删除前边的#, 内容改为*
pg_hba.conf
最后一行添加
host all all 0.0.0.0/0 md5
执行数据库关闭,启动。
以上为所有postgresSQL安装步骤
防火墙设置
打开配置文件
[root@localhost ~]# vi /etc/sysconfig/iptables
正确的配置文件
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 5432 -j ACCEPT
注意点:新开放的端口一定要在端口22后面
重启防火墙使配置生效
[root@localhost ~]# /etc/init.d/iptables restart
其它
查看开放端口
[root@localhost ~]# /etc/init.d/iptables status
关闭防火墙
[root@localhost ~]# /etc/init.d/iptables stop
postGIS
- 使用root用户登录
Su – root
输入密码
安装 geos
解压: tar zvf geos-3.5.0.tar
进入目录: cd /geos-3.5.0
执行 ./configure –prefix=/opt/geos
如果报错g++not found
执行yum install gcc_c++
重新执行./configure –prefix=/opt/geos
如果报错Configure:configure: error: could not find xml2-config from libxml2 within the current path. You may need to try re-running configure with a --with-xml2config
执行 yum install libxml2-devel.x86_64
重新执行./configure –prefix=/opt/geos
执行 make
执行 make install
安装 proj
解压: tar zvf proj -3.5.0.tar
进入目录: cd / proj -3.5.0
执行 ./configure –prefix=/opt/ proj
执行 make
执行 make install
安装gdal
解压: tar zvf gdal-3.5.0.tar
进入目录: cd /gdal-3.5.0
执行 ./configure –prefix=/opt/gdal
执行 make
执行 make install
执行 postgis安装
- 解压 tar zvf postgis-2.2.4dev.tar
- 进入目录 cd /postgis-2.2
- 执行
./configure --prefix=/opt/postgis-2.2/ --with-pgconfig=/opt/pgsql-9.4.9/bin/pg_config --with-geosconfig=/opt/geos/bin/geos-config --with-projdir=/opt/proj/ --with-gdalconfig=/opt/gdal/bin/gdal-config
执行 make
执行 make install - 打开 vi /etc/ld.so.conf
输入
/opt/geos/lib
/opt/proj/lib//lib
/opt/pgsql-9.4.9/lib
/opt/postgis-2.2/lib
保存退出,执行
sudo ldconfig - 使用postgres用户登录
执行 psql -d postgis
进入 psql命令行
执行 create extension postgis;
该过程如果报错ERROR: could not load library “/opt/pgsql/lib/postgis-2.2.so”: libproj.so.9: cannot open shared object file: No such file or directory
执行: cp /opt/proj/lib/libproj.so.9 /opt/pgsql-9.4.9/lib/
该过程如果报错ERROR: could not load library “/opt/pgsql-9.4.9/lib/rtpostgis-2.2.so”: libgdal.so.1: cannot open shared object file: No such file or directory
执行:cp /opt/gdal/lib/libgdal.so.1 /opt/pgsql-9.4.9/lib/
返回继续执行 create extension postgis_topology;
CREATE EXTENSION fuzzystrmatch;
出错:
ERROR: could not open extension control file “/usr/local/pgsql/share/extension/fuzzystrmatch.control”: No such file or directory
这个扩展已经包含在pgsql源码中,但是默认并未完成,所以需要安装之,进入pgsql源码目录:
cd contrib/fuzzystrmatch/
make
make install
然后再在pgsql命令行下执行:CREATE EXTENSION fuzzystrmatch;
至此整个数据库安装完成。