麒麟V10系统,postgres+postgis安装,保姆级教程,包含所有安装包

👨‍⚕ 主页: gis分享者
👨‍⚕ 感谢各位大佬 点赞👍 收藏⭐ 留言📝 加关注✅!
👨‍⚕ 收录于专栏:运维工程师



前言

本文详细介绍麒麟V10系统下,我们如何安装postgres数据库以及postgis扩展。保姆级教程,另外附件中包含安装包,感谢支持~

一、posgresql部署

1.1 安装前可以先进行用户以及用户组的配置,方便后面进行授权,通过编译安装也需要

# 新增用户组 groupadd postgres 
# 创建用户组内用户 useradd -g postgres postgres 
# 修改用户密码 passwd postgres
# 我得密码:postgres123+.

1.2 通过yum安装

如果用户通过yum能匹配导相应版本,可以直接进行安装。进行检索安装。

yum search postgres*                 # 选择对应版本进行安装
yum -y install postgresql   # 安装相应程序包
yum -y install qt5-qtbase-postgresql   # 安装相应程序包

在这里插入图片描述
安装完成后可以进行相应的检查

rpm -qa | grep postgres    # 检查PostgreSQL 是否已经安装
rpm -qal | grep postgres   # 检查PostgreSQL 安装位置

在这里插入图片描述

1.3 编译安装

1.3.1 安装软件准备基于此情况,我们首先需要准备相应的安装包内容

下载地址参照 postgresql v10.5下载地址:https://www.postgresql.org/ftp/source/v10.5/
postgresql源码编译时的 ./configure 需要此软件,安装方式。右键选择在终端打开

[root@localhost ~]# yum install readline-devel

在这里插入图片描述
最好安装下openssl-devel,因为安装timescaledb时会提示这个未安装(一般情况也可以不安装)

[root@localhost ~]# yum install openssl-devel

在这里插入图片描述

1.3.2 文件包编译

将下载好的文件放入文件目录下,这里我放在postgresql目录下
在这里插入图片描述

[root@localhost home]# mkdir postgresql   #创建postgresql目录
[root@localhost home]# cd /home/postgresql  #切换到postgresql目录下
[root@localhost home]# tar -zvxf postgresql-10.5.tar.gz  #解压文件
[root@localhost postgresql]# cd postgresql-10.5   #切换到postgresql-10.0目录下
[root@localhost postgresql-10.0]# ./configure  #执行文件
[root@localhost postgresql-10.0]# make
[root@localhost postgresql-10.0]# make install

1.3.3 安装完成后进行数据库data配置

mkdir -p /usr/local/pgsql/data # 创建数据存储目录
chown -R postgres:postgres /usr/local/pgsql # 用户/用户组目录授权

初始化数据库
su – postgres
在这里插入图片描述

/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
/usr/local/pgsql/bin/createdb xjzfxygis

编辑用户下的环境变量配置文件
vi ./.bash_profile
在这里插入图片描述
输入如下内容:

LD_LIBRARY_PATH=/usr/local/pgsql/lib
export LD_LIBRARY_PATH
PATH=/usr/local/pgsql/bin:$PATH
export PATH
export PGDATA=/usr/local/pgsql/data

编辑相应的数据库配置文件,修改postgresql.conf与pg_hba.conf

cd /usr/local/pgsql/data

查找listen_addresses在postgresql.conf文件中的位置并显示行号
在这里插入图片描述
0.0.0.0/0 md5需要密码验证
cat postgresql.conf | grep -n listen_addresses
#编辑postgresql.conf文件,修改默认’localhost’ 为’*’
vi postgresql.conf
#编辑IPv4 local connections: 追加一行,如图所示
vi pg_hba.conf
#修改完成后可以进行服务的重启

/usr/local/pgsql/bin/pg_ctl restart

此处截图为pg_hba.conf追加配置
设置服务自动启动
chkconfig –list
修改密码

psql -h localhost -U postgres
alter role postgres with password ' shihuipassword123+.'; 修改密码

开通端口5432

firewall-cmd --zone=public --add-port=5432/tcp –permanent
firewall-cmd –reload
firewall-cmd --zone=public --list-ports # 查看已经开放的端口

二、PostGIS安装部署

此时发现postgis在麒麟系统环境内并没有提供相关yum安装包,那么则进行所需运行环境程序的编译安装即可。

2.1 安装编译时环境

设置安装相应编译文件后也需要对相应的文件进行用户的授权,否则运行时会显示该用户无权限,或者文件不存在。运行 create extension *会出现错误

2.1.1 proj4安装

[root@localhost home]# wget http://download.osgeo.org/proj/proj-4.9.3.tar.gz   # 下载文件

在这里插入图片描述

[root@localhost ~]# cd /home 
[root@localhost home]# tar -zxvf proj-4.9.3.tar.gz
[root@localhost home]# cd proj-4.9.3
[root@localhost proj-4.9.3]# ./configure --prefix=/data-postgis/pgsql/plugin/proj
[root@localhost proj-4.9.3]# make
[root@localhost proj-4.9.3]# make install
[root@localhost proj-4.9.3]# echo "/data-postgis/pgsql/plugin/proj/lib" > /etc/ld.so.conf.d/proj-4.9.3.conf
[root@localhost proj-4.9.3]#  ldconfig

2.1.2 geos安装

[root@localhost home]# tar -jxf geos-3.6.1.tar.bz2
[root@localhost home]# cd geos-3.6.1 
[root@localhost geos-3.6.1]# ./configure --prefix=/data-postgis/pgsql/plugin/geos
[root@localhost geos-3.6.1]# make
[root@localhost geos-3.6.1]# make install
[root@localhost geos-3.6.1]# echo "/data-postgis/pgsql/plugin/geos/lib" > /etc/ld.so.conf.d/geos-3.6.1.conf
[root@localhost geos-3.6.1]# ldconfig

在这里插入图片描述
Configure 错误处理:
g++: command not found 错误
yum install gcc-c++

error:#error “Can not compile without isnan function or macro”
在这里插入图片描述
在geos解压的文件中,找到/include/config.h
编辑该文件,取消#undef HAVE_ISNAN的注释,保存退出
然后重新配置geos如下:

[root@localhost geos-3.6.1]# ./configure --prefix=/data-postgis/pgsql/plugin/geos
[root@localhost geos-3.6.1]# make
[root@localhost geos-3.6.1]# make install
[root@localhost geos-3.6.1]# echo "/data-postgis/pgsql/plugin/geos/lib" > /etc/ld.so.conf.d/geos-3.6.1.conf
[root@localhost geos-3.6.1]# ldconfig

2.1.2 gdal安装

[root@localhost home]# wget http://download.osgeo.org/gdal/2.1.2/gdal-2.1.2.tar.gz
[root@localhost home]# tar -zxvf gdal-2.1.2.tar.gz
[root@localhost home]# cd gdal-2.1.2
[root@localhost gdal-2.1.2]# ./configure --prefix=/data-postgis/pgsql/plugin/gdal
[root@localhost gdal-2.1.2]# make
[root@localhost gdal-2.1.2]# make install
[root@localhost gdal-2.1.2]# echo "/data-postgis/pgsql/plugin/gdal/lib" > /etc/ld.so.conf.d/gdal-2.1.2.conf
[root@localhost gdal-2.1.2]# ldconfig

2.2 编译postgis安装包

2.2.1 编译安装

[root@localhost home]# wget http://postgis.net/stuff/postgis-2.5.3dev.tar.gz
[root@localhost home]# tar -zxvf postgis-2.5.3dev.tar.gz
[root@localhost home]# cd postgis-2.5.3dev
[root@localhost postgis-2.5.3dev]# ./configure --prefix=/data-postgis/pgsql/plugin/postgis --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-geosconfig=/data-postgis/pgsql/plugin/geos/bin/geos-config --with-gdalconfig=/data-postgis/pgsql/plugin/gdal/bin/gdal-config --with-projdir=/data-postgis/pgsql/plugin/proj
[root@localhost postgis-2.5.3dev]# make
[root@localhost postgis-2.5.3dev]# make install

2.2.2 安装扩展插件

select name from pg_available_extensions;
CREATE EXTENSION postgis;
<think>好的,我现在需要帮助用户找到在PostgreSQL 16上安装PostGIS教程。根据用户提供的引用资料,现有的引用都是关于PostgreSQL 15或更早版本的安装方法,但用户现在需要的是PostgreSQL 16的指导。我需要结合已有的信息,并查找是否有适用于PostgreSQL 16的PostGIS安装步骤。 首先,我应该确认PostGIS是否已经支持PostgreSQL 16。通常,PostGIS的版本会与特定PostgreSQL版本兼容。用户提供的引用中,引用[2]提到安装postgis-3.4.0beta1在PostgreSQL 15.1上,而引用[3]和[4]是关于Windows和Linux的安装方法。可能PostGIS的最新版本已经支持PostgreSQL 16,我需要检查官方网站。 接下来,安装步骤可能会根据操作系统的不同而有所变化。用户提供的引用中有关于yum安装(引用[1]和[4])和Windows安装(引用[3])的方法。因此,我需要分别说明不同系统下的安装步骤。 对于Linux系统,使用yum或apt安装时,需要确保仓库中有支持PostgreSQL 16的PostGIS包。可能需要添加正确的仓库源,然后通过包管理器安装。例如,在CentOS上,可能需要使用pgdg仓库,并指定PostgreSQL 16和对应的PostGIS版本。 在Windows上,用户需要下载与PostgreSQL 16兼容的PostGIS安装程序。官网下载页面可能已经有相应的版本,用户需要找到匹配的.exe文件进行安装。 另外,安装完成后,用户需要在数据库中启用PostGIS扩展,这一步可能类似不同版本,即运行CREATE EXTENSION postgis;。 需要注意的是,由于PostgreSQL 16可能相对较新,部分系统的官方仓库可能还未更新对应的PostGIS包。这时候可能需要从源代码编译安装,或者等待仓库更新。但用户可能更希望使用预编译的包,因此需要确认可用性。 最后,用户可能需要参考官方文档或社区资源,确保安装过程的正确性。同时,提醒用户注意版本兼容性,避免安装不匹配的版本导致问题。</think>### PostgreSQL 16 安装 PostGIS 的步骤 #### 1. **确认系统兼容性** - PostgreSQL 16 需要匹配对应版本的 PostGIS。截至最新信息,PostGIS 3.4 及以上版本已支持 PostgreSQL 16[^2][^3]。 - 若使用 Linux 系统(如 CentOS/RHEL 或 Ubuntu),需确保包管理器已配置 PostgreSQL 16 的官方仓库。 --- #### 2. **Linux 系统安装(以 CentOS 为例)** ##### 步骤 1: 添加 PostgreSQL 16 官方仓库 ```bash # 添加仓库源 sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm ``` ##### 步骤 2: 安装 PostgreSQL 16 和 PostGIS ```bash # 安装 PostgreSQL 16 服务端和客户端 sudo yum install -y postgresql16-server postgresql16-contrib # 安装 PostGIS 扩展包(需确认仓库中存在对应版本) sudo yum install -y postgis34_16 # 示例名称,具体版本可能为 postgis3_16 或类似 ``` ##### 步骤 3: 初始化数据库并启用 PostGIS ```bash # 初始化数据库 sudo /usr/pgsql-16/bin/postgresql-16-setup initdb # 启动服务 sudo systemctl enable postgresql-16 sudo systemctl start postgresql-16 # 进入 PostgreSQL 命令行创建扩展 sudo -u postgres psql CREATE EXTENSION postgis; ``` --- #### 3. **Windows 系统安装** ##### 步骤 1: 下载 PostGIS 安装包 - 访问 PostGIS Windows 下载页面:[https://download.osgeo.org/postgis/windows/](https://download.osgeo.org/postgis/windows/)[^3]。 - 选择与 PostgreSQL 16 匹配的版本(如 `postgis-bundle-pg16-x64-3.4.0.exe`)。 ##### 步骤 2: 运行安装向导 - 双击安装包,按提示选择 PostgreSQL 16 的安装目录。 - 安装完成后,在 PgAdmin 中执行以下 SQL 启用扩展: ```sql CREATE EXTENSION postgis; ``` --- #### 4. **验证安装** ```sql -- 检查 PostGIS 版本 SELECT postgis_full_version(); ``` 若返回版本信息(如 `POSTGIS="3.4.0"`),则安装成功。 --- ### 注意事项 1. **版本匹配问题** - 若官方仓库未提供 PostGIS for PostgreSQL 16 的包,需从源码编译或等待仓库更新[^4]。 2. **扩展依赖** - PostGIS 可能依赖 `postgis_sfcgal` 或 `postgis_topology`,需通过包管理器一并安装[^1]。 ---
评论 102
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gis分享者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值