1、安裝步驟
-- 安裝對應的rpm文件(其他系統的rpm包,請自行到https://yum.postgresql.org/下載)
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
-- 查詢postgresql的版本
yum search postgresql
-- 安裝對應的版本(我安裝的是postgresql9.6+postgis2.4)
yum -y install postgresql96.x86_64 postgresql96-server.x86_64 postgresql96-devel.x86_64
-- 安裝對應的postgis插件
yum install postgis24_96.x86_64
如果出現如下圖所示錯誤,
請執行如下命令:rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
執行完畢后,繼續執行yum install postgis24_96.x86_64
至此整個安裝過程完畢!
2、初始化運行環境
-- 初始化數據庫
/usr/pgsql-9.6/bin/postgresql96-setup initdb
-- 啟動psql服務器
systemctl start postgresql-9.6
--設置開機自啟動
systemctl enable postgresql-9.6
--開發防火牆
firewall-cmd--permanent --add-port=5432/tcp
firewall-cmd--reload
-- 修改pg_hba.conf和postgresql.conf
/var/lib/pgsql/9.6/data/pg_hba.conf 將配置文件中記錄的method的ident修改為trust(可以實現用戶名和密碼訪問數據庫)
/var/lib/pgsql/9.6/data/postgresql.conf 修改listen_addresses = 'localhost'為listen_addresses= '*',允許所有遠程訪問
(這樣可以在其它客戶機上遠程登陸服務器,比如在windows機器上使用pgadmin客戶端)
-- 初始化數據庫
su postgresql
--登錄到數據庫
psql(可以默認登陸到用戶名為:postgres 數據庫名為postgres的數據庫)
--查看當前連接到的數據庫
\c
--查看當前的數據庫信息
\l
--查看當前數據庫的表信息
\d
--導入sql腳本
第一種方法:\i sql腳本的路徑信息
第二種:psql -U 用戶 -d 數據庫 -h 主機 -p 端口 -f 腳本路徑
至此基本的安裝,初始化過程就結束了, 如果你在過程中有任何疑問,歡迎交流學習!