centos7 完全离线安装postgresql12.5和postgis3.0插件教程

                                                        centos7 完全离线安装postgresql12.5和postgis3.0插件教程

1,postgresql12.5安装包以及postgis3.0插件和相关依赖下载地址:

链接:https://pan.baidu.com/s/12GFnU_kdCJ_4UtJ3F03oXw 
提取码:post 
复制这段内容后打开百度网盘手机App,操作更方便哦--来自百度网盘超级会员V3的分享

关于离线安装包内容的说明:文件内包含postgresql12.5的安装包,postgis3.0安装包,以及所需要的4个依赖和2个json-c的依赖的rpm包。

2,安装前的环境准备

本地仓库,仓库使用系统安装ISO文件或者从官网下载everything ISO文件,本地仓库搭建好后,执行命令:

yum install gcc gcc-c++ openssl openssl-devel  readline readline-devel -y

注意,全部安装都是离线化,并且都是源码编译安装方式。操作系统使用的为centos7.2.

新增普通用户postgres,新增用户命令为:useradd postgres。

将第一步下载下来的文件上传到服务器上。

3,postgresql12.5的安装

找到文件postgresql-12.5.tar.bz2解压,解压命令为:tar  jxf postgresql-12.5.tar.bz2

进入解压后的目录 执行命令:./configure --prefix=/usr/local/pgsql &&make&&make install

如上图即成功安装,postgresql十分人性化,替运维准备了启动脚本:

源码包内自带有启动脚本,该脚本路径如下(注意,是源码包,不是预编译时指定的那个/usr/local/pgsql):

[root@centos7 start-scripts]# pwd
/usr/local/src/postgresql-9.5.24/contrib/start-scripts
[root@centos7 start-scripts]# ll
total 8
-rw-r--r-- 1 1107 1107 1529 Nov 10 06:34 freebsd
-rw-r--r-- 1 1107 1107 3642 Nov 10 06:34 linux
drwxrwxrwx 2 1107 1107   84 Nov 10 06:45 macos
drwxrwxrwx 2 1107 1107   87 Nov 10 06:45 osx

cp /usr/local/src/postgresql-9.5.24/contrib/start-scripts/linux /etc/init.d/pgsql  &&chmod +x /etc/init.d/pgsql && chown -Rf /etc/init.d/pgsql #复制启动脚本到自启动目录下并赋予可执行权限,并将属组更改为postgres用户。(更改属组才可以使用root用户利用service命令启停服务)。

该脚本内使用的变量要和环境变量设置的一一对应,环境变量的设置如下: vim  /etc/profile

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

初始化pg的数据库

由于环境变量已经设置好了,因此 直接执行  initdb 即可。(这一步类似二进制安装),这里需要使用普通用户执行这个命令,也就是su 切换到普通用户 postgres。

如果想重新指定 可使用命令 initdb -d你想要的路径   (需要说明的是,目标路径必须为空,并且postgres用户对此路径有权限读写) ,如果不-d参数指定,那么,该初始化程序会使用/etc/profile 内定义的数据库路径。

下图为初始化数据库成功的演示。

[postgres@centos2 ~]$ initdb
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... PRC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /usr/local/pgsql/data -l logfile start

使用启动脚本管理pg服务的启停以及状态查询

service pgsql start |stop |status |restart

[root@centos2 postgresql-12.5]# service pgsql status
pg_ctl: no server running
[root@centos2 postgresql-12.5]# service pgsql start
Starting PostgreSQL: ok
[root@centos2 postgresql-12.5]# ps -ef | grep postgre
postgres  39004      1  0 20:21 ?        00:00:00 /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
postgres  39006  39004  0 20:21 ?        00:00:00 postgres: checkpointer   
postgres  39007  39004  0 20:21 ?        00:00:00 postgres: background writer   
postgres  39008  39004  0 20:21 ?        00:00:00 postgres: walwriter   
postgres  39009  39004  0 20:21 ?        00:00:00 postgres: autovacuum launcher   
postgres  39010  39004  0 20:21 ?        00:00:00 postgres: stats collector   
postgres  39011  39004  0 20:21 ?        00:00:00 postgres: logical replication launcher   
root      39013   1229  0 20:21 pts/0    00:00:00 grep --color=auto postgre

上图为服务启动成功的截图

4,高版本cmake的安装配置

本例中,我是解压后重命名为cmake,路径为 /usr/local/cmake,环境变量配置为:vim /etc/profile

CMAKE_HOME=/usr/local/cmake
PATH=$PATH:$CMAKE_HOME/bin
export PATH

5,依赖gdal的编译安装

tar xf gdal-2.1.3.tar.xz 
    cd gdal-2.1.3/ 
    ./configure --prefix=/usr/local/gdal
    echo $?
     make && make install

这里需要说明一下,指定路径是为了后面的postgis引用方便,如果默认,环境变量不太好配置。 

编译成功的截图:

6,依赖geos的编译安装

tar jxf geos-3.8.0.tar.bz2
cd geos-3.8.0/src
cmake ../
make && make install

 编译成功的截图:

7,依赖proj4的编译安装

 tar zxf proj-4.9.3.tar.gz 
 cd proj-4.9.3/
  ./configure 
    make && make install
    echo $?

 编译成功的截图(有可执行程序proj了):

8,json-c的编译安装

在编译前,需要将文件夹内的两个rpm包安装,这两个rpm包是json-c的强依赖,安装命令为:rpm -ivh *.rpm

下图为json-c的正式编译步骤:

  unzip mirrors-json-c-master.zip 
  cd json-c/
  mkdir build
  cd build/
     cmake ../
     make && make install

9,postgis的编译安装

vim /etc/ld.so.conf

/usr/local/lib
/usr/local/lib64
/usr/local/pgsql/lib

这里啰嗦一句,第三行的引用是postgresql的lib库位置,pg安装在哪就写哪,本例中因为pg是安装在 /usr/local/pgsql 下,因此这么写的,一定要注意哦!!! 

需要像/etc/profile 一样,让它生效,命令为:ldconfig

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH:/usr/local/include/

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-gdalconfig=/usr/local/gdal/bin/gdal-config

make && make install
 

预编译成功的截图:

--------------- Extensions --------------- 
  PostGIS Raster:                     enabled
  PostGIS Topology:                   enabled
  SFCGAL support:                     disabled
  Address Standardizer support:       disabled

 -------- Documentation Generation -------- 
  xsltproc:             /usr/bin/xsltproc
  xsl style sheets:     
  dblatex:              
  convert:              
  mathml2.dtd:          http://www.w3.org/Math/DTD/mathml2/mathml2.dtd

 编译成功的截图:

for OLD_VERSION in 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.3.10 2.3.11 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 3.0.0alpha4 3.0.0beta1 3.0.0rc1 3.0.0rc2; do \
	ln -fs "${tpl}" /usr/local/pgsql/datadir/extension/postgis_topology--$OLD_VERSION--3.0.0.sql; \
done
/usr/bin/install -c -m 644 .//postgis_topology.control '/usr/local/pgsql/datadir/extension/'
/usr/bin/install -c -m 644  postgis_topology.control sql/postgis_topology--3.0.0.sql sql/postgis_topology--unpackaged--3.0.0.sql  '/usr/local/pgsql/datadir/extension/'
make[2]: Leaving directory `/root/postgis-3.0.0/extensions/postgis_topology'
make[1]: Leaving directory `/root/postgis-3.0.0/extensions'
[root@centos6 postgis-3.0.0]# echo $?
0

启动postgresql服务,进入命令行操作界面,执行以下命令: 

create extension postgis

select * from pg_available_extensions where name like 'postgis%';

插件正常的状态为至少三行。

postgres=# select * from pg_available_extensions where name like 'postgis%';
          name          | default_version | installed_version |                               comment                               
------------------------+-----------------+-------------------+---------------------------------------------------------------------
 postgis                | 3.0.0           | 3.0.0             | PostGIS geometry, geography, and raster spatial types and functions
 postgis_tiger_geocoder | 3.0.0           |                   | PostGIS tiger geocoder and reverse geocoder
 postgis_topology       | 3.0.0           |                   | PostGIS topology spatial types and functions
 postgis_raster         | 3.0.0           |                   | PostGIS raster types and functions
(4 rows)

猜你喜欢

转载自blog.csdn.net/alwaysbefine/article/details/114874242