摘要:本文主要向大家介绍了Linux运维知识之GIS on CentOS 7 之 PostgreSQL & PostGIS,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助。
本文主要向大家介绍了Linux运维知识之GIS on CentOS 7 之 PostgreSQL & PostGIS,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助。
PostgreSQL & PostGIS
安装postgresql
配置好yum源之后,使用yum info postgresql可发现 postgresql的版本为9.2.23,若想安装最新版本,可参考下面操作
https://www.postgresql.org/download/linux/redhat/
//docs.nextgis.com/docs_ngweb/source/install-centos7.html
//www.postgresonline.com/journal/archives/362-An-almost-idiots-guide-to-install-PostgreSQL-9.5,-PostGIS-2.2-and-pgRouting-2.1.0-with-Yum.html
sudo yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-3.noarch.rpm
# 查看上述仓库中可用的包
yum list | grep postgresql95# 安装 PostgreSQL client server
sudo yum install postgresql95 postgresql95-server postgresql95-libs \
postgresql95-contrib postgresql95-devel# 查看帮助
psql --help
rpm -qa | grep postgresql* # 查看已安装软件# 初始化数据库,并设置随系统启动
sudo /usr/pgsql-9.5/bin/postgresql95-setup initdb
sudo systemctl start postgresql-9.5.service # service postgresql-9.5 start
sudo systemctl enable postgresql-9.5.service
# 编辑验证参数(此处使用nano编辑器,可以使用 vim)# psql 进入postgres数据库之后,使用 show hba_file; 查看文件位置
sudo nano /var/lib/pgsql/9.5/data/pg_hba.conf
sudo vim /var/lib/pgsql/9.5/data/pg_hba.conf
将ident 修改为 md5
PostgreSQL ident和peer基于操作系统用户的认证 PostgreSQL认证方法
如果是 peer,可能会出现 对等认证失败 的错误
# "local" is for Unix domain socket connections onlylocal all all md5# IPv4 local connections:host all all 127.0.0.1/32 md5# IPv6 local connections:host all all ::1/128 md5
# 可进一步修改 postgresql.conf 以监听目标地址
su postgres # 切换到postgres 或 sudo su postgres
psql -U postgres #登录数据库,默认没有密码
ALTER USER postgres WITH PASSWORD '密码'; #修改密码 sudo passwd postgres# 或者使用 \password 命令
\password postgres select * from pg_shadow; # 查看数据库信息
\q #退出
psql -V
sudo systemctl restart postgresql-9.5.service # 重启服务,或 service postgresql-9.5 restart
# 使用postgres用户新建一个psql数据库用户(ngw_admin)# \du 命令可以查看用户信息# -P 表示密码,-e表示显示命令。 使用 -s 或 --superuser 赋予超级用户权限
sudo -u postgres createuser ngw_admin -P -e# 新建数据库(db_ngw),所有者为 ngw_admin
sudo -u postgres createdb -O ngw_admin --encoding=UTF8 db_ngw
postgresql-client
libraries and client binaries
postgresql-server
core database server
postgresql-contrib
additional supplied modules
postgresql-devel
libraries and headers for C language development
pgadmin4
pgAdmin 4 graphical administration utility
### 安装postgis
https://postgis.net/install/
The postgis2_95-client contains the PostGIS commandline tools shp2gpsql, pgsql2shp, raster2pgsql that are useful for loading or exporting spatial data.
sudo yum install epel-release # 没有配置epel源的话
sudo yum install postgis2_95 postgis2_95-client # 安装
# 需要 pgRouting 时 yum install pgrouting_95
# 登录进入相应数据库
psql -U ngw_admin -d db_ngw
# 为已有数据库(db_ngw)扩展 postgis 功能CREATE EXTENSION postgis;SELECT PostGIS_Full_Version(); # 测试数据库是否包含了postgis的功能
或者直接在shell中执行
sudo psql -u postgres -d db_ngw -c 'CREATE EXTENSION postgis;'
sudo psql -u postgres -d db_ngw -c \
'ALTER TABLE geometry_columns OWNER TO ngw_admin;'
sudo psql -u postgres -d db_ngw -c \
'ALTER TABLE spatial_ref_sys OWNER TO ngw_admin;'
sudo psql -u postgres -d db_ngw -c \
'ALTER TABLE geography_columns OWNER TO ngw_admin;'
psql -h localhost -d db_ngw -U ngw_admin -c "SELECT PostGIS_Full_Version();"
使用template方式直接创建postgis数据库,并指定所有者
# 登录数据库# postgis_21_sample 为 2.1 版本postgis数据库create database geodataont template postgis_21_sample owner gdo;# 或者createdb -O gdo -U postgres -T postgis_22_sample geodataont
启用 PostGIS 功能的相关SQL
DO NOT INSTALL it in the database called postgres.
# 连接数据库之后,执行以下sql命令启用相应功能
# Enable PostGIS (includes raster)CREATE EXTENSION postgis;
# Enable TopologyCREATE EXTENSION postgis_topology;
# Enable PostGIS Advanced 3D
# and other geoprocessing algorithms
# sfcgal not available with all distributionsCREATE EXTENSION postgis_sfcgal;
# fuzzy matching needed for TigerCREATE EXTENSION fuzzystrmatch;
# rule based standardizerCREATE EXTENSION address_standardizer;
# example rule data setCREATE EXTENSION address_standardizer_data_us;
# Enable US Tiger GeocoderCREATE EXTENSION postgis_tiger_geocoder;
CREATE EXTENSION pgrouting;SELECT * FROM pgr_version();
# yum install ogr_fdw95CREATE EXTENSION ogr_fdw;
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注系统运维Linux频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号