易陆发现互联网技术论坛

 找回密码
 开始注册
查看: 3|回复: 0
收起左侧

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

[复制链接]
发表于 2024-5-25 09:00:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?开始注册

x

# T. J$ I& L  H: ]
( |7 K( V/ @1 w- Z+ N. u[root@opennms ~]# telnet 172.24.21.38 5432* Y! B8 \3 W* X9 Q
Trying 172.24.21.38...0 }, [' `6 p+ z% Y
telnet: connect to address 172.24.21.38: Connection refused
% y" `2 f' I- B4 G# o' Y[root@opennms ~]# ps -ef |grep pg5 Z$ N7 [( y& L
postgres  91577      1  0 13:52 ?        00:00:00 /usr/pgsql-12/bin/postmaster -D /var/lib/pgsql/12/data/
6 K% Q6 E2 H3 d; R7 A/ Wroot      93151  84651  0 13:56 pts/0    00:00:00 grep --color=auto pg
1 C0 J5 k. K# U1 r' |; @- s) h. h- a[root@opennms ~]# vim /var/lib/pgsql/12/# ~6 J% @8 c( d9 Y' y
backups/    data/       initdb.log  
+ ?0 j5 M7 k) D/ w2 D[root@opennms ~]# vim /var/lib/pgsql/12/data/pg_hba.conf
5 E- W# l+ R& k' f- _3 ~, w# _, I: R[root@opennms ~]# systemctl restart postgresql-12.service 7 [5 [1 w1 L3 g+ f
[root@opennms ~]# vim /var/lib/pgsql/12/data/pg_hba.conf
4 p8 |3 F0 h1 U# l* y8 G[root@opennms ~]# netstat -ntlp2 r& `0 K  m1 e: g( R# M5 \7 M$ O
Active Internet connections (only servers)
1 {* ?7 r, p! w0 iProto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    $ d0 B& r$ ]- x2 d/ X7 |% z
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1422/master         
# d. `7 v9 W" D6 l$ k! r, y2 ftcp        0      0 0.0.0.0:60028           0.0.0.0:*               LISTEN      1519/sshd: /usr/sbi " v' ]- g: ]$ ]
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      1229/zabbix_agentd  2 s$ d* e; e5 `& z4 O# Z4 e
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      94593/postmaster   
7 G5 l+ g7 M7 z- K/ }tcp6       0      0 ::1:25                  :::*                    LISTEN      1422/master         9 w( L2 f2 [' ~! S8 `6 j0 g
tcp6       0      0 :::60028                :::*                    LISTEN      1519/sshd: /usr/sbi
" M$ t* D! T1 W+ F. ftcp6       0      0 :::10050                :::*                    LISTEN      1229/zabbix_agentd  
. L; G% M& C! X% Dtcp6       0      0 ::1:5432                :::*                    LISTEN      94593/postmaster    5 ]: y+ ?: d& {6 t# H. P
[root@opennms ~]# vim /var/lib/pgsql/12/data/pg_hba.conf
+ t- C) }# _3 j* Z8 Y1 c4 m[root@opennms ~]# systemctl restart postgresql-12.service
# V) n  j0 t9 U/ ]# W[root@opennms ~]# netstat -ntlp" G" X% X3 K7 i
Active Internet connections (only servers)- Z9 m5 I; B# L% i, E
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
( _& Y- e' A# C0 rtcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1422/master         ' K% S1 Y- b- ?$ E- R1 h3 V0 E' o7 D
tcp        0      0 0.0.0.0:60028           0.0.0.0:*               LISTEN      1519/sshd: /usr/sbi   t# {( k: U8 q9 _# p
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      1229/zabbix_agentd  : w0 y  d6 Z. o
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      95523/postmaster      U- B5 |- e/ w+ V
tcp6       0      0 ::1:25                  :::*                    LISTEN      1422/master         
7 V6 G/ {$ u4 t3 \% a5 H7 ?tcp6       0      0 :::60028                :::*                    LISTEN      1519/sshd: /usr/sbi
6 w6 A# o% h: V( N5 k& \; C% q) b6 Etcp6       0      0 :::10050                :::*                    LISTEN      1229/zabbix_agentd  
$ C3 a$ M! _. R+ S. q; d/ Htcp6       0      0 ::1:5432                :::*                    LISTEN      95523/postmaster   
% z3 J5 H+ C, H! V. ~" d7 ~  K[root@opennms ~]# telnet 172.24.21.38 5432
# C# w& S& x& h8 v. }9 jTrying 172.24.21.38...
  J* N; Z! w# {3 Q7 vtelnet: connect to address 172.24.21.38: Connection refused
) l0 c$ ~1 h; l5 N" e+ v[root@opennms ~]# systemctl reload postgresql-12.service 3 `* h/ W* K, M5 v7 \1 a4 U# `
[root@opennms ~]# telnet 172.24.21.38 5432
" E9 c+ F4 J: k1 c9 ITrying 172.24.21.38...' B9 _! p1 }& i+ J; K  s# h
telnet: connect to address 172.24.21.38: Connection refused
- t" F: W4 B; r& R. A[root@opennms ~]# vim /var/lib/pgsql/12/data/pg_hba.conf 1 M3 y) b+ r4 A6 @0 L; _& `; T
[root@opennms ~]# systemctl reload postgresql-12.service 5 c2 m1 @6 H$ \
[root@opennms ~]# telnet 172.24.21.38 5432
" [, o' l2 {) f2 E6 ZTrying 172.24.21.38...
& [7 c  |+ i; p4 E' W" ?& ntelnet: connect to address 172.24.21.38: Connection refused3 p0 V# c; S/ T. X
[root@opennms ~]# telnet 172.24.21.38 5432  W' ~. E. J" M* _
Trying 172.24.21.38...
9 _( q0 ^. q9 J& htelnet: connect to address 172.24.21.38: Connection refused
  O5 A) ^2 `, ?8 K, |; s' `3 v- T0 }# _# U6 b) g( j  @
* l$ W  R: m' `) S( U# U7 S
[root@opennms ~]# vim /var/lib/pgsql/12/data/postgresql.conf
# G* Y) t- x4 B. `[root@opennms ~]# systemctl reload postgresql-12.service
/ U2 J" Z( S( e6 B0 U[root@opennms ~]# telnet 172.24.21.38 5432- u9 N2 Y1 f0 @% F$ I, I1 {* U0 [# {
Trying 172.24.21.38...2 E# Y; t4 K: M2 A+ i
telnet: connect to address 172.24.21.38: Connection refused
9 L( a6 r/ j$ z6 T$ Y! b[root@opennms ~]# systemctl restart postgresql-12.service
- G) A0 v! V9 a' @# S3 PJob for postgresql-12.service failed because the control process exited with error code. See "systemctl status postgresql-12.service" and "journalctl -xe" for details.3 j' l# N9 s( y( [/ B( q5 X
[root@opennms ~]# vim /var/lib/pgsql/12/data/postgresql.conf ) L: Z/ K' j7 l, s

; v( z2 Q% F" r0 I% [) V配置文件中4 C, I- O2 U6 Y
listen_addresses = '172.24.21.38 '
8 ]  h/ K  X8 D, h4 B; {8 _需要添加单引号,才能正常启动postgresql服务:
# B: O+ D. W+ X' G$ k+ _, J, S
5 P) k  ]/ f: o# g$ h, v4 c: J" I[root@opennms ~]# vim /var/lib/pgsql/12/data/postgresql.conf " o0 ?+ r4 k' H% C/ i& T, F# |
[root@opennms ~]# systemctl restart postgresql-12.service ; m& ?3 b) [7 [5 ^3 L" M

! e$ a- n) c1 P- G- a
: |( S8 F: b  o8 \$ R' K8 _[root@opennms ~]# netstat -ntlp% D6 t% H$ |5 k# Z& ^
Active Internet connections (only servers)3 J- a0 ?- l* b+ H4 p' ]5 Y
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
# I* z8 z& {7 ]% c: d0 ktcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1422/master         
8 Y; z& X) T7 xtcp        0      0 0.0.0.0:60028           0.0.0.0:*               LISTEN      1519/sshd: /usr/sbi
2 J& `4 }4 \4 x' j/ \$ Ntcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      1229/zabbix_agentd  ) ^/ v- V- n$ G6 o& |9 P
tcp        0      0 172.24.21.38:5432       0.0.0.0:*               LISTEN      98618/postmaster   
/ F8 C8 a1 L& I8 @, i$ E0 L2 b: btcp6       0      0 ::1:25                  :::*                    LISTEN      1422/master         + y8 a" O% y: ^2 i
tcp6       0      0 :::60028                :::*                    LISTEN      1519/sshd: /usr/sbi # E& O9 b" y5 c' d' q+ V* C' q8 R! }
tcp6       0      0 :::10050                :::*                    LISTEN      1229/zabbix_agentd  
; w' P8 P& A! Z; T  J2 B/ ?[root@opennms ~]# telnet 172.24.21.38 54326 U7 [* d- w, a! D
Trying 172.24.21.38...- l5 v( }* ]# S% x! n
Connected to 172.24.21.38.
; n1 }, o5 o  _) H: JEscape character is '^]'.4 y6 U, _3 W9 A& I' i$ \
" T" H% W8 y/ \5 p3 }. ^- _5 O

+ k" D$ X' Y( B. y1 o' v. U, VConnection closed by foreign host.; e8 G; y/ K* a) t6 a2 j
[root@opennms ~]# 0 K* R  ?6 \* Q& w4 z, H, `
[root@opennms ~]# vim /var/lib/pgsql/12/data/postgresql.conf ) U% ?7 o; v/ p8 |: c4 |8 @% b$ c
修改监听地址为* 即可完成pgsql所有地址可以访问:
  T" e/ X. h: ^5 Plisten_addresses = '*'
6 K0 D! D, ^/ Z: n
! c: I  s. g9 }5 b! t[root@opennms ~]# systemctl restart postgresql-12.service 5 n- W' }. }% z0 j
[root@opennms ~]# netstat -ntlp) |0 Z! D+ R& }9 s) B
Active Internet connections (only servers)
& S/ i# M% Q' X8 e8 ?. \8 ZProto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    / q/ n0 h- i8 K/ o# F6 b+ L
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1422/master         ( W, U+ T" z) K  Q1 ]! a
tcp        0      0 0.0.0.0:60028           0.0.0.0:*               LISTEN      1519/sshd: /usr/sbi 5 _1 o: P, C$ \* D8 R7 w
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      1229/zabbix_agentd  
4 u: U5 v* g; }5 d5 z, stcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      99785/postmaster    4 u4 o, M% j$ r; f& x. \
tcp6       0      0 ::1:25                  :::*                    LISTEN      1422/master         
! l+ r" u. R" etcp6       0      0 :::60028                :::*                    LISTEN      1519/sshd: /usr/sbi 5 @) h0 k$ r+ J& Z* p# S& y& x( }! ]
tcp6       0      0 :::10050                :::*                    LISTEN      1229/zabbix_agentd  1 @, K' J" S3 x, a6 Y7 f0 \
tcp6       0      0 :::5432                 :::*                    LISTEN      99785/postmaster   
3 A) y, d( P. B+ C[root@opennms ~]# vim /var/lib/pgsql/12/data/postgresql.conf 1 ]& N; `; L3 m( i
+ j; {' j  @& k1 D& w* Z# Y
[root@opennms ~]# telnet 172.24.21.38 5432
! R+ p" o7 G3 T5 `, s2 XTrying 172.24.21.38...
# e8 g- d" M1 H+ d! T$ HConnected to 172.24.21.38., `; A1 V4 x( n/ t/ c
Escape character is '^]'.
$ K5 z7 ]0 f7 J! j! z) R' O( N
: ], y3 H# ^: a) p+ R3 O' h
, y2 c, c" i' H1 w0 h! S7 M
3 v0 _: A5 y) L4 ?4 u' p5 K( a; @7 {4 s9 u: o. n* g1 w! D- X' x+ e, }& c
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

北京云银创陇科技有限公司以云计算运维,代码开发

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )点击这里给我发消息

GMT+8, 2026-4-9 00:01 , Processed in 0.054702 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

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