記一次 Centos7.4 使用 yum 安裝 PostgreSql v11

一、基礎信息說明

官網:https://www.postgresql.org/

下載說明地址:https://www.postgresql.org/download/linux/redhat/

中文社區 http://www.postgres.cn/index.php/v2/home

中文網 https://postgres.fun/

易百教程 https://www.yiibai.com/postgresql

二、系統、工具說明

1、系統版本 Centos7.4    CentOS-7-x86_64-Minimal-1804

下載地址:  http://archive.kernel.org/centos-vault/7.4.1708/isos/x86_64/   

2、VMware 版本:VMware Workstation Pro15

虛擬機安裝過程可參考:https://blog.csdn.net/llwy1428/article/details/89328381

3、工具:xshell5

三、安裝、部署

1、配置虛擬機網絡,每臺虛擬機均接入互聯網

參考:

https://blog.csdn.net/llwy1428/article/details/85058028

2、設置靜態IP

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33

[root@localhost ~]# service network restart

3、安裝基本工具

[root@localhost ~]# yum install -y vim lrzsz tree wget rpm net-tools
[root@localhost ~]# yum update -y

4、瀏覽器打開 https://www.postgresql.org/download/linux/redhat/ 

如下圖:

5、安裝資源 rpm 、客戶端、服務端

[root@localhost ~]# yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
[root@localhost ~]# yum install -y postgresql11

[root@localhost ~]# yum install -y postgresql11-server

6、數據庫初始化

[root@localhost ~]# /usr/pgsql-11/bin/postgresql-11-setup initdb
效果:
Initializing database ... OK

7、設置允許外部連接

查看目錄

[root@localhost ~]# vim /var/lib/pgsql/11/data/postgresql.conf

[root@localhost ~]# vim /var/lib/pgsql/11/data/pg_hba.conf
host    all             all             0.0.0.0/0               md5

說明:

TYPE:pg的連接方式,local:本地unix套接字,host:tcp/ip連接

DATABASE:指定數據庫

USER:指定數據庫用戶

ADDRESS:ip地址,可以定義某臺主機或某個網段,32代表檢查整個ip地址,相當於固定的ip,24代表只檢查前三位,最後一                         位是0~255之間的任何一個

METHOD:認證方式,常用的有ident,md5,password,trust,reject。

                      md5是常用的密碼認證方式。

                      password是以明文密碼傳送給數據庫,建議不要在生產環境中使用。

                      trust是隻要知道數據庫用戶名就能登錄,建議不要在生產環境中使用。

                      reject是拒絕認證。

8、防火牆開放 5432 端口(條件允許可關閉防火牆)

例如:
[root@localhost ~]# firewall-cmd --zone=public(作用域) --add-port=80/tcp(端口和訪問類型) --permanent(永久生效)
操作:
[root@localhost ~]# firewall-cmd --zone=public --add-port=5432/tcp --permanent
success
[root@localhost ~]#  firewall-cmd --reload
success

其它防火牆操作可參考:

https://blog.csdn.net/llwy1428/article/details/99676257

9、 postgresql 安裝目錄授權

[root@localhost ~]# chown postgres:root -R /usr/pgsql-11/

10、啓動服務

[root@localhost ~]# systemctl start postgresql-11
[root@localhost ~]# netstat -lntp

11、切換用戶,設置數據庫密碼

[root@localhost ~]# su - postgres
-bash-4.2$ psql -U postgres
postgres=# ALTER USER postgres with encrypted password '123456';
postgres=# \l

注意:遇到啓動錯誤及解決方式:

[root@localhost ~]# systemctl start postgresql-11
Job for postgresql-11.service failed because the control process exited with error code. See "systemctl status postgresql-11.service" and "journalctl -xe" for details.

查看錯誤詳情:

[root@localhost ~]# journalctl -xe

說明:data 目錄下信息可能丟失

重新初始化,提示 data 目錄已經存在

[root@localhost ~]# /usr/pgsql-11/bin/postgresql-11-setup initdb
Data directory is not empty!

刪除現有 data 目錄下的所有信息

[root@localhost ~]# rm -rf /var/lib/pgsql/11/data/*

重新執行數據庫初始化:

[root@localhost ~]# /usr/pgsql-11/bin/postgresql-11-setup initdb
Initializing database ... OK

再次啓動 postgresql 服務

[root@localhost ~]# systemctl start postgresql-11
[root@localhost ~]# netstat -lntp

12、第三方客戶端工具測試連接:

 

 

至此  Centos7.4  使用  yum  安裝 PostgreSql   v11  操作完畢!

安裝、配置 Pgadmin 可參考:

https://hunter.blog.csdn.net/article/details/102486511

擴展:Centos7 編譯安裝 PostgreSql 11.4

https://blog.csdn.net/llwy1428/article/details/95444151

 

 

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