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

👨‍⚕ 主页: gis分享者

👨‍⚕ 感谢各位大佬 点赞👍 收藏⭐ 留言📝 加关注✅!

👨‍⚕ 收录于专栏:运维工程师


文章目录

  • 前言
  • 一、posgresql部署
    • [1.1 安装前可以先进行用户以及用户组的配置,方便后面进行授权,通过编译安装也需要](#1.1 安装前可以先进行用户以及用户组的配置,方便后面进行授权,通过编译安装也需要)
    • [1.2 通过yum安装](#1.2 通过yum安装)
    • [1.3 编译安装](#1.3 编译安装)
      • [1.3.1 安装软件准备基于此情况,我们首先需要准备相应的安装包内容](#1.3.1 安装软件准备基于此情况,我们首先需要准备相应的安装包内容)
      • [1.3.2 文件包编译](#1.3.2 文件包编译)
      • [1.3.3 安装完成后进行数据库data配置](#1.3.3 安装完成后进行数据库data配置)
  • 二、PostGIS安装部署
    • [2.1 安装编译时环境](#2.1 安装编译时环境)
      • [2.1.1 proj4安装](#2.1.1 proj4安装)
      • [2.1.2 geos安装](#2.1.2 geos安装)
      • [2.1.2 gdal安装](#2.1.2 gdal安装)
    • [2.2 编译postgis安装包](#2.2 编译postgis安装包)
      • [2.2.1 编译安装](#2.2.1 编译安装)
      • [2.2.2 安装扩展插件](#2.2.2 安装扩展插件)

前言

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

一、posgresql部署

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

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

1.2 通过yum安装

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

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

安装完成后可以进行相应的检查

powershell 复制代码
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 需要此软件,安装方式。右键选择在终端打开

powershell 复制代码
[root@localhost ~]# yum install readline-devel

最好安装下openssl-devel,因为安装timescaledb时会提示这个未安装(一般情况也可以不安装)

powershell 复制代码
[root@localhost ~]# yum install openssl-devel

1.3.2 文件包编译

将下载好的文件放入文件目录下,这里我放在postgresql目录下

powershell 复制代码
[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配置

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

初始化数据库

su -- postgres

powershell 复制代码
/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

输入如下内容:

powershell 复制代码
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

powershell 复制代码
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

#修改完成后可以进行服务的重启

powershell 复制代码
/usr/local/pgsql/bin/pg_ctl restart

此处截图为pg_hba.conf追加配置

设置服务自动启动

chkconfig --list

修改密码

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

开通端口5432

powershell 复制代码
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安装

powershell 复制代码
[root@localhost home]# wget http://download.osgeo.org/proj/proj-4.9.3.tar.gz   # 下载文件
powershell 复制代码
[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安装

powershell 复制代码
[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如下:

powershell 复制代码
[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安装

powershell 复制代码
[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 编译安装

powershell 复制代码
[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 安装扩展插件

powershell 复制代码
select name from pg_available_extensions;
CREATE EXTENSION postgis;
相关推荐
千寻技术帮1 天前
10371_基于Springboot的书籍影视交流论坛
mysql·毕业设计·springboot·安装·书籍影视
问道飞鱼1 天前
【数据库知识】PGSQL数据类型详细说明
数据库·sql·postgresql
java_logo1 天前
Supabase Postgres Docker 容器化部署指南
运维·docker·postgresql·容器·postgres部署教程·postgres部署文档·docker postgres
杨了个杨89821 天前
PostgreSQL 完全备份与还原
数据库·postgresql
大道之简1 天前
PostgreSQL pgvector向量数据库
数据库·postgresql
yfhmmm1 天前
PostgreSQL如何进行时间点恢复(PITR)
数据库·postgresql
程序员老赵2 天前
Supabase Postgres Docker 容器化部署指南
docker·postgresql
困死了11112 天前
PostgreSQL笔记
数据库·笔记·postgresql
前端之虎陈随易2 天前
PostgreSQL v18发布,新增AIO uuidv7 OAuth等功能
数据库·postgresql
小草儿7992 天前
postgresql相关
postgresql