配置supermap iportal数据库,银河麒麟arm架构SP3系统中离线编译安装postgres、postgis

梦想mc / 2024-10-16 / 原文

 一、安装环境

准备postgresql-11.2.tar.gzpostgis-2.5.0.tar.gz文件,geos-3.6.1-12.ky10.aarch64.rpm包,再准备一台有外网的机器。

如果遇到缺少的包,去有外网的机器下载,再考到内网机器里安装。

大部分安装都是编译安装,遵循配置、编译、安装这三步。

注意安装后的软件目录postgres用户要有权限访问

用命令

cat /etc/.kyinfo

 查询操作系统版本,本次测试版本为

dist_id=Kylin-Server-V10-SP3-General-Release-2303-arm64-2023-03-24 14:51:29

 postgres、postgis源码下载地址

https://www.postgresql.org/ftp/source/
https://download.osgeo.org/postgis/source/

二、使用make方法安装posgresql

安装这两个 yum install -y readline-devel zlib-devel 如果缺少依赖,去查拿有外网的机器下载
解压postgresql-11.2.tar.gz
再解压目录,配置、编译、安装
./configure --prefix=/usr/local/postgresql
make
make install 

三、创建用户postgres,用来启动postgres服务。

创建postgres用户
useradd postgres
passwd postgres
设置postgres安装目录权限
#首先创建一个文件夹,作为数据库的数据存储点
mkdir /usr/local/postgresql/data
chown -R postgres /usr/local/postgresql
初始化数据库
/usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data -E UTF8
配置环境变量.bashrc
vi .bashrc
export PGPORT=6000
export PGUSER=postgres
export PGHOME=/usr/local/postgresql

export PGDATA=/usr/local/postgresql/data

export PATH=${PGHOME}/bin:${PATH}
LD_LIBRARY_PATH=$PGHOME/lib:/usr/local/lib:/usr/local/lib64:/usr/lib64:$LD_LIBRARY_PATH

–读取环境变量

source .bashrc

启动数据库

/usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data -l logfile start

停止数据库

/usr/local/postgresql/bin/pg_ctl stop -D /usr/local/postgresql/data -m fast

四、postgis安装

新建posgtis下载目录,在目录下操作

1.安装gdal

wget http://download.osgeo.org/gdal/2.2.4/gdal-2.2.4.tar.gz
tar xf gdal-2.2.4.tar.gz
cd gdal-2.2.4
./configure
make -j 50
make install -j 50

2.安装proj

wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz
tar xf proj-4.8.0.tar.gz
cd proj-4.8.0
./configure
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local/lib
make -j 50
make install -j 50

3.安装geos

下载 geos-3.6.1-12.ky10.aarch64.rpm

rpm -ivh geos-3.6.1-12.ky10.aarch64.rpm

4.安装json-c

wget https://s3.amazonaws.com/json-c_releases/releases/json-c-0.13.1.tar.gz
tar -xf json-c-0.13.1.tar.gz
./autogen.sh
./configure
make -j 50
make install -j 50

5.安装protobuf-c

wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz
tar xvf protobuf-2.6.1.tar.gz
cd protobuf-2.6.1
./configure
make -j 50
make check
make install -j 50

wget https://github.com/protobuf-c/protobuf-c/releases/download/v1.2.1/protobuf-c-1.2.1.tar.gz
tar xvf protobuf-c-1.2.1.tar.gz
cd protobuf-c-1.2.1
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig // 指定protobuf.pc文件所在
./configure
make -j 50
make install -j 50

 

6.配置ldconfig

cat /etc/ld.so.conf

vim /etc/ld.so.conf

include ld.so.conf.d/*.conf

/usr/local/gdal/lib/
/usr/local/proj/lib/
/usr/local/geos/lib/
/usr/local/postgresql/lib
/usr/local/lib

#保存退出

ldconfig

7.安装postgis(./configure对应目录需校对)

wget http://download.osgeo.org/postgis/source/postgis-2.5.0.tar.gz
tar -xf postgis-2.5.0.tar.gz
cd postgis-2.5.0/

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

make -j 50
make install -j 50

 

验证POSTGIS是否正确安装

# 连接登录postgresql数据库
postgres=# psql -U postgres -h localhost -d postgres -p 5432
用户 postgres 的口令:
psql (11.2)
输入 "help" 来获取帮助信息.

# 创建test数据库
postgres=# create database test;
> CREATE DATABASE

# 切换test数据库
postgres=# \c test;
您现在已经连接到数据库 "test",用户 "postgres".

# 创建postgis扩展
test=# create extension postgis;
CREATE EXTENSION

# 查询全部扩展
test=# select postgis_full_version();
postgis_full_version
----------------------------------------------------------------------------------------------------------------------------------------------------------------
POSTGIS="3.1.0 3.1.0" [EXTENSION] PGSQL="110" GEOS="3.9.0-CAPI-1.14.1" PROJ="7.1.1" LIBXML="2.9.9" LIBJSON="0.12" LIBPROTOBUF="1.2.1" WAGYU="0.5.0 (Internal)"
(1 行记录)

 

配置数据库远程连接

要配置PostgreSQL以允许远程连接,请按照以下步骤操作:

 

编辑postgresql.conf文件:

找到该文件(通常位于/etc/postgresql/版本/main/),并编辑它。取消注释或修改listen_addresses参数,设置为'*'以允许监听所有接口。

listen_addresses = '*'

 

编辑pg_hba.conf文件:

同样找到该文件,并进行编辑。在文件末尾添加规则以允许远程连接:

host all all 0.0.0.0/0 md5

 最后在客户端用navicat连一下测试一下

五、配置超图iportal

postgres中新建iportal数据库

执行下面两个命令

./psql -U postgres -d iportal -f /usr/local/postgresql/share/contrib/postgis-2.5/postgis.sql
./psql -U postgres -d iportal -f /usr/local/postgresql/share/contrib/postgis-2.5/spatial_ref_sys.sql

剩下的按照超图帮助文档来

六、其他的辅助命令

查看所有运行的端口

sudo ss -tuln

查看端口占用情况

netstat -tulnp | grep 8190
#iportal常用端口,shutdown.sh运行后需要多等一会,如果shutdown.sh执行完,进程杀不掉,手动清理以下端口
8190
8195
8292
38194

 包安哪找不着了,用

find /usr -name 包名
find /opt -name 包名