找回密码
 注册
查看: 13|回复: 0

postgresql pgsql数据库修改默认监听地址listen_addresses = '*'

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2024-5-25 09:00:16 | 显示全部楼层 |阅读模式
2 P. {' G; e' `

" U) o' ^$ O  b) s$ o: P9 `[root@opennms ~]# telnet 172.24.21.38 5432, u2 r- Q# Y# e* x2 S
Trying 172.24.21.38...% a6 l- H, B# K) S2 Y3 h* w5 v$ \
telnet: connect to address 172.24.21.38: Connection refused+ T  L8 p/ i$ x0 I6 \7 B' u
[root@opennms ~]# ps -ef |grep pg* {' V% K3 e4 z% s8 h: D
postgres  91577      1  0 13:52 ?        00:00:00 /usr/pgsql-12/bin/postmaster -D /var/lib/pgsql/12/data/
. C+ m$ z0 O5 Rroot      93151  84651  0 13:56 pts/0    00:00:00 grep --color=auto pg1 N" L: K; k' C8 o- l6 P
[root@opennms ~]# vim /var/lib/pgsql/12/
) Y+ H$ B" }* W! z6 gbackups/    data/       initdb.log  
& c$ ~8 g+ b. f# B! R[root@opennms ~]# vim /var/lib/pgsql/12/data/pg_hba.conf
4 w, C3 @6 s7 D[root@opennms ~]# systemctl restart postgresql-12.service
$ v, R. @7 u3 n; a* T8 O[root@opennms ~]# vim /var/lib/pgsql/12/data/pg_hba.conf
- s5 q5 i5 G' L$ J0 w, A[root@opennms ~]# netstat -ntlp( i  |6 A+ A$ H# o0 P$ R8 S$ T. Q
Active Internet connections (only servers)
; F9 F  I3 N5 b7 Z* qProto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
1 J5 D* l" Y3 I3 ^4 i' @tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1422/master         
: Z- U& g3 [* v% stcp        0      0 0.0.0.0:60028           0.0.0.0:*               LISTEN      1519/sshd: /usr/sbi & S) A1 g% S8 T/ E* q
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      1229/zabbix_agentd  2 v* n  v# R+ ]% b: ^! w
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      94593/postmaster   
. m; }8 B$ H. K5 ^1 rtcp6       0      0 ::1:25                  :::*                    LISTEN      1422/master         
! c( ?( T, V# \, B$ f! Dtcp6       0      0 :::60028                :::*                    LISTEN      1519/sshd: /usr/sbi 5 O2 {8 ]6 c0 Y6 `' P$ N
tcp6       0      0 :::10050                :::*                    LISTEN      1229/zabbix_agentd  / h" b' ^, J% `; J! ?
tcp6       0      0 ::1:5432                :::*                    LISTEN      94593/postmaster    ) A. Q$ X/ \  z! c9 K! H0 U
[root@opennms ~]# vim /var/lib/pgsql/12/data/pg_hba.conf + r: p+ |( \: b2 ?5 C/ s' o
[root@opennms ~]# systemctl restart postgresql-12.service
3 W' z  B/ P/ J* c4 A1 E[root@opennms ~]# netstat -ntlp( n3 C$ p7 G4 S) {
Active Internet connections (only servers)/ r  p& l1 B& I7 ]  l6 x
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
) ]" [1 E0 l: Q9 M, n+ [tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1422/master         
: ^9 n8 v7 Z/ h) `& f; g, O& htcp        0      0 0.0.0.0:60028           0.0.0.0:*               LISTEN      1519/sshd: /usr/sbi . v' C7 j9 t5 D- Y1 V! n9 @) V
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      1229/zabbix_agentd  
3 z4 B% y( K0 ?9 J/ {  {( etcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      95523/postmaster    ; G" ?5 s3 Y, ~6 Y( T5 ~/ [' I8 M
tcp6       0      0 ::1:25                  :::*                    LISTEN      1422/master         
. x. K3 P. I5 ftcp6       0      0 :::60028                :::*                    LISTEN      1519/sshd: /usr/sbi
  N1 X* _6 p- [  a: p" R1 y+ ]tcp6       0      0 :::10050                :::*                    LISTEN      1229/zabbix_agentd  
. [; _" k) c3 t. S* j) k- Ztcp6       0      0 ::1:5432                :::*                    LISTEN      95523/postmaster    . H& e+ Y/ I1 M  X# K+ Z
[root@opennms ~]# telnet 172.24.21.38 5432' \7 s& ]$ d7 Z" c6 m1 t7 {( D
Trying 172.24.21.38...
7 n9 `  q5 f# }: A0 Otelnet: connect to address 172.24.21.38: Connection refused
8 G3 B! r0 Q$ w" K1 R& O0 I- _[root@opennms ~]# systemctl reload postgresql-12.service 2 w# H2 F0 {4 Q6 }% ]: |
[root@opennms ~]# telnet 172.24.21.38 54323 X) O! D8 ]8 i/ `3 H7 f
Trying 172.24.21.38...# P, s" u6 ^2 d  Z% f. G0 c0 t0 w
telnet: connect to address 172.24.21.38: Connection refused& T( M4 F" o- j
[root@opennms ~]# vim /var/lib/pgsql/12/data/pg_hba.conf 5 g; Z2 j- O* U2 n9 J) C
[root@opennms ~]# systemctl reload postgresql-12.service + g" k3 M1 ]# N
[root@opennms ~]# telnet 172.24.21.38 5432* V) p. T5 g# Q
Trying 172.24.21.38...3 I3 G2 k1 n6 ]+ v* \
telnet: connect to address 172.24.21.38: Connection refused6 i  I) w1 A2 [5 A) T
[root@opennms ~]# telnet 172.24.21.38 54324 v! V8 N, S! W6 D- z8 {6 O
Trying 172.24.21.38...
; w9 Y# G8 O. Z5 wtelnet: connect to address 172.24.21.38: Connection refused
( @% o- X3 L, \% [
2 u. }% x* V& M8 ~- {! C, R- V3 e: b$ F  x; M6 G) t
[root@opennms ~]# vim /var/lib/pgsql/12/data/postgresql.conf ! Q8 K" h6 c8 @" e4 e
[root@opennms ~]# systemctl reload postgresql-12.service 6 O5 v$ ]9 z# V- A% _4 f: O; `
[root@opennms ~]# telnet 172.24.21.38 5432
& d3 Z- K7 z- X4 TTrying 172.24.21.38...# J" b) _! V6 |' S" p, d
telnet: connect to address 172.24.21.38: Connection refused5 h8 A# _! {7 \3 T- U
[root@opennms ~]# systemctl restart postgresql-12.service
1 v/ Y5 [2 w& k  _* {, V) kJob for postgresql-12.service failed because the control process exited with error code. See "systemctl status postgresql-12.service" and "journalctl -xe" for details.5 m8 S: d  r) P/ v/ I
[root@opennms ~]# vim /var/lib/pgsql/12/data/postgresql.conf
. r% b$ \) [8 t6 s& `2 |; H
! ]. L; M* r" D# b配置文件中8 ^" s: z5 x% g6 Z4 V
listen_addresses = '172.24.21.38 '
9 @- ~0 V: @9 f需要添加单引号,才能正常启动postgresql服务:/ p6 k2 p8 d1 t

  Q. @) L- R1 r[root@opennms ~]# vim /var/lib/pgsql/12/data/postgresql.conf 1 M+ p+ V" {. C* c3 v
[root@opennms ~]# systemctl restart postgresql-12.service ) b' n7 ]/ U7 ~: D5 U  w+ m

- |# e1 r& {7 O. j/ y" r/ d
% I. F+ z1 \# ?6 U4 q- k, B[root@opennms ~]# netstat -ntlp
$ S9 n8 x! B: \" X! SActive Internet connections (only servers)# g% O* I& }- y2 q& }
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    * X. h, N4 l% x0 T1 ~
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1422/master         ) m! x, G2 W/ B8 G% U
tcp        0      0 0.0.0.0:60028           0.0.0.0:*               LISTEN      1519/sshd: /usr/sbi ! |; G8 w* g1 m
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      1229/zabbix_agentd  
# t' h* a/ P  |4 g/ J3 K- Ptcp        0      0 172.24.21.38:5432       0.0.0.0:*               LISTEN      98618/postmaster    " l8 b: K- f4 ?+ Y/ U5 q
tcp6       0      0 ::1:25                  :::*                    LISTEN      1422/master         
; d7 e; F9 e! K  R+ H0 H7 [$ L$ Qtcp6       0      0 :::60028                :::*                    LISTEN      1519/sshd: /usr/sbi
! v  _- ?- R; z- m& itcp6       0      0 :::10050                :::*                    LISTEN      1229/zabbix_agentd  
% S0 h1 F7 \' N6 N/ _' |" e8 N9 x) `[root@opennms ~]# telnet 172.24.21.38 5432; D' J1 Q+ h( H: t
Trying 172.24.21.38...) K5 i9 K3 m; c
Connected to 172.24.21.38.6 N, @* c  k3 M+ `% i# a8 \
Escape character is '^]'.
! M9 y! K, J& X3 R% q. t: x! `1 O3 s, r4 }1 e6 b
0 ]/ ?! s$ [' D; q8 L/ \
Connection closed by foreign host.' B+ W9 n' _' {/ I$ |+ V
[root@opennms ~]# & C" V' C4 I+ M! x+ [% L3 M
[root@opennms ~]# vim /var/lib/pgsql/12/data/postgresql.conf
% o* i' S" k1 O9 q& o9 q$ U修改监听地址为* 即可完成pgsql所有地址可以访问:2 f: ~5 w8 p1 W4 ~& n
listen_addresses = '*'3 X* @& E2 g7 m9 g  B1 l: A  [

' m* W9 T2 p5 o- l[root@opennms ~]# systemctl restart postgresql-12.service . r$ {! B  J# t% g1 v* A# Q. t
[root@opennms ~]# netstat -ntlp# ^3 m6 v% W% w
Active Internet connections (only servers)
/ s3 t) C6 b, w* WProto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
6 w) Y0 ?7 ?, Otcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1422/master         " T7 E, s5 W/ P& O# B
tcp        0      0 0.0.0.0:60028           0.0.0.0:*               LISTEN      1519/sshd: /usr/sbi
% C8 {* G1 m2 D, T6 f$ x! x/ ?( ^tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      1229/zabbix_agentd  
/ W0 R) \! Q6 |" Ptcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      99785/postmaster      p) N9 V6 `# p1 F# h! D1 S+ _. K4 @
tcp6       0      0 ::1:25                  :::*                    LISTEN      1422/master         
% a, G6 r, E- ]2 _' W: ]tcp6       0      0 :::60028                :::*                    LISTEN      1519/sshd: /usr/sbi 0 D( R5 P1 n5 v1 l
tcp6       0      0 :::10050                :::*                    LISTEN      1229/zabbix_agentd  - D5 Q. O# I. I4 A! \9 v6 k
tcp6       0      0 :::5432                 :::*                    LISTEN      99785/postmaster    0 c* _( n! \% s- K2 H
[root@opennms ~]# vim /var/lib/pgsql/12/data/postgresql.conf $ ^; n! I. E- W( \+ ]& ]. E/ _' _4 Y
) Y$ |& `( q/ @+ g2 p
[root@opennms ~]# telnet 172.24.21.38 5432
8 ^0 U, o+ R) i) ^; l$ }- S0 ITrying 172.24.21.38...( T5 C9 B' r/ v# Z, a
Connected to 172.24.21.38.
3 a+ u9 `7 Y; o6 GEscape character is '^]'.7 R0 b. e8 r' z1 P) {2 S% Q

3 }' p- G: k, U& D0 v  D0 o' R0 P/ i. x9 r

4 s6 @6 G- V3 f$ o" A7 j& |9 e
6 L3 }" n$ }# J# U( ?4 s& `
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 04:07 , Processed in 0.017358 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表