yum 下載資源包
yum install -y https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-3.noarch.rpm
yum 安裝 postgresql
yum install -y postgresql95-server postgresql95-contrib
初始化數據庫
/usr/pgsql-9.5/bin/postgresql95-setup initdb
設置開機啓動
systemctl enable postgresql-9.5.service
啓動服務
systemctl start postgresql-9.5.service
查看版本
psql --version
修改初始賬戶密碼
sudo -u postgres psql postgres
\password postgres (注意前面有斜槓)
開啓遠程訪問
vi /var/lib/pgsql/9.5/data/postgresql.conf
修改#listen_addresses = 'localhost' 爲 listen_addresses='*'
添加白名單
vi /var/lib/pgsql/9.5/data/pg_hba.conf
# IPv4 local connections:
host all all 127.0.0.1/32 ident
host all all 192.168.88.88/32(需要連接的服務器IP) md5
重啓服務
systemctl restart postgresql-9.5.service
防火牆開啓 5432 端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
重啓防火牆
firewall-cmd --reload