1.下载所需要的包RepoView: PostgreSQL PGDG 14 Updates RPMs(需要下载的包都放在root下即可)
下载地址RepoView:PostgreSQL PGDG 更新 RPM
下载下面三个包:
postgresql14-14.11-1PGDG.rhel7.x86_64.rpm
postgresql14-libs-14.11-1PGDG.rhel7.x86_64.rpm
postgresql14-server-14.11-1PGDG.rhel7.x86_64.rpm
2.按照以下顺序安装rpm包
rpm -ivh postgresql14-libs-14.11-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql14-14.11-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql14-server-14.11-1PGDG.rhel7.x86_64.rpm
可能出现的问题:安装过程中提示libicu报错,则需要安装libicu包:libicu包下载地址
http://mirror.centos.org/centos/7/os/x86_64/Packages/libicu-50.2-4.el7_7.x86_64.rpm
rpm -ivh libicu-50.2-4.el7_7.x86_64.rpm
3.初始化Postgresql
ps:因为安装好后postgres用户默认没有密码,需要切换root用户设置密码,不然无法切换用户。
sudo -i //切换root用户
passwd postgres #重设密码
mkdir -p /home/pgsql/14/data
chown -R postgres:postgres /home/pgsql //改文件夹所有者
chmod -R 777 /data/pgsql //赋权
su - postgres
/usr/pgsql-14/bin/initdb -D /home/pgsql/14/data #以指定数据目录初始化
4.修改配置
1)修改远程访问
vi /home/pgsql/14/data/postgresql.conf
需要修改的参数项:
listen_addresses = '*' //配置为允许远程访问
port = 6432 //将前面的#号删掉,默认端口5432,我的是8432,按实际情况修改
max_connections = 2000 //设置最大连接数2000,默认100
shared_buffers = 1024MB //默认128MB,此参数决定有多少内存可以被PostgreSQL用于缓存数据
maintenance_work_mem = 256MB //默认64MB,数据库一个操作的内存使用上限
2)配置客户端
vim /home/pgsql/14/data/pg_hba.conf
将访问数据库的客户端IP增加一行
host all all 0.0.0.0/0 md5
3)修改service文件
cd /usr/lib/systemd/system //进入system下
vim postgresql-14.service
修改数据存储目录
Environment=PGDATA=/home/pgsql/14/data
psql连接数据库socket报错:
[root@pms3ecs02 ~]# psql -U postgres
psql: error: connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
例如更改数据库的端口为6432,则软连接:
ln -s /run/postgresql/.s.PGSQL.6432 /run/postgresql/.s.PGSQL.5432
5.刷新并重启
systemctl daemon-reload
systemctl start postgresql-14
————————————————
安装postgis
外网机下载安装包和依赖:
1:添加仓库源
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2:下载对应pg版本兼容的gis
yum install -y yum-utils
yum search postgis
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* epel: mirrors.bfsu.edu.cn
========================================================================================================== N/S matched: postgis ===========================================================================================================
postgis-docs.x86_64 : Extra documentation for PostGIS
postgis-utils.x86_64 : The utils for PostGIS
postgis25_12-client.x86_64 : Client tools and their libraries of PostGIS
postgis25_12-devel.x86_64 : Development headers and libraries for PostGIS
postgis25_12-docs.x86_64 : Extra documentation for PostGIS
postgis25_12-gui.x86_64 : GUI for PostGIS
postgis25_12-utils.x86_64 : The utils for PostGIS
postgis30_12-client.x86_64 : Client tools and their libraries of PostGIS
postgis30_12-devel.x86_64 : Development headers and libraries for PostGIS
postgis30_12-docs.x86_64 : Extra documentation for PostGIS
postgis30_12-gui.x86_64 : GUI for PostGIS
postgis30_12-utils.x86_64 : The utils for PostGIS
postgis30_13-client.x86_64 : Client tools and their libraries of PostGIS
postgis30_13-devel.x86_64 : Development headers and libraries for PostGIS
postgis30_13-docs.x86_64 : Extra documentation for PostGIS
postgis30_13-gui.x86_64 : GUI for PostGIS
postgis30_13-utils.x86_64 : The utils for PostGIS
postgis31_12-client.x86_64 : Client tools and their libraries of PostGIS
postgis31_12-devel.x86_64 : Development headers and libraries for PostGIS
postgis31_12-docs.x86_64 : Extra documentation for PostGIS
postgis31_12-gui.x86_64 : GUI for PostGIS
postgis31_12-llvmjit.x86_64 : Just-in-time compilation support for postgis31
postgis31_12-utils.x86_64 : The utils for PostGIS
postgis31_13-client.x86_64 : Client tools and their libraries of PostGIS
postgis31_13-devel.x86_64 : Development headers and libraries for PostGIS
postgis31_13-docs.x86_64 : Extra documentation for PostGIS
postgis31_13-gui.x86_64 : GUI for PostGIS
postgis31_13-llvmjit.x86_64 : Just-in-time compilation support for postgis31
postgis31_13-utils.x86_64 : The utils for PostGIS
postgis31_14-client.x86_64 : Client tools and their libraries of PostGIS
postgis31_14-devel.x86_64 : Development headers and libraries for PostGIS
postgis31_14-docs.x86_64 : Extra documentation for PostGIS
postgis31_14-gui.x86_64 : GUI for PostGIS
postgis31_14-llvmjit.x86_64 : Just-in-time compilation support for postgis31
postgis31_14-utils.x86_64 : The utils for PostGIS
postgis32_12-client.x86_64 : Client tools and their libraries of PostGIS
postgis32_12-devel.x86_64 : Development headers and libraries for PostGIS
postgis32_12-docs.x86_64 : Extra documentation for PostGIS
postgis32_12-gui.x86_64 : GUI for PostGIS
postgis32_12-llvmjit.x86_64 : Just-in-time compilation support for postgis32
postgis32_12-utils.x86_64 : The utils for PostGIS
postgis32_13-client.x86_64 : Client tools and their libraries of PostGIS
postgis32_13-devel.x86_64 : Development headers and libraries for PostGIS
postgis32_13-docs.x86_64 : Extra documentation for PostGIS
postgis32_13-gui.x86_64 : GUI for PostGIS
postgis32_13-llvmjit.x86_64 : Just-in-time compilation support for postgis32
postgis32_13-utils.x86_64 : The utils for PostGIS
postgis32_14-client.x86_64 : Client tools and their libraries of PostGIS
postgis32_14-devel.x86_64 : Development headers and libraries for PostGIS
postgis32_14-docs.x86_64 : Extra documentation for PostGIS
postgis32_14-gui.x86_64 : GUI for PostGIS
postgis32_14-llvmjit.x86_64 : Just-in-time compilation support for postgis32
postgis32_14-utils.x86_64 : The utils for PostGIS
postgis32_15-client.x86_64 : Client tools and their libraries of PostGIS
postgis32_15-devel.x86_64 : Development headers and libraries for PostGIS
postgis32_15-docs.x86_64 : Extra documentation for PostGIS
postgis32_15-gui.x86_64 : GUI for PostGIS
postgis32_15-llvmjit.x86_64 : Just-in-time compilation support for postgis32
postgis32_15-utils.x86_64 : The utils for PostGIS
postgis33_12-client.x86_64 : Client tools and their libraries of PostGIS
postgis33_12-devel.x86_64 : Development headers and libraries for PostGIS
postgis33_12-docs.x86_64 : Extra documentation for PostGIS
postgis33_12-gui.x86_64 : GUI for PostGIS
postgis33_12-llvmjit.x86_64 : Just-in-time compilation support for postgis33
postgis33_12-utils.x86_64 : The utils for PostGIS
postgis33_13-client.x86_64 : Client tools and their libraries of PostGIS
postgis33_13-devel.x86_64 : Development headers and libraries for PostGIS
postgis33_13-docs.x86_64 : Extra documentation for PostGIS
postgis33_13-gui.x86_64 : GUI for PostGIS
postgis33_13-llvmjit.x86_64 : Just-in-time compilation support for postgis33
postgis33_13-utils.x86_64 : The utils for PostGIS
postgis33_14-client.x86_64 : Client tools and their libraries of PostGIS
postgis33_14-devel.x86_64 : Development headers and libraries for PostGIS
postgis33_14-docs.x86_64 : Extra documentation for PostGIS
postgis33_14-gui.x86_64 : GUI for PostGIS
postgis33_14-llvmjit.x86_64 : Just-in-time compilation support for postgis33
postgis33_14-utils.x86_64 : The utils for PostGIS
postgis33_15-client.x86_64 : Client tools and their libraries of PostGIS
postgis33_15-devel.x86_64 : Development headers and libraries for PostGIS
postgis33_15-docs.x86_64 : Extra documentation for PostGIS
postgis33_15-gui.x86_64 : GUI for PostGIS
postgis33_15-llvmjit.x86_64 : Just-in-time compilation support for postgis33
postgis33_15-utils.x86_64 : The utils for PostGIS
SFCGAL.x86_64 : C++ wrapper library around CGAL for PostGIS
pgrouting_12.x86_64 : Routing functionality for PostGIS
pgrouting_13.x86_64 : Routing functionality for PostGIS
pgrouting_14.x86_64 : Routing functionality for PostGIS
pgrouting_15.x86_64 : Routing functionality for PostGIS
postgis.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis25_12.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis30_12.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis30_13.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis31_12.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis31_13.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis31_14.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis32_12.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis32_13.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis32_14.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis32_15.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis33_12.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis33_13.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis33_14.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis33_15.x86_64 : Geographic Information Systems Extensions to PostgreSQL
Name and summary matches only, use "search all" for everything.
yumdownloader --resolve --destdir /tmp/ postgis32_14
[root@192-168-31-195 tmp]# ll
total 73380
-rw-r--r-- 1 root root 36921 Jun 3 2022 armadillo-10.8.2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 103424 Feb 17 2014 arpack-3.1.3-2.el7.x86_64.rpm
-rw-r--r-- 1 root root 4699420 Aug 10 2017 atlas-3.10.1-12.el7.x86_64.rpm
-rw-r--r-- 1 root root 408548 Aug 10 2017 blas-3.4.2-8.el7.x86_64.rpm
-rw-r--r-- 1 root root 53176 Apr 4 2020 boost-date-time-1.53.0-28.el7.x86_64.rpm
-rw-r--r-- 1 root root 173480 Apr 4 2020 boost-serialization-1.53.0-28.el7.x86_64.rpm
-rw-r--r-- 1 root root 40732 Apr 4 2020 boost-system-1.53.0-28.el7.x86_64.rpm
-rw-r--r-- 1 root root 58924 Apr 4 2020 boost-thread-1.53.0-28.el7.x86_64.rpm
-rw-r--r-- 1 root root 540436 Oct 2 2017 cfitsio-3.370-10.el7.x86_64.rpm
-rw-r--r-- 1 root root 260496 Jan 3 00:48 CGAL-4.7-1.rhel7.1.x86_64.rpm
-rw-r--r-- 1 root root 64540 Jul 10 2014 CharLS-1.0-5.el7.x86_64.rpm
-rw-r--r-- 1 root root 65788 Jul 4 2014 dejavu-fonts-common-2.33-6.el7.noarch.rpm
-rw-r--r-- 1 root root 1482820 Jul 4 2014 dejavu-sans-fonts-2.33-6.el7.noarch.rpm
-rw-r--r-- 1 root root 260512 Nov 12 2018 fontconfig-2.13.0-4.3.el7.x86_64.rpm
-rw-r--r-- 1 root root 10116 Jul 4 2014 fontpackages-filesystem-1.44-8.el7.noarch.rpm
-rw-r--r-- 1 root root 32454 Dec 17 2021 freexl-1.0.6-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 8449208 Jan 3 00:48 gdal34-libs-3.4.3-4.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 884392 Jan 3 00:49 geos310-3.10.3-1.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 662508 Jan 3 00:49 geos39-3.9.2-1.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 40964 Jul 4 2014 giflib-4.1.6-9.el7.x86_64.rpm
-rw-r--r-- 1 root root 813196 Jul 28 2014 gpsbabel-1.5.0-2.el7.x86_64.rpm
-rw-r--r-- 1 root root 1682124 Sep 16 2021 hdf5-1.8.12-13.el7.x86_64.rpm
-rw-r--r-- 1 root root 154048 Nov 12 2018 jasper-libs-1.900.1-33.el7.x86_64.rpm
-rw-r--r-- 1 root root 47560 Jul 4 2014 jbigkit-libs-2.0-11.el7.x86_64.rpm
-rw-r--r-- 1 root root 5629884 Aug 11 2017 lapack-3.4.2-8.el7.x86_64.rpm
-rw-r--r-- 1 root root 154032 Nov 21 2016 lcms2-2.6-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 34814 Feb 12 2019 libaec-1.0.4-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 433272 Jul 19 2014 libdap-3.13.1-2.el7.x86_64.rpm
-rw-r--r-- 1 root root 97264 Jan 3 00:49 libgeotiff16-1.6.0-6.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 30280 Jan 3 00:49 libgeotiff16-devel-1.6.0-6.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 308088 Oct 15 2020 libgfortran-4.8.5-44.el7.x86_64.rpm
-rw-r--r-- 1 root root 91596 Nov 12 2018 libglvnd-1.0.1-0.8.git5baa1e5.el7.x86_64.rpm
-rw-r--r-- 1 root root 127648 Nov 12 2018 libglvnd-glx-1.0.1-0.8.git5baa1e5.el7.x86_64.rpm
-rw-r--r-- 1 root root 32864 Feb 5 2014 libgta-1.0.4-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 67720 Aug 11 2017 libICE-1.0.9-9.el7.x86_64.rpm
-rw-r--r-- 1 root root 7202728 Mar 25 2020 libicu-50.2-4.el7_7.x86_64.rpm
-rw-r--r-- 1 root root 137752 Aug 23 2019 libjpeg-turbo-1.2.90-8.el7.x86_64.rpm
-rw-r--r-- 1 root root 194944 Oct 15 2020 libquadmath-4.8.5-44.el7.x86_64.rpm
-rw-r--r-- 1 root root 40160 Nov 25 2015 libSM-1.2.2-2.el7.x86_64.rpm
-rw-r--r-- 1 root root 2492976 Jan 3 00:49 libspatialite43-4.3.0a-15.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 75268 Jan 3 00:49 libspatialite43-devel-4.3.0a-15.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 176172 Oct 15 2020 libtiff-4.0.3-35.el7.x86_64.rpm
-rw-r--r-- 1 root root 485288 Oct 15 2020 libtiff-devel-4.0.3-35.el7.x86_64.rpm
-rw-r--r-- 1 root root 50076 Apr 13 2017 libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm
-rw-r--r-- 1 root root 19536 Jul 4 2014 libusb-0.1.4-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 62908 Apr 25 2018 libusbx-1.0.21-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 174472 May 5 2023 libwebp-0.3.0-11.el7.x86_64.rpm
-rw-r--r-- 1 root root 621888 Mar 21 23:27 libX11-1.6.7-5.el7_9.x86_64.rpm
-rw-r--r-- 1 root root 168524 Mar 21 23:27 libX11-common-1.6.7-5.el7_9.noarch.rpm
-rw-r--r-- 1 root root 29784 Jul 4 2014 libXau-1.0.8-2.1.el7.x86_64.rpm
-rw-r--r-- 1 root root 218900 Nov 12 2018 libxcb-1.13-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 20916 Jul 4 2014 libXdamage-1.1.4-4.1.el7.x86_64.rpm
-rw-r--r-- 1 root root 39572 Nov 25 2015 libXext-1.3.3-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 18684 Aug 11 2017 libXfixes-5.0.3-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 7340 Nov 25 2015 libxshmfence-1.2-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 247560 Oct 15 2020 libxslt-1.1.28-6.el7.x86_64.rpm
-rw-r--r-- 1 root root 17972 Aug 11 2017 libXxf86vm-1.1.4-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 299372 Apr 5 2023 libzstd-1.5.5-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 169812 Nov 18 2020 mesa-libGL-18.3.4-12.el7_9.x86_64.rpm
-rw-r--r-- 1 root root 46956 Nov 18 2020 mesa-libglapi-18.3.4-12.el7_9.x86_64.rpm
-rw-r--r-- 1 root root 200876 Jul 4 2014 mesa-libGLU-9.0.0-4.el7.x86_64.rpm
-rw-r--r-- 1 root root 208316 Jul 4 2014 mpfr-3.1.1-4.el7.x86_64.rpm
-rw-r--r-- 1 root root 709772 Dec 13 2015 netcdf-4.3.3.1-5.el7.x86_64.rpm
-rw-r--r-- 1 root root 224372 Jan 3 00:49 ogdi41-4.1.0-2.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 4583548 Sep 30 2018 openblas-openmp-0.3.3-2.el7.x86_64.rpm
-rw-r--r-- 1 root root 156596 Feb 20 2020 openjpeg2-2.3.1-3.el7_7.x86_64.rpm
-rw-r--r-- 1 root root 88128 Nov 12 2018 openjpeg-libs-1.5.1-18.el7.x86_64.rpm
-rw-r--r-- 1 root root 95568 Apr 25 2018 pciutils-3.5.1-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 206176 Aug 11 2017 pcre2-10.23-2.el7.x86_64.rpm
-rw-r--r-- 1 root root 806344 Nov 18 2020 poppler-0.26.5-43.el7.1.x86_64.rpm
-rw-r--r-- 1 root root 2254884 Jul 4 2014 poppler-data-0.4.6-3.el7.noarch.rpm
-rw-r--r-- 1 root root 4108764 Jan 3 01:54 postgis32_14-3.2.5-1.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 1565852 Feb 8 05:27 postgresql14-14.11-1PGDG.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 707760 Feb 8 05:27 postgresql14-contrib-14.11-1PGDG.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 279632 Feb 8 05:27 postgresql14-libs-14.11-1PGDG.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 5748144 Feb 8 05:27 postgresql14-server-14.11-1PGDG.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 2635440 Jan 3 00:50 proj72-7.2.1-1.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 4785208 Nov 18 2020 qt-4.8.7-9.el7_9.x86_64.rpm
-rw-r--r-- 1 root root 18396 Oct 15 2020 qt-settings-19-23.12.el7.centos.noarch.rpm
-rw-r--r-- 1 root root 15476 Jan 3 00:48 SFCGAL-1.3.1-2.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 1731796 Jan 3 00:48 SFCGAL-libs-1.3.1-2.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 65176 Feb 10 2023 shapelib-1.3.0-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 639692 Jan 3 00:51 sqlite33-3.30.1-6.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 563836 Jan 3 00:51 sqlite33-libs-3.30.1-6.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 184152 Dec 7 2017 SuperLU-5.2.0-5.el7.x86_64.rpm
-rw-r--r-- 1 root root 423152 Aug 23 2019 unixODBC-2.3.1-14.el7.x86_64.rpm
-rw-r--r-- 1 root root 899740 Mar 5 2020 xerces-c-3.1.1-10.el7_7.x86_64.rpm
有可能回用到开发者服务包:postgresql14-devel-14.11-1PGDG.rhel7.x86_64.rpm
传输安装包到离线机器:
将下载的所有RPM包传输到离线安装的CentOS 7机器上
bash
yum localinstall -y *.rpm
su - postgres
createdb gisdb
连接到数据库:
bash
psql gisdb
在数据库中启用PostGIS扩展:
sql
CREATE EXTENSION postgis;
检查PostGIS是否已正确安装,可以执行以下命令:
sql
SELECT PostGIS_Version();
这将显示安装的PostGIS版本,确认扩展已正确安装。
退出PostgreSQL:
sql
\q
回到系统用户:
bash
exit