CentOS7.6安裝Postgresq11和PostGIS
由於在CentOS7.6下使用《CentOS7.5安裝Postgresql10.5和PostGIS》安裝PostGIS時候會報錯,下面安利一個 CentOS7.6安裝Postgresq11和PostGIS。
- 系統:Centos7.6
一、安裝Postgres11
1.首先安裝PostgreSQL的rpm
yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-ppc64le/pgdg-centos11-11-2.noarch.rpm -y
查看postgresql源
yum list | grep postgresql
安裝postgresql11
yum install postgresql11-server postgresql11-contrib -y
這樣會給我們的系統增加一個postgres用戶
2.修改默認數據目錄
Postgresql默認的數據目錄是/var/lib/pgsql/版本號/data目錄,這要求你在/var下有足夠的存儲空間,我們這裏將其換掉,假設/home的空間很大。
首先在/home下創建一個Postgresql的數據目錄,指定所有者postgres同時分配權限
mkdir /home/postgresql_data
chown postgres:postgres /home/postgresql_data
chmod 750 /home/postgresql_data
設置環境變量
export PATH=/usr/pgsql-11/bin:$PATH
export LD_LIBRARY_PATH=/usr/pgsql-11/lib
export PGDATA=/home/postgresql_data
切換到postgres用戶,使用initdb初始化數據庫,這樣在/home/postgresql_data下會增加很多東西
在root用戶下授權讀寫權限
chmod 777 /usr/lib/systemd/system/postgresql-11.service
修改/usr/lib/systemd/system/postgresql-11.service文件的內容,在#Location of database direcotry裏面指定正確的PGDATA:
#Location of database directory
Environment=PGDATA=/home/postgresql_data
3.在root用戶下配置數據庫服務開機啓動並立即啓動數據庫服務
systemctl enable postgresql-11.service
service postgresql-11 start
service postgresql-11 status
檢查數據庫狀態,有綠色,沒紅色說明啓動完成
這個過程中出現過一個錯誤,啓動失敗:
我這邊將/home/postgresql_data下的postmaster.pid刪除再重啓服務就好了
4.修改密碼
分爲postgres用戶密碼和數據庫密碼,保持一致吧
passwd postgres
設置數據庫密碼:
su postgres
psql
ALTER USER postgres WITH PASSWORD '密碼';
二、安裝PostGIS
1.先安裝幾個工具包
yum install wget net-tools epel-release -y
然後安裝postgis
yum install postgis25_11 postgis25_11-client -y
安裝拓展工具
yum install ogr_fdw11 -y
yum install pgrouting_11 -y
2.創建數據庫osm_db
CREATE DATABASE osm_db OWNER postgres;
進入數據庫
\c osm_db
安裝PostGis擴展
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
CREATE EXTENSION ogr_fdw;
然後可以驗證是否安裝成功
SELECT postgis_full_version();
設置遠程連接
1.修改配置文件
首先修改/home/postgresql_data/pg_hba.conf,改爲:
其次修改/home/postgresql_data/postgresql.conf,改爲:
之後重啓服務
service postgresql-10 restart
!!!重要:開啓服務器防火牆
firewall-cmd --add-service=postgresql --permanent 開放postgresql服務
firewall-cmd --reload 重載防火牆