一、準備工作:
1.postgresql官網:https://www.postgresql.org
2.下載頁面:https://www.postgresql.org/download/
3.Red Hat家族Linux(包括CentOS/Fedora/Scientific/Oracle)下載頁面:https://www.postgresql.org/download/linux/redhat/
4.本文使用系統爲:centos 7.5 1804
5.可以使用一下網址找到對應的postgresql yum安裝版本 頁面:
https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
二、系統執行命令:
1.yum install -y https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
- yum -y install postgresql11
- yum -y install postgresql11-server
- /usr/pgsql-11/bin/postgresql-11-setup initdb
- systemctl enable postgresql-11
- systemctl start postgresql-11
三、開通PostgreSQL端口(如果防火牆關閉可以忽略此步驟) - firewall-cmd --zone=public --add-port=5432/tcp --permanent
- firewall-cmd --reload
- firewall-cmd --list-ports
四、設置postgres的密碼
Last login: Fri Jul 19 17:13:49 CST 2019 on pts/0
-bash-4.2$ psql -U postgres
psql (11.4)
Type "help" for help.
postgres=# ALTER USER postgres with encrypted password 'welcome1';
ALTER ROLE
postgres=# \q
-bash-4.2$ exit
logout
五、設置遠程訪問
命令:
vim /var/lib/pgsql/11/data/postgresql.conf
打開後找到:listen_addresses修改爲:
listen_addresses = ''
要監聽的IP地址;以逗號分隔的地址列表;默認爲'localhost';對所有人使用''。修改完畢後保存關閉。
命令:
vim /var/lib/pgsql/11/data/pg_hba.conf
打開後文本新增內容如下:
host all all 0.0.0.0/0 md5
修改完成後保存關閉編輯。
六。重啓postgres 數據庫
systemctl restart postgresql-11