一、安装部署GeoServer
1、下载GeoServer
官网:http://geoserver.org/
教程:GeoServer使用 OSGeo中国中心 | 开放地理空间实验室
文档:GeoServer用户手册 — GeoServer 2.19.x User Manual (osgeo.cn)
wget https://nchc.dl.sourceforge.net/project/geoserver/GeoServer/2.19.0/geoserver-2.19.0-bin.zip
2、解压GeoServer
如果没有安装解压工具,请使用命令安装unzip
sudo yum install unzip -y
创建geoserver目录并解压
mkdir geoserver && unzip geoserver-2.16.2-war.zip -d geoserver
3、启动
[root@localhost geoserver]# cd bin/
[root@localhost bin]# nohup ./startup.sh
4、访问地址
http://172.0.0.1:8090/geoserver/web/
使用默认的用户名 admin
和密码 geoserver
登录,就能看到主界面了
5、修改GeoServer数据目录
webapps/geoserver/WEB-INF/web.xml
<web-app>
...
<context-param>
<param-name>GEOSERVER_DATA_DIR</param-name>
<param-value>/home/geoserver_data</param-value>
</context-param>
...
</web-app>
6、解决 GeoServer 的跨域(CORS)问题
\webapps\geoserver\WEB-INF
容器版本参考一下这个路径,修改这下面的:web.xml
用任意一种文本编辑器打开它,找到如下两个片段去掉注释:
<!-- Uncomment following filter to enable CORS
<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
<init-param>
<param-name>chainPreflight</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>allowedOrigins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>allowedMethods</param-name>
<param-value>GET,POST,PUT,DELETE,HEAD,OPTIONS</param-value>
</init-param>
<init-param>
<param-name>allowedHeaders</param-name>
<param-value>*</param-value>
</init-param>
</filter>
-->
<!-- Uncomment following filter to enable CORS
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->
重启。
二、安装部署PostGreSql
1、安装PostgreSQL
PostgreSQL: Linux downloads (Red Hat family)
# 安装版本库的RPM:
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# 禁用内置的PostgreSQL模块:
sudo dnf -qy module disable postgresql
# 安装PostgreSQLL:
sudo dnf install -y postgresql13-server
# 可选择初始化数据库并启用自动启动:
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13
2、创建存储目录
[root@localhost ~] cd /home
[root@localhost ~] mkdir postgresql
[root@localhost ~] chmod 777 /home/postgresql
3、初始化数据库
[root@localhost ~] su postgres
[root@localhost ~] /usr/pgsql-13/bin/initdb -D /home/postgresql/data
4、设置开机启动,启动数据库
systemctl enable postgresql-13 #设置开机启动
systemctl start postgresql-13 #启动postgresql
#查看启动效果:
#方法一:
ps -ef | grep postgre
#方法二:
systemctl status postgresql-13
5、数据库目录授权
1)创建postgres用户
[root@localhost ~]# groupadd postgres //用户
[root@localhost ~]# useradd postgres -g postgres
[root@localhost ~]# passwd postgres
更改用户 postgres 的密码 。
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新
2)设置用户和权限
[root@localhost ~]#chown -R postgres:postgres /home/postgresql
[root@localhost ~]#chmod -R 0700 /home/postgresql/data
3) 切换postgres启动
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ /usr/pgsql-13/bin/pg_ctl -D /home/postgresql/data/ -l logfile restart
等待服务器进程启动 .... 完成
服务器进程已经启动
重启:
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ /usr/pgsql-13/bin/pg_ctl -D /home/postgresql/data/ -l logfile start
等待服务器进程启动 .... 完成
服务器进程已经启动
[postgres@localhost ~]$
6、修改数据库的密码
su postgres
bash-4.4$ /usr/pgsql-13/bin/pg_ctl -D /home/postgresql/data/ -l logfile start
bash-4.4$ psql
psql (13.2)
输入 "help" 来获取帮助信息.
postgres=# ALTER USER postgres WITH PASSWORD 'slsd1959';
ALTER ROLE
postgres=# exit
bash-4.4$ exit
exit
7、修改配置文件
7.1 修改指定的数据目录
vi /usr/lib/systemd/system/postgresql-13.service
# 执行前须执行命令:
# 1. mkdir -p /data/pgsql/
# 2. chown postgres:postgres -R /data/pgsql
# 3. chmod 700 /data/pgsql/data -R
#修改Environment=PGDATA=/var/lib/pgsql/11/data/为
Environment=PGDATA=/home/postgresql/data/
7.2 修改数据目录
vi /data/pgsql/data/postgresql.conf
#执行前须执行命令:
# 1. mkdir -p /data/pgsql/
# 2. chown postgres:postgres -R /data/pgsql
# 3. chmod 700 /data/pgsql/data -R
#修改data_directory:
data_directory = '/home/postgresql/data/'
其它配置修改:
log_directory = 'log'
max_connections = 100
7.3 设置远程连接
vim /home/postgresql/data/pg_hba.conf
添加内容:host all all 0.0.0.0/0 md5
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
host all all 0.0.0.0/0 md5
开放端口号:
1、开启防火墙
systemctl start firewalld
2、开放指定端口
firewall-cmd --zone=public --add-port=5432/tcp --permanent
命令含义:
--zone #作用域
--add-port=5432/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
3、重启防火墙
firewall-cmd --reload
4、查看端口号
netstat -ntlp //查看当前所有tcp端口·
netstat -ntulp |grep 5432 //查看所有9000端口使用情况·
vim /home/postgresql/data/postgresql.conf
修改内容:
listen_addresses = ‘*’
port = 5432
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
8、配置开机启动数据库
创建脚本
mkdir /home/postgresql/bin
cd /home/postgresql/bin
vim startup.sh
内容:
#! /bin/bash
su postgres<<!
cd /home/postgresql
/usr/pgsql-13/bin/pg_ctl -D /home/postgresql/data -l logfile start
exit $?
!
9、查看数据库
postgres=# \l
数据库列表
名称 | 拥有者 | 字元编码 | 校对规则 | Ctype | 存取权限
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 |
template0 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 行记录)
三、安装部署PostGIS
1、安装PostGIS
在 CentOS 8 上安装 PostGIS 3.1 需要几个步骤。以root身份运行这些步骤。
- 安装PostgreSQL repo RPM
dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
- 禁用postgresql模块
dnf -qy module disable postgresql
- 安装EPEL repo RPM
dnf -y install epel-release
- 启用PowerTools repo(某些依赖项需要)
dnf -y config-manager --set-enabled PowerTools
- 安装PostGIS
dnf -y install postgis31_13
注意:如果安装的时候依赖出现问题,可参考https://blog.csdn.net/avi9111/article/details/113100002
依次执行命令,重新生成cache后,再执行安装PostGIS命令
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
yum clean all
yum makecache
- 安装成功后可以利用命令查看安装信息
[root@localhost ~]# rpm -qi postgis31_13
Name : postgis31_13
Version : 3.1.1
Release : 4.rhel8
Architecture: x86_64
Install Date: 2021年04月30日 星期五 09时41分53秒
Group : Unspecified
Size : 35096901
License : GPLv2+
Signature : DSA/SHA1, 2021年03月29日 星期一 05时13分28秒, Key ID 1f16d2e1442df0f8
Source RPM : postgis31_13-3.1.1-4.rhel8.src.rpm
Build Date : 2021年03月29日 星期一 05时09分04秒
Build Host : koji-rhel8-x86-64-pgbuild
Relocations : (not relocatable)
Vendor : PostgreSQL Global Development Group
URL : http://www.postgis.net/
Summary : Geographic Information Systems Extensions to PostgreSQL
Description :
PostGIS adds support for geographic objects to the PostgreSQL object-relational
database. In effect, PostGIS "spatially enables" the PostgreSQL server,
allowing it to be used as a backend spatial database for geographic information
systems (GIS), much like ESRI's SDE or Oracle's Spatial extension. PostGIS
follows the OpenGIS "Simple Features Specification for SQL" and has been
certified as compliant with the "Types and Functions" profile.
2、启用PostGIS Spatial功能
[root@localhost /]# su - postgres # 切换postgres用户并进入数据库
[postgres@localhost ~]$ su postgres
密码:
bash-4.4$ psql -d test_db
psql (13.2)
输入 "help" 来获取帮助信息.
test_db=# CREATE EXTENSION postgis; # 开启PostGIS扩展
CREATE EXTENSION
test_db=# SELECT PostGIS_version();
postgis_version
---------------------------------------
3.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1 # 查看postgis扩展信息
(1 行记录)
test_db=# \q
bash-4.4$ exit
exit
PostgreSQL和PostGIS就全部安装完成!