pgsql16及postgis安装
postgis 下载登录 postgis 的官方网站:
PostGIS
下载符合 postgresql 数据库版本的 postgis 安装包。
postgresql 16.0
gcc 4.8.5
make 3.82
proj 8.2.1
libxml2 2.9.9
gdal 3.5.3
geos 3.6.6
protobuf 3.6.1
protobuf-c-1.4.1
postgis-3.4.0
各种依赖包安装地址
postgresql
https://www.postgresql.org/ftp/source/
gcc
https://gcc.gnu.org/releases.html
proj
https://proj.org/download.html
libxml2
https://download.gnome.org/sources/libxml2/
json-c
https://s3.amazonaws.com/json-c_releases/releases/index.html
gdal
https://github.com/OSGeo/gdal/releases
geos
https://libgeos.org/usage/download/
protobuf
https://github.com/google/protobuf/releases
protobuf-c
https://github.com/protobuf-c/protobuf-c/releases
安装 postgresql
1、编译,指定安装postgresql的路径
./configure --prefix=/usr/local/pgsql
2、编译:
make
3、安装:
make install
4、创建用户组和用户:
groupadd postgres
useradd -g postgres postgres
5、创建数据库库文件存储目录、给postgres赋予权限:
mkdir /usr/local/pgsql/data
cd /usr/local/pgsql
chown postgres.postgres data
chmod 750 /usr/local/pgsql/data
6、编辑~/.bash_profile文件
#vi ~/.bash_profile
设置以下的情况变量,
export PGHOME=/usr/local/pgsql
export PGDATA=/usr/local/pgsql/data
PATH=$PATH:$PGHOME/bin
export PATH
7、初始化数据库目录:
切换用户(root也可以)
su - postgresql
初始化数据 -D指定初始化创建的数据库的文件路径
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
8、启动数据库
$ pg_ctl -D /usr/local/pgsql/data -l logfile start
$ ps -ef | grep postgres
安装 libxml2
1、上传安装包
$ cd /opt/postgresql/soft
$ rz
2、解压缩
$ xz -d libxml2-2.9.9.tar.xz
$ tar -xvf libxml2-2.9.9.tar
3、安装
$ cd libxml2-2.9.9
$ ./configure --prefix=/usr/local/libxml2
$ make && make install
......
make: Entering directory `/opt/postgresql/soft/libxml2-2.9.9/python'
CC libxml.lo
libxml.c:14:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
make: *** Error 1
make: Leaving directory `/opt/postgresql/soft/libxml2-2.9.9/python'
make: *** Error 1
make: Leaving directory `/opt/postgresql/soft/libxml2-2.9.9/python'
make: *** Error 2
make: Leaving directory `/opt/postgresql/soft/libxml2-2.9.9/python'
make: *** Error 1
make: Leaving directory `/opt/postgresql/soft/libxml2-2.9.9'
make: *** Error 2
报错没有找到 python 的头文件,安装 python 开发包办理
$ exit
logout
# mkdir /usr/local/libxml2
# chown postgres:postgres /usr/local/libxml2
# yum install python-devel
# su - postgres
Last login: Tue Feb 28 10:01:38 CST 2023 on pts/1
$ cd /opt/postgresql/soft/libxml2-2.9.9
$ make && make install
安装 geos
1、上传安装包
$ cd /opt/postgresql/soft
$ rz
2、解压缩
$ tar -xvf geos-3.6.6.tar.bz2
3、安装
$ cd geos-3.6.6
$ ./configure --prefix=/usr/local/geos
$ exit
logout
# mkdir /usr/local/geos
# chown postgres:postgres /usr/local/geos
# su - postgres
$ cd /opt/postgresql/soft/geos-3.6.6
$ make && make install
安装 proj
1、上传安装包
$ cd /opt/postgresql/soft
$ rz
2、解压缩
$ tar -xvf proj-8.2.1.tar.gz
3、安装
$ cd proj-8.2.1
$ ./configure --prefix=/usr/local/proj
......
enabled, pthread
checking for SQLITE3... configure: error: Package requirements (sqlite3 >= 3.11) were not met:
No package 'sqlite3' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables SQLITE3_CFLAGS
and SQLITE3_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
proj8 对于 sqlite 数据库有版本要求,重新安装 sqlite 数据库
sqlite下载地址:
https://www.sqlite.org/download.html
上传并安装
$ cd /opt/postgresql/soft
$ rz
$ tar -xvf sqlite-autoconf-3410000.tar.gz
$ cd sqlite-autoconf-3410000
$ ./configure --prefix=/usr/local/sqlite
$ exit
# mkdir /usr/local/sqlite
# su - postgres
$ cd /opt/postgresql/soft/sqlite-autoconf-3410000
$ make && make install
修改链接
# cd /usr/bin/
# mv sqlite3 sqlite3_old
# ln -s /usr/local/sqlite/bin/sqlite3 sqlite3
继承安装 proj
$ su - postgres
$ cd /opt/postgresql/soft/proj-8.2.1
$ ./configure --prefix=/usr/local/proj
报错找不到 libtiff-4 包,服务器已经安装了
$ rpm -qa libtiff
libtiff-4.0.3-35.el7.x86_64
实验安装开发包,发现可以办理问题
# yum install libtiff-devel
继承安装 proj
# ./configure --prefix=/usr/local/proj
报错缺少 curl 包
# yum install curl
继承安装 proj
# ./configure --prefix=/usr/local/proj
# exit
# mkdir /usr/local/proj
# chown postgres:postgres /usr/local/proj
# su - postgres
$ cd /opt/postgresql/soft/proj-8.2.1
$ make && make install
安装 gdal
1、上传安装包
$ cd /opt/postgresql/soft
$ rz
2、解压缩
$ tar -xvf gdal-3.5.3.tar.gz
3、安装
$ exit
# mkdir /usr/local/gdal
# chown postgres:postgres /usr/local/gdal
# su - postgres
$ cd /opt/postgresql/soft/gdal-3.5.3
# ./configure --prefix=/usr/local/gdal
报错找不到 PROJ 包,添加情况变量到 /etc/profile 也不收效,选择手动指定proj安装目录的方式办理。
应该再实验在 /etc/ld.so.conf 中配置库包位置试试
# ./configure --prefix=/usr/local/gdal --with-proj=/usr/local/proj/
# make && make install
安装 json-c
1、上传安装包
$ cd /opt/postgresql/soft
$ rz
2、解压缩
$ tar -xvf json-c-0.10.tar.gz
3、安装
$ exit
# mkdir /usr/local/jons-c
# chown postgres:postgres /usr/local/jons-c
# su - postgres
$ cd /opt/postgresql/soft/json-c-0.10
$ ./configure --prefix=/usr/local/json-c
$ make && make install
安装 postgis
1、上传安装包
$ cd /opt/postgresql/soft
$ rz
2、解压缩
$ tar -xvf postgis-3.2.4.tar.gz
3、安装
# ./configure --prefix=/usr/local/postgis
# ./configure --prefix=/usr/local/postgis --with-geosconfig=/usr/local/bin/geos-config
......
configure: WARNING: "Could not find json-c"
checking for PROTOBUFC... no
libprotobuf-c not found in pkg-config
checking protobuf-c/protobuf-c.h usability... no
checking protobuf-c/protobuf-c.h presence... no
checking for protobuf-c/protobuf-c.h... no
configure: error: unable to find protobuf-c/protobuf-c.h using CPPFLAGS. You can disable MVT and Geobuf support using --without-protobuf
报错找不到 protobuf-c 包,实验利用 yum 安装,安装完成之后问题未办理
手动下载 protobuf-c 进行安装
安装 protobuf-c
下载地址
https://github.com/protobuf-c/protobuf-c/releases
上传并安装
$ cd /opt/postgresql/soft
$ rz
# tar -xvf protobuf-c-1.4.1.tar.gz
$ exit
# mkdir /usr/local/protobuf-c
# chown postgres:postgres /usr/local/protobuf-c
# su - postgres
# cd /opt/postgresql/soft/protobuf-c-1.4.1
# ./configure --prefix=/usr/local/protobuf-c
protobuf-c 依赖与 protobuf 包,必要先安装 protobuf 包
安装 protobuf 包
https://github.com/google/protobuf/releases
上传并安装
$ cd /opt/postgresql/soft
$ rz
# tar -xvf protobuf-all-3.6.1.tar.gz
$ exit
# mkdir /usr/local/protobuf
# chown postgres:postgres /usr/local/protobuf
# su - postgres
$ cd /opt/postgresql/soft/protobuf-3.6.1
$ ./configure --prefix=/usr/local/protobuf
$ make && make install
继承安装 protobuf-c
$ ./configure --prefix=/usr/local/protobuf-c
$ make && make install
继承安装 postgis
$ ./configure --prefix=/usr/local/postgis --with-geosconfig=/usr/local/bin/geos-config
如果还报 protobuf-c 找不到的问题,把 protobuf-c 的库参加到情况变量中去
vim /etc/profile
export LD_LIBRARY_PATH=/usr/local/protobuf/lib:$LD_LIBRARY_PATH
如果还报其他依赖文件找不到可以指定依赖包路径
./configure --prefix=/usr/local/postgis --with-geosconfig=/usr/local/geos/bin/geos-config --with-gdalconfig=/usr/local/gdal/bin/gdal-config --with-projdir=/usr/local/proj
$ make && make install
postgresql 接入 postgis 扩展
1、创建一个数据库
$ psql
gisdb=# create database gisdb;
2、加载 postgis 插件
gisdb=# create extension postgis;
ERROR: could not load library "/usr/local/pgsql-14.6/lib/postgis-3.so": libgeos_c.so.1: cannot open shared object file: No such file or directory
将所安装的软件库都参加到共享库办理上述问题
# vim /etc/ld.so.conf
/usr/local/gdal/lib
/usr/local/geos/lib
/usr/local/proj/lib
/usr/local/pgsql/lib
/usr/local/json-c/lib
/usr/local/libxml2/lib
/usr/local/protobuf/lib
/usr/local/protobuf-c/lib
# ldconfig
gisdb=# create extension postgis;
CREATE EXTENSION
至此安装完成
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]