本文只講PostgreSQL在CentOS 7.x 下的安裝,其他系統請查看:https://www.postgresql.org/download
PostgreSQL 所用版本為:PostgreSQL 10
1.安裝存儲庫
yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
2.安裝客戶端
yum install postgresql10
3.安裝服務端
yum install postgresql10-server
4.驗證是否安裝成功
rpm -aq| grep postgres
輸出如下:
4.初始化數據庫
/usr/pgsql-10/bin/postgresql-10-setup initdb
5.啟用開機自啟動
systemctl enable postgresql-10 systemctl start postgresql-10
6.配置防火牆
firewall-cmd --permanent --add-port=5432/tcp firewall-cmd --permanent --add-port=80/tcp firewall-cmd --reload
7.修改用戶密碼
su - postgres 切換用戶,執行后提示符會變為 '-bash-4.2$'
psql -U postgres 登錄數據庫,執行后提示符變為 'postgres=#'
ALTER USER postgres WITH PASSWORD 'postgres' 設置postgres用戶密碼為postgres \q 退出數據庫
8.開啟遠程訪問
vim /var/lib/pgsql/10/data/postgresql.conf 修改#listen_addresses = 'localhost' 為 listen_addresses='*' 當然,此處‘*’也可以改為任何你想開放的服務器IP
9.信任遠程連接
vim /var/lib/pgsql/10/data/pg_hba.conf 修改如下內容,信任指定服務器連接 # IPv4 local connections: host all all 127.0.0.1/32 trust
host all all 192.168.157.1/32(需要連接的服務器IP,如果是所有則0.0.0.0/0) trust
10.重啟服務
systemctl restart postgresql-10
11.使用DBMS軟件連接
這里使用的是Navicat
連接成功:
安裝 PGAdmin4:
1:yum -y install epel-release
2.yum install pgadmin4
3./usr/pgadmin4/bin/pgadmin4-web-setup.sh
4.
cd /usr/lib/python2.7/site-packages/pgadmin4-web/
vim config_local.py
#設置你希望的IP,0.0.0.0表示不受限制,如果你只希望局域網內訪問,請使用適當的局域網ip
DEFAULT_SERVER = '0.0.0.0'
#設置你希望的端口
DEFAULT_SERVER_PORT = 8080