Centos7離線安裝Postgresql文檔

需求

  1. 是在centos下離線安裝postgresql11.4,要求可以外網連接,需要詳細部署步驟
  2. 要求訪問端口改爲9527
  3. 客戶端可以使用pgadmin來測試連接

目錄結構

在這裏插入圖片描述

安裝Postgre

複製安裝包

請將安裝Postgre文件夾放入指定目錄下下,並進入指定目錄

進入安裝Postgre文件夾中

cd 安裝Postgre

創建文件夾

sudo mkdir -p /chinamobile/soft

sudo mkdir -p /chinamobile/work/postgresql

解壓postgresql-11.4.tar

sudo tar xf postgresql-11.4.tar -C /chinamobile/soft

進入Postgre_rpm包文件夾中

cd Postgre_rpm包

安裝rpm軟件包

sudo rpm -Uvh *.rpm --nodeps --force
在這裏插入圖片描述

進入postgresql-11.4源碼包目錄中

cd /chinamobile/soft/postgresql-11.4

配置環境

./configure --prefix=/chinamobile/work/postgresql
在這裏插入圖片描述

進行編譯安裝

sudo make
在這裏插入圖片描述

sudo make install
在這裏插入圖片描述

相關配置

創建用戶

sudo useradd postgres

sudo passwd postgres
在這裏插入圖片描述

設定權限

sudo mkdir /chinamobile/work/postgresql/data

sudo mkdir /chinamobile/work/postgresql/log

sudo chown -R postgres:postgres /chinamobile/work/postgresql

配置環境變量

編寫profile

sudo vim /etc/profile

追加下面內容

export PGDATA=/chinamobile/work/postgresql/data
export PGHOME=/chinamobile/work/postgresql
export PGPORT=9527
export PATH=$PGHOME/bin:$PATH

在這裏插入圖片描述

生效配置

source /etc/profile

初始化數據庫

切換到postgres用戶

sudo su - postgres
在這裏插入圖片描述

初始化數據庫

initdb
在這裏插入圖片描述

配置數據庫

cd /chinamobile/work/postgresql/data

配置對數據庫的訪問控制(設置爲可以通過密碼訪問)

vim pg_hba.conf

更改爲

# IPv4 local connections:
# host    all             all             127.0.0.1/32            trust
host    all             all             0.0.0.0/0               trust

在這裏插入圖片描述

配置數據庫參數(設置服務器監聽整個網絡,設置端口號爲9527)

vim postgresql.conf

更改爲

listen_addresses = '*'

port = 9527
在這裏插入圖片描述

退出postgres

exit

開放9527端口

新增開放9527端口號

sudo firewall-cmd --zone=public --add-port=9527/tcp --permanent

重啓防火牆開機

sudo systemctl restart firewalld.service

配置系統服務

進入postgresql的解壓目錄

cd /chinamobile/soft/postgresql-11.4

sudo cp contrib/start-scripts/linux /etc/init.d/postgresql

sudo vim /etc/init.d/postgresql

更改爲

# Installation prefix
prefix=/chinamobile/work/postgresql

# Data directory
PGDATA="/chinamobile/work/postgresql/data"

# Who to run the postmaster as, usually "postgres".  (NOT "root")
PGUSER=postgres

# Where to keep a log file
PGLOG="/chinamobile/work/postgresql/log/serverlog"

在這裏插入圖片描述

賦予文件執行權限

sudo chmod +x /etc/init.d/postgresql

設定服務開機自啓

sudo chkconfig --add postgresql

啓動及連接數據庫

啓動數據庫服務

service postgresql start

命令行連接數據庫

sudo su - postgres

psql
在這裏插入圖片描述

pgadmin連接數據庫

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章