Pet*_*sik 3 postgresql configuration connectivity
我在从不同主机连接到 PostgreSQL 服务器时遇到错误,我配置了两者postgresql.conf,pg_hba.conf 但不幸的是没有结果。
所以我已经从包中在 Debian 上安装了 PostgreSQL,添加了用户createuser和useradd,然后通过createdb作为我的自定义用户作为所有者创建了 db 。之后我设置postgresql.conf了这些值
listen_addresses = '*'
ssl = false
Run Code Online (Sandbox Code Playgroud)
并添加了这一行 pg_hba.conf
host all all 192.168.0.0/24 md5
Run Code Online (Sandbox Code Playgroud)
然后我重新启动了服务并尝试通过我的机器连接psql -U admin -d admin -h 10.10.30.88,我收到此错误
psql: FATAL: no pg_hba.conf entry for host "192.168.10.195", user "admin", database "admin", SSL off
Run Code Online (Sandbox Code Playgroud)
那么我是不是忘记了什么?
所有的 pg_hba.conf
local all postgres peer
local all all peer
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
host all all 192.168.0.0/24 md5
host all all 10.10.0.0/24 md5
Run Code Online (Sandbox Code Playgroud)
ipconfig PostgreSQL 服务器
eth0 Link encap:Ethernet HWaddr 52:54:00:00:00:03
inet addr:10.10.30.88 Bcast:10.10.30.255 Mask:255.255.255.0
inet6 addr: fe80::5054:ff:fe00:3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4001 errors:0 dropped:0 overruns:0 frame:0
TX packets:2297 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:365126 (356.5 KiB) TX bytes:306782 (299.5 KiB)
Run Code Online (Sandbox Code Playgroud)
ipconfig 来自同一网络中的其他虚拟机
eth0 Link encap:Ethernet HWaddr 52:54:00:00:00:15
inet addr:10.10.30.83 Bcast:10.10.30.255 Mask:255.255.255.0
inet6 addr: fe80::5054:ff:fe00:15/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:144749 errors:0 dropped:0 overruns:0 frame:0
TX packets:18950 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:16160192 (15.4 MiB) TX bytes:1323052 (1.2 MiB)
Run Code Online (Sandbox Code Playgroud)
ipconfig 从我的机器
eth0 Link encap:Ethernet HWaddr c4:7d:46:11:5c:ab
inet addr:192.168.10.195 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::c67d:46ff:fe11:5cab/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:198498 errors:0 dropped:0 overruns:0 frame:0
TX packets:78205 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:168115954 (168.1 MB) TX bytes:10312744 (10.3 MB)
Interrupt:20 Memory:f0600000-f0620000
Run Code Online (Sandbox Code Playgroud)
我也有自己的 KVM(未运行)
virbr0 Link encap:Ethernet HWaddr 2e:e4:de:95:07:1b
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Run Code Online (Sandbox Code Playgroud)
Wifi 未启用
wlan0 Link encap:Ethernet HWaddr ac:fd:ce:b3:dc:e7
inet6 addr: fe80::aefd:ceff:feb3:dce7/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:32251 errors:0 dropped:0 overruns:0 frame:0
TX packets:159 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3268413 (3.2 MB) TX bytes:21321 (21.3 KB)
Run Code Online (Sandbox Code Playgroud)
问题可能是由于这一行:
host all all 192.168.0.0/24 md5
Run Code Online (Sandbox Code Playgroud)
这(24)基本上告诉 Postgres 允许来自任何具有以下形式的 IP 的机器的连接:192.168.0.x。所以,你的192.168.10.195不符合条件。您可以将其替换为:
host all all 192.168.0.0/16 md5 -- any 192.168.x.x
Run Code Online (Sandbox Code Playgroud)
或者
host all all 192.168.10.0/24 md5 -- any 192.168.10.x
Run Code Online (Sandbox Code Playgroud)
或者
host all all 192.168.10.195/32 md5 -- only 192.168.10.195
Run Code Online (Sandbox Code Playgroud)
取决于您要允许的 IP 范围。
| 归档时间: |
|
| 查看次数: |
1821 次 |
| 最近记录: |