天天看點

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

1、環境準備

檢查PostgreSQL 是否已經安裝

rpm -qa | grep postgres

檢查PostgreSQL 安裝位置

rpm -qal | grep postgres

解除安裝已安裝PostgreSQL

rpm –e PostgreSQL版本

檢視解除安裝是否已完成

rpm -qa | grep postgres

新增postgres使用者組

groupadd postgres

新增postgres使用者并且設定這個使用者屬于上面建立的postgres使用者組

useradd -g postgres postgres

修改postgres使用者密碼

passwd postgres

2、yum安裝

(不需要事先建立使用者和使用者組)

2.1、安裝

使用yum安裝postgresql

yum –y install postgresql-server.x86_64

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章
PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

初始化postgresql資料庫

service postgresql initdb

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

啟動postgresql服務

service postgresql start

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

檢視postgresql的服務狀态

service postgresql status

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

查postgres的程序資訊

ps -ef | grep postgres

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

查postgres的端口号5432是否已經打開

netstat -tpnl |grep 5432

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

設定開機啟動postgresql

chkconfig postgresql on

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

2.2、連接配接測試

切換使用者

su postgres

連接配接資料庫

psql -U postgres

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

檢視資料庫表

select * from pg_shadow;

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

列出所有的資料庫

\l

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

退出

\q

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

2.3、修改配置

預設安裝時,PostgreSQL的資料庫目錄在/var/lib/pgsql/data目錄

(1)修改postgresql的配置檔案

vi /var/lib/pgsql/data/postgresql.conf

修改監聽IP:

listen_addresses = '*'

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

日志采集器打開

logging_collector = on

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

設定日志目錄

log_directory = 'pg_log'

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

隻保留一天的日志,進行循環覆寫

log_truncate_on_rotation = on
log_rotation_age = 1d           
PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

共享記憶體大小

shared_buffers = 32MB

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

(2)修改postgresql服務連接配接檔案

vi /var/lib/pgsql/data/pg_hba.conf

第80行【local all all peer】peer改為md5

第82行【host all all 127.0.0.1/32 iden】下增加一條,【0.0.0.0/24】允許所有IP連接配接

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

關閉防火牆

service iptables stop

開放5432端口

iptables -I INPUT -p tcp --dport 5432 -j ACCEPT

重新開機資料庫

service postgresql restart

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

2.4、遠端連接配接

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章
PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

3、離線安裝

3.1、安裝包準備

通路官網生成下載下傳連結

通路官網

https://www.postgresql.org/

→點選Download→選擇需要的作業系統版本

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

線上伺服器上下載下傳yum 源

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

查找安裝包

yum search postgres

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

下載下傳 Postgresql

mkdir psql10
yum install --downloadonly --downloaddir=psql10 postgresql10 postgresql10-server           
PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

打包并上傳到離線伺服器

tar -zcvf pgsql10.tar.gz *

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

3.2、安裝

解壓并安裝

tar -xzvf pgsql10.tar.gz
cd /pgsql10
rpm -ivh postgre*           
PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

設定自啟動

systemctl enable postgresql-10
systemctl start postgresql-10           

啟動服務

service postgresql-10 initdb
chkconfig postgresql-10 on           

3.3、連接配接測試

進入建立的使用者

su postgres

psql -U postgres

select * from pg_shadow;

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

3.4、修改配置

(1)修改postgresql的配置檔案

`

vi /var/lib/pgsql/10/data/postgresql.conf

listen_addresses = '*'

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章
PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

vi /var/lib/pgsql/10/data/pg_hba.conf

第26行【local all all peer】peer改為md5

第28行【host all all 127.0.0.1/32 iden】下增加一條, 【0.0.0.0/24】允許所有IP連接配接

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

service iptables stop

iptables -I INPUT -p tcp --dport 5432 -j ACCEPT

service postgresql restart

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

3.5、遠端連接配接

PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章
PostGresql資料庫Linux伺服器安裝1、環境準備2、yum安裝3、離線安裝附:參考文章

附:參考文章

https://www.cnblogs.com/qiyebao/p/4562557.html https://blog.51cto.com/11298469/2414026?source=dra https://www.cnblogs.com/mchina/archive/2012/06/06/2539003.html https://blog.csdn.net/u010177412/article/details/82150207 https://www.postgresql.org/download/linux/redhat/ https://blog.51cto.com/hsbxxl/2117398 https://blog.csdn.net/qq_36395686/article/details/100133098