CentOS7 yum安裝PostgreSQL 10

整個安裝過程非常便捷,官方文檔也非常簡潔清晰。

1.安裝YUM源

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

2.安裝客戶端

yum install postgresql10 -y

3.安裝服務端

yum install postgresql10-server -y

4.驗證是否安裝成功

rpm -aq| grep postgres
postgresql10-10.12-1PGDG.rhel7.x86_64
postgresql10-libs-10.12-1PGDG.rhel7.x86_64
postgresql10-server-10.12-1PGDG.rhel7.x86_64

5.初始化數據庫

/usr/pgsql-10/bin/postgresql-10-setup initdb

6.啓用開機自啓動

systemctl enable postgresql-10
systemctl start postgresql-10

7.配置防火牆

firewall-cmd --permanent --add-port=5432/tcp  
firewall-cmd --permanent --add-port=80/tcp  
firewall-cmd --reload  

8.登錄

#切換用戶
[root@vcentos7-150 log]# su - postgres
上一次登錄:三 3月 25 08:54:41 CST 2020pts/1 上

#登錄
-bash-4.2$ psql -U postgres
psql (10.12)
輸入 "help" 來獲取幫助信息.

postgres=#

9.修改密碼

ALTER USER postgres WITH PASSWORD 'postgres'  #設置postgres用戶密碼爲postgres
\q  #退出數據庫

10.配置監聽

vim /var/lib/pgsql/10/data/postgresql.conf
#修改#listen_addresses = 'localhost'  爲  listen_addresses='*'

11.配置連接鑑權方式

vi /var/lib/pgsql/10/data/pg_hba.conf
#增加如下內容,信任指定服務器連接
    # IPv4 local connections:
    host    all            all      0.0.0.0/0         md5
#可根據實際的安全級別進行配置。

若未配置,連接時會出現錯誤。

致命錯誤: 用戶 “postgres” Password 認證失敗

注意
有些帖子或博客的文章將 pg_hba.conf中的METHOD 從ident改爲trust,是極度危險的,安全風險極高。
建議只有重置密碼時,纔對本機使用trust。

12.重啓服務

systemctl restart postgresql-10

關於離線安裝

由於特殊需要,業務中是無互聯網的,因此需要進行離線安裝,後續會專門介紹離線安裝方法。

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