Article directory
-
- Environmental Statement
- Precautions
- Postgresql 12.2 installation
- PostGIS 3.0.1 installation
-
- 1.GEOS compilation and installation
- 2.PROJ compilation and installation
- 3. Protubuf-c compilation and installation
- 4.Json-c compilation and installation
- 5.SFCGAL compilation and installation
- 6.GDAL compilation and installation
- 7.Pcre compilation and installation
- 8.PostGIS compilation and installation
Environmental Statement
This environment is used to adapt to ArcGIS 10.8.1 and ArcGIS Pro 2.6.
name | Version | Related dependencies |
---|---|---|
operating system | centos7.6 | |
postgresql | 12.2 | zlib-devel readline-devel |
postgis | 3.0.1 | gcc g++ |
GEOS | 3.8.0 | |
sqlite3 | 3.32.2 | |
PROJ | 6.3.1 | |
protubuf | 3.15.3 | |
protubuf-c | 1.3.3 | |
json-c | 0.13.1 | |
CMake | 3.16.8 | openssl openssl-devel |
CGAL | 4.14.3 | gmp-devel boost-devel mpfr-devel zlib-devel libxml2-devel |
SFCGAL | 1.3.7 | |
GDAL | 3.0.4 | |
pcre | 8.45 |
PostgreSQL - PostGIS is built on PostgreSQL, so PostgreSQL must be installed.
GNU C Compiler (gcc) - gcc is the most standard C language compiler in Linux. You need to install gcc to compile the source code of PostGIS and other software or function libraries.
GNU Make (gmake or make) - This is also used to compile source code.
Proj4 - The Proj4 reprojection library is used to provide coordinate reprojection functionality in PostGIS.
GEOS - GEOS geometry library, used to support geometric information processing, analysis and other functions in PostGIS. GEOS can also be directly considered as a geometric algorithm library.
LibXML2 - LibXML2 is currently used for some imported functions in PostGIS, such as ST_GeomFromGML() and ST_GeomFromKML().
JSON-C - Currently JSON-C is used to import data in GeoJSON format through the ST_GeomFromGeoJSON() function
GDAL - used for PostGIS support for raster data.
SFCGAL - used for PostGIS support for three-dimensional data.
PostGIS - Extensions for spatial data, spatial indexes, and spatial functions for PostgreSQL.
Precautions
1. Except for a few major components, use YUM to install those that can be installed with YUM.
2. It is best not to specify the installation path during local compilation and installation. Use the default path /usr/local to prevent shared libraries and executable files from being found after the installation is completed.
3. After the environment variables and shared libraries are modified, they must be refreshed and reloaded in time.
4. If you encounter a situation where the variables and shared libraries have been configured and the shared libraries still cannot be read during compilation and installation, you can try closing the ssh session and reconnecting to the server.
5. When installing, install strictly according to the specified version. For version parameters, refer to the official PostGIS instructions.
Postgresql 12.2 installation
1. Install basic libraries
yum -y install zlib-devel readline-devel
2. Create a system user
Execute the following command as root user
# 创建 postgres 用户
adduser postgres
# 给 postgres 用户设置密码
passwd postgres
3. Download the installation package
Download address: https://ftp.postgresql.org/pub/source/v12.2/postgresql-12.2.tar.gz
4. Unzip, compile and install
# 切换为postgres用户
su - postgres
# 进入安装包所在文件夹
cd /home/postgres/software
# 解压安装包
tar -xzvf postgresql-12.2.tar.gz
# 进入解压后的安装包
cd postgresql-12.2
# 进行编译检查,设置安装目录为/home/postgres,构建时开启支持xml数据类型 --with-libxml
./configure --prefix=/home/postgres --with-libxml
# ./configure无误后,执行编译安装
make
make install
5. Environment variable configuration
If you need to use postgresql related commands in any environment, you need to add the contents of $PGHOME/bin to the PATH environment variable and edit the /etc/profile file.
If you are only using it under the postgres user, you need to edit the /home/postgres/.bash_profile file.
vi /etc/profile
# 在最后追加以下内容
export PGHOME=/home/postgres
export PATH=$PGHOME/bin:$PATH
# 如果需要设置一个单独的目录作为数据库目录,则需要明确指定PGDATA环境变量,且该文件夹的owner必须为postgres用户
export PGDATA=/home/postgres/data
If you need the environment variables to take effect immediately, execute the following command
source /etc/profile
source /home/postgres/.bash_profile
6.Initialize the data directory
Initialize the database directory (single instance)
. After configuring the PG bin directory as an environment variable, directly execute the following command for the target database
(let the database directory be /home/postgres/data)
initdb -D /home/postgres/data
If there is a need to adjust the WAL log size (mainly used for archiving and master-slave configuration optimization, once initdb is initialized and specified, it cannot be modified), you can execute the following command (not necessary), the unit of –wal-segsize is MB initdb
- D /data/pgdata --wal-segsize=128
7. Configure remote login
1. Edit the pg_hba.conf file
vi /home/postgres/data/pg_hba.conf
Adding host all all 0.0.0.0/0 md5
to the file means that all users can log in to PostgreSQL through md5 (password) through any IP.
As shown below:
host all all 0.0.0.0/0 md5
2. Edit the postgresql.conf file
vi /home/postgres/data/postgresql.conf
Modify listen_addresses to *, as shown in the figure below:
8. Configure system services
1. Create postgresql.service file
vi /usr/lib/systemd/system/postgresql.service
write
[Unit]
Description=PostgreSQL database server
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
Environment=PGPORT=5432
Environment=PGDATA=/home/postgres/data
OOMScoreAdjust=-1000
ExecStart=/home/postgres/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300
ExecStop=/home/postgres/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/home/postgres/bin/pg_ctl reload -D ${PGDATA} -s
TimeoutSec=300
[Install]
WantedBy=multi-user.target
2.Control commands
systemctl daemon-reload # 启用服务控制守护
systemctl start postgresql # 启动
systemctl stop postgresql # 停止
systemctl restart postgresql # 重启
systemctl enable postgresql # 开机自启
systemctl staus postgresql # 查看状态
9.Set database user password
# 切换到postgres用户
su - postgres
# 直接用postgres超级用户登录,默认不需要密码,psql直接回车就以postgres用户进入了postgres数据库
psql -U postgres
# 修改超级用户密码为:postgres
alter role postgres with pass 'postgres';
# 退出
\q
10.Remote connection test
Access through Navicat connection.
Successful connection is as follows
PostGIS 3.0.1 installation
Note: Install gcc and gcc-c++ first, and other components will depend on them for compilation and installation.
yum install -y gcc gcc-c++
Version view
gcc --version
g++ --version
1.GEOS compilation and installation
Download address: https://download.osgeo.org/geos/geos-3.8.0.tar.bz2
1. Installation command
tar -jxvf geos-3.8.0.tar.bz2
cd geos-3.8.0
./configure
make
make install
2. Test
geos-config --version
2.PROJ compilation and installation
Note: proj6.3.2 depends on sqlite3, and the version of sqlite3 must be ≥ 3.11. The sqlite3 version installed by the system yum is 3.7, so sqlite3 must be upgraded.
2.1.Upgrade sqlite3
Download address: http://www.sqlite.org/2020/sqlite-autoconf-3320200.tar.gz
1.yum installation
yum -y install sqlite sqlite-devel
2. Compile and install
tar zxvf sqlite-autoconf-3320200.tar.gz
cd sqlite-autoconf-3320200/
./configure --prefix=/usr/local/sqlite
make
make install
3.Environment configuration
vi /etc/profile
# 在最后面追加以下内容
export SQLITE3=/usr/local/sqlite
export PATH=$SQLITE3/bin:$PATH
export PKG_CONFIG_PATH=/usr/local/sqlite/lib/pkgconfig
# 刷新
source /etc/profile
4. Replacement version
cp /usr/local/sqlite/bin/sqlite3 /usr/bin/
5. Test
sqlite3 --version
2.2.Install proj
Download address: http://download.osgeo.org/proj/proj-6.3.1.tar.gz
1. Installation command
tar -zxvf proj-6.3.1.tar.gz
cd proj-6.3.1
./configure
make
make install
The successful installation is as follows:
2. Test
proj
3. Protubuf-c compilation and installation
Note: protobuf-c depends on protobuf, so install protobuf first.
3.1. Install protubuf
Download address: https://github.com/protocolbuffers/protobuf/releases/download/v3.15.3/protobuf-all-3.15.3.tar.gz
1. Installation command
tar -zxvf protobuf-all-3.15.3.tar.gz
cd protobuf-3.15.3
./configure
make
make install
The successful installation is as follows:
2. Environment configuration
vi /etc/profile
# 最后面追加以下内容
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
# 刷新
source /etc/profile
3. Test
protoc --version
3.2. Install protobuf-c
Download address: https://github.com/protobuf-c/protobuf-c/releases/download/v1.3.3/protobuf-c-1.3.3.tar.gz
1. Installation command
tar -zxvf protobuf-c-1.3.3.tar.gz
cd protobuf-c-1.3.3
./configure
make
make install
The successful installation is as follows:
2. Test
protoc-c --version
4.Json-c compilation and installation
Download address: https://codeload.github.com/json-c/json-c/tar.gz/refs/tags/json-c-0.13.1-20180305
Installation command
tar -zxvf json-c-json-c-0.13.1-20180305.tar.gz
cd json-c-json-c-0.13.1-20180305/
./configure
make
make install
The successful installation is as follows:
5.SFCGAL compilation and installation
Note: Since the corresponding version of PostGIS is relatively new, the default CMake version of CentOS 7 is insufficient, and a new version of CMake needs to be compiled and installed.
5.1.Install CMake
Download address: https://github.com/Kitware/CMake/releases/download/v3.16.8/cmake-3.16.8.tar.gz
1. Install openssl related libraries
yum -y install openssl openssl-devel
2. Installation command
tar -zxvf cmake-3.16.8.tar.gz
cd cmake-3.16.8
./bootstrap
gmake
make install
The successful installation is as follows:
3. Test
cmake --version
5.2.Install CGAL
Note: sfcgal and pgRouting (network analysis) both rely on boost and cgal. It may happen that boost and cgal are successfully installed and compiled, but sfcgal cannot be compiled, or pgrouting cannot be used after being compiled. The reason is the problem of boost and cgal. Just remember one thing, only install to the default path, do not specify the path.
Download address: https://github.com/CGAL/cgal/releases/download/releases%2FCGAL-4.14.3/CGAL-4.14.3.tar.xz
1. Install relevant dependent libraries
yum -y install gmp-devel boost-devel mpfr-devel zlib-devel libxml2-devel
2. Installation command
tar -xvf CGAL-4.14.3.tar.xz
cd CGAL-4.14.3
mkdir build && cd build
cmake ..
make
make install
The successful installation is as follows:
5.3.Install SFCGAL
Download address: https://codeload.github.com/Oslandia/SFCGAL/tar.gz/refs/tags/v1.3.7
1. Installation command
tar -zxvf SFCGAL-1.3.7.tar.gz
cd SFCGAL-1.3.7
mkdir build && cd build
cmake ..
make
make install
The successful installation is as follows:
After the installation is completed, you need to configure a soft link to libSFCGAL.so to prevent subsequent gdal installation from being unable to find it.
ln -s /usr/local/lib64/libSFCGAL.so /usr/local/lib/libSFCGAL.so
ln -s /usr/local/lib64/libSFCGAL.so.1 /usr/local/lib/libSFCGAL.so.1
6.GDAL compilation and installation
Download address: https://download.osgeo.org/gdal/3.0.4/gdal-3.0.4.tar.gz
1. Installation command
tar -zxvf gdal-3.0.4.tar.gz
cd gdal-3.0.4
./configure
make
make install
The successful installation is as follows:
2. Test
gdal-config --version
7.Pcre compilation and installation
Download address: http://downloads.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.tar.gz
1. Installation command
tar -zxvf pcre-8.45.tar.gz
cd pcre-8.45
./configure
make
make install
The successful installation is as follows:
2. Test
pcre-config --version
8.PostGIS compilation and installation
Download address: https://download.osgeo.org/postgis/source/postgis-3.0.1.tar.gz
1. Installation command
tar -zxvf postgis-3.0.1.tar.gz
cd postgis-3.0.1
./configure --with-pgconfig=/home/postgres/bin/pg_config
make
make install
The successful installation is as follows:
2. Environment configuration
vi /etc/ld.so.conf
# 在最后面追加以下内容
/home/postgres/lib
/usr/local/lib
/usr/local/lib64
# 重新加载
ldconfig
3. Test
3.1 Switch postgres user
su - postgres
3.2 Log in to the database
psql -p 5432 -d postgres -U postgres -W
3.3 Create a test library
create datebase test;
3.4 Enter the test library and create an extension
# 进入测试库
\c test;
# 创建postgis扩展
create extension postgis;
# 验证栅格类数据需要的raster扩展
create extension postgis_raster;
# 如果安装带有sfcgal,验证下三维sfcgal扩展
create extension postgis_sfcgal;
3.5 Check postgresql and postgis versions
select VERSION();
select * from pg_available_extensions WHERE name like 'postgis';