Prepare a centos7 operating system with PostgreSQL Database installed. If not, see here.
- Configure the postgresql.conf . file
Find the path containing the file postgresql.conf
#find / -name “postgresql.conf“
Access the path and edit the file like so
#vi /var/lib/pgsql/11/data/postgresql.conf
find the line #listening_addresses=’localhost’ , #port=5432 and adjusted like a star
listening_addresses=’*’
port=5432'*' means it will listen on all ip addresses if you want to listen with 1 or several ip addresses, you can replace the * sign with the ip address you want, each ip separated by comma
- Configuration file pg_hba.conf
Find the file path pg_hba.conf
#find / -name “pg_hba.conf”
Access the path and edit the file like so
# vi /var/lib/pgsql/11/data/pg_hba.conf
Add the following line at the end of the file
host all all 0.0.0.0/0 md5 –> all ip addresses can connect to postgresql.
(md5 is the password authentication mode, if you don't want to authenticate with a password, then replace it md5 is equal to trust).
host all 103.121.88.143/24 md5 –> only allow ip addresses in range 192.168.3.12/24 - Firewall configuration on centos7
Open port 5432 on centos7's firewalld firewall
#firewall-cmd –zone=public –add-port=5432/tcp –permanent
#firewall-cmd –relead
Check if the port is open
firewall-cmd –zone=public –list-port
Allow to add wan ip address on firewalld firewall to allow ip to connect remotely (get wan ip address) here).
#firewall-cmd –permanent –zone=public –add-source=192.168.100.1
#firewall-cmd –relead
Check to see if it has been added
#firewall-cmd –zone=public –list-all - Login to check
Here use another vps with ip like in the file settings pg_hba.conf to test the connection to postgresql server configured by me trust So when you log in, you don't need to confirm the password.
Good luck
Thanh Tung
The post Configuring PostgreSQL to allow remote connections appeared first on BKNS.VN.
Post a Comment
Post a Comment