PostgreSQL 13 リモート接続の設定方法

2021年10月20日

1.MD5認証方式を設定する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[root@localhost ~]# vi /var/lib/pgsql/data/postgresql.conf
59行目
修正前
listen_addresses = '*'
修正後
listen_addresses = '*'
[root@localhost ~]# vi /var/lib/pgsql/data/postgresql.conf 59行目 修正前 listen_addresses = '*' 修正後 listen_addresses = '*'
[root@localhost ~]#  vi /var/lib/pgsql/data/postgresql.conf
59行目
修正前
listen_addresses = '*'
修正後
listen_addresses = '*'

2.接続を許可するネットワークを指定

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[root@localhost ~]# vi /var/lib/pgsql/data/pg_hba.conf
最終行に以下を追記
host all all 192.168.0.0/0 md5
[root@localhost ~]# vi /var/lib/pgsql/data/pg_hba.conf 最終行に以下を追記 host all all 192.168.0.0/0 md5
[root@localhost ~]#  vi /var/lib/pgsql/data/pg_hba.conf
最終行に以下を追記
host    all             all             192.168.0.0/0          md5

3.postgresqlを再起動

[root@localhost ~]# systemctl restart postgresql

4.postgresqlサービスを許可
# firewall-cmd –add-service=postgresql
success
# firewall-cmd –runtime-to-permanent
success

5.動作確認

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
アクセス許可ネットワーク内の任意のホストからサーバー接続確認
[root@localhost ~]# psql -h 192.168.229.132 -d testdb2 -U rockyuser
ユーザ rockyuser のパスワード:  #パスワード入力
psql (13.3)
"help"でヘルプを表示します。
testdb2=>
アクセス許可ネットワーク内の任意のホストからサーバー接続確認 [root@localhost ~]# psql -h 192.168.229.132 -d testdb2 -U rockyuser ユーザ rockyuser のパスワード:  #パスワード入力 psql (13.3) "help"でヘルプを表示します。 testdb2=>
アクセス許可ネットワーク内の任意のホストからサーバー接続確認
[root@localhost ~]# psql -h 192.168.229.132 -d testdb2 -U rockyuser
ユーザ rockyuser のパスワード:  #パスワード入力
psql (13.3)
"help"でヘルプを表示します。

testdb2=>

 

Rocky Linux 8

Posted by arkgame