在Centos系统源码安装postgreSQL数据库及postGIS扩展

发布于:2024-04-27 ⋅ 阅读:(23) ⋅ 点赞:(0)

安装前
PostGIS扩展通常需要安装一些依赖项。
1.GDAL: PostGIS需要GDAL(Geospatial Data Abstraction Library)来处理地理空间数据格式。
2.GEOS: GEOS(Geometry Engine - Open Source)是一个用于处理地理空间数据的C++库。
3.Proj: Proj是用于地图投影的库。

postgreSQL与postGIS插件的版本支持关系
在这里插入图片描述版本对应关系详情

本次安装的各版本如下
postgresql-13.0.tar
geos-3.9.0
gdal-2.4.4
proj-7.2.1
postgis-3.0.10

一、安装postgreSQL

1.1安装

包下载地址
选postgresql-13.0.tar.gz。
使用工具将下载好的包传到服务器。
解压 ,进入解压目录

tar -zxvf postgresql-13.0.tar.gz 
cd postgresql-13.0

./configure
这一步不成功看下面解决方法
make
make install
adduser postgres

./configure --prefix=/usr/local/postgresql
这一步不成功看下面解决方法
make
make install
#创建用户
adduser postgres
#修改目录的所有者为postgres用户
chown -R postgre:postgre /usr/local/postgresql
su - postgres

环境变量配置
编辑/etc/profile 文件 在最后插入如下两行

export PGHOME=/usr/local/postgresql
export PATH=$PATH:$PGHOME/bin

编辑完执行使其生效

source /etc/profile

1.2启动数据库服务、登录

切换到刚刚创建的postgres用户、切换到安装的目录bin下

su postgres
cd /usr/local/postgresql/bin
#初始化数据库
./initdb -D /usr/local/postgresql/data -U postgre --encoding=UTF8 --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8

启动数据库服务

./pg_ctl -D /usr/local/postgresql/data/ start

登录数据库

psql -U postgres -d postgres -h 127.0.0.1 - p 5432

修改密码

\password

连续输入两次密码,第一次输入、第二次确认。

1.3修改配置

修改配置文件
/usr/local/postgresql/data/postgresql.conf
添加

listen_addresses = '*'
port = 5432

pg_hba.conf
添加

host    all               all             0.0.0.0/0           md5

重启数据库生效

/usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data/  restart

二、依赖安装

2.1安装Proj4

包下载地址
解压,进入解压目录

tar -zxvf proj-7.2.1.tar.gz
cd /proj-7.2.1

生成配置、构建

./configure --prefix=/usr/local/postgresql/plugin/proj
make
make install

2.2安装GEOS

包下载地址
解压,进入解压目录

tar -xvf geos-3.9.0.tar.bz2
cd geos-3.9.0/

使用autoconf工具 用configure.ac 文件生成 configure 脚本。
执行命令:

autoconf

生成configure 脚本,生成配置、构建。

./configure --prefix=/usr/local/postgresql/plugin/geos
make
make install

2.3gdal安装

包下载地址
解压,进入解压目录

tar -zxvf gdal-2.4.4.tar.gz
cd gdal-2.4.4/

生成configure 脚本,生成配置、构建。

./configure --prefix=/usr/local/postgresql/plugin/gdal
make
make install

2.4postgis安装

包下载地址
解压,进入解压目录

tar -zxvf postgis-3.0.10.tar.gz
cd postgis-3.0.10/

生成configure 脚本,生成配置、构建。

./configure --prefix=/usr/local/postgresql/plugin/postgis --with-pgconfig=/usr/local/postgresql/bin/pg_config --with-geosconfig=/usr/local/postgresql/plugin/geos/bin/geos-config --with-projdir=/usr/local/postgresql/plugin/proj --with-gdalconfig=/usr/local/postgresql/plugin/gdal/bin/gdal-config
make
make install

2.4检查PostGiS是否安装成功

加载 PostGIS 扩展:

CREATE EXTENSION postgis;
#检查PostGIS 的版本信息
SELECT postgis_full_version();

在这里插入图片描述

三、安装过程中遇到的问题汇总

configure: error: readline library not found
解决方案

configure: error: could not find pg_config within the current path. You may need to re-run configure with a --with-pgconfig parameter.
执行:

./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config

configure: error: Package requirements (libxml-2.0) were not met:
No package ‘libxml-2.0’ found
执行:

sudo yum install libxml2-devel

configure: error: could not find geos-config within the current path. You may need to try re-running configure with a --with-geosconfig parameter.
执行

yum install geos geos-devel

configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure. It is possible the compiler isn’t looking in the proper directory.
Use --without-readline to disable readline support.
安装readline 库及其开发文件:

sudo yum install readline readline-devel

checking for SQLITE3… configure: error: Package requirements (sqlite3 >= 3.11) were not met:
解决方法:

sudo yum update
sudo yum install sqlite sqlite-devel

checking for TIFF… configure: error: Package requirements (libtiff-4) were not met:
解决方法:

sudo yum install libtiff libtiff-devel

configure: error: curl not found. If wanting to do a build without curl support (and thus without built-in networking capability), explictly disable it with --without-curl
解决方法:

sudo yum install curl libcurl-devel

jpeg2000dataset.cpp:40:10: fatal error: jasper/jasper.h: No such file or directory
#include <jasper/jasper.h>
^~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** […/…/GDALmake.opt:670: …/o/jpeg2000dataset.lo] Error 1
解决方法:
https://www.jianshu.com/p/e19b3da3e63a

configure: error: Package requirements (libxml-2.0) were not met:
Package ‘libxml-2.0’, required by ‘virtual:world’, not found

sudo yum install libxml2 libxml2-devel

ERROR: could not load library “/usr/local/postgresql/lib/postgis-3.so”: libgeos_c.so.1: cannot open shared object file: No such file or directory
解决方法:

find / -name "libgeos_c.so.1"
/usr/local/postgresql/plugin/geos/lib/libgeos_c.so.1
#将查询到的文件路径写入到/etc/ld.so.conf文件中
echo "/usr/local/postgresql/plugin/geos/lib" >> /etc/ld.so.conf
ldconfig

ERROR: could not load library “/usr/local/postgresql/lib/postgis-3.so”: libproj.so.19: cannot open shared object file: No such file or directory
解决方法:

find / -name "libgeos_c.so.1"
/usr/local/postgresql/plugin/proj/lib/libproj.so.19
#将查询到的文件路径写入到/etc/ld.so.conf文件中
echo "/usr/local/postgresql/plugin/proj/lib/" >> /etc/ld.so.conf
ldconfig

网站公告

今日签到

点亮在社区的每一天
去签到