Ubuntu16.04 Postgresql & PostGIS在线安装部署


Postgresql安装

  1. 添加PostgreSQl数据库来源,参考官方说明
# Add PostgreSQL apt repository
echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main' >> /etc/apt/sources.list.d/pgdg.list

# Import the repository signing key, and update the package lists
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
  1. 安装PostgreSQL
 sudo apt-get update
 # 备注:apt这块没有9.4版本,可以换成9.5等其他版本
 sudo apt-get install postgresql-10

3.修改用户postgres的密码

sudo -u postgres psql -c "alter user postgres with password 'postgres';"
  1. 修改配置文件
# 1.修改配置文件 pg_hba.conf,如果找不到可以使用命令:find / -name pg_hba.conf 查找
vi /etc/postgresql/10/main/pg_hba.conf 
# 在最后一行添加,然后保存并退出(按Esc+:wq!)
host	all		all		0.0.0.0/0	md5

# 2.修改配置文件postgresql.conf,如果找不到可以使用命令:find / -name postgresql.conf 查找
vi  /etc/postgresql/10/main/postgresql.conf
# 将 #listen_addresses = ‘localhost’ 的注释去掉并改为 listen_addresses = ‘*’
# 修改max_connections按需求更改,默认最大支持100个连接。修改之后保存并退出。
  1. 重启服务
systemctl restart postgresql-10
  1. 防火墙打开5432端口
firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd —reload

也可以使用如下命令

sudo ufw allow 5432

PostGIS安装

  1. 安装PostGIS
sudo apt install postgresql-10-postgis-2.4 
sudo apt install postgresql-10-postgis-scripts

#to get the commandline tools shp2pgsql, raster2pgsql you need to do this
sudo apt install postgis
  1. 创建数据库
sudo -u postgres createdb gis
  1. 为数据库添加PostGIS扩展插件
sudo -u postgres psql -d gis -c 'CREATE EXTENSION postgis;'
sudo -u postgres psql -d gis -c 'CREATE EXTENSION postgis_topology;'

这块根据你自己的需要,添加相应的扩展。

参考资料

  1. HOW TO INSTALL AND USE POSTGRESQL 10 ON UBUNTU 16.04 LTS
  2. 离线部署

转载自:https://blog.csdn.net/yh0503/article/details/84641669

You may also like...

退出移动版