1. 程式人生 > >阿里雲CentOS安裝PostgreSQL

阿里雲CentOS安裝PostgreSQL

在PostgreSQL官方文件:https://www.postgresql.org/download/linux/redhat/ 有選項和說明

1、檢查有沒安裝:rpg -ga | grep postgresql

2、下載 從上述網址得到YUM地址,即在終端輸入:yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm

      注意:整個YUM必須都是小寫的命令,Unix嚴格區分大小寫(通過阿里雲遠端終端複製貼上的是大寫字母,不可用)

3、安裝,終端輸入:yum install postgresql11-server postgresql11-libs

4、初始化:/usr/pgsql-11/bin/postgresql-11-setup initdb (注意這裡必須要輸入完整路徑...)

5、配置服務

systemctl enable postgresql-11

systemctl start postgresql-11

 

6、配置遠端連線:

vim /var/lib/pgsql/11/data/postgresql.conf  將listen_addresses 修改為 '*'

vim /var/lib/pgsql/11/data/pg_hba.conf  

新增IP監聽(加入一行) host all all 0.0.0.0/0 md5

重啟服務:systemctl restart postgresql-11

7、修改資料庫密碼,以postgres為例:

      通過命令切換使用者: su - postgres

      使用命令更改密碼(用MD5加密):alter role postgres with ENCRYPTED password '123456'

 

      可以使用命令檢視是否能登入:psql -h 127.0.0.1 -U postgres -d 123456 -W

8、配置ECS伺服器的《安全組》策略

 

9、最後檢視ECS例項公網地址,在外網訪問