温馨提示×

centos怎样远程用pgadmin

小樊
37
2026-09-21 11:04:48
栏目: 智能运维

在 CentOS 上远程使用 pgAdmin 连接 PostgreSQL,一般有两种常见方式:


一、在 CentOS 上安装 pgAdmin(Web 版,推荐)

1. 添加 pgAdmin 仓库(以 pgAdmin 4 为例)

sudo dnf install -y https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-2-1.noarch.rpm

2. 安装 pgAdmin 4(Web 模式)

sudo dnf install -y pgadmin4-web

3. 初始化 pgAdmin

sudo /usr/pgadmin4/bin/setup-web.sh

按提示设置:

  • 邮箱(登录用)
  • 密码
  • Apache 是否启用

4. 开放防火墙端口(默认 80)

sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload

5. 浏览器远程访问

http://服务器IP/pgadmin4

二、远程连接 PostgreSQL(重要配置)

1. 修改 PostgreSQL 监听地址

编辑:

sudo vi /var/lib/pgsql/15/data/postgresql.conf

(版本号可能不同)

修改:

listen_addresses = '*'

2. 配置允许远程连接

编辑:

sudo vi /var/lib/pgsql/15/data/pg_hba.conf

添加:

host    all    all    0.0.0.0/0    md5

3. 重启 PostgreSQL

sudo systemctl restart postgresql-15

4. 防火墙放行 5432

sudo firewall-cmd --add-port=5432/tcp --permanent
sudo firewall-cmd --reload

三、在 pgAdmin 中添加服务器

  1. 登录 pgAdmin
  2. 右键 Servers → Register → Server
  3. 填写:
    • Host: CentOS 服务器 IP
    • Port: 5432
    • Username / Password

四、其他方式(可选)

  • Windows / macOS 本地装 pgAdmin,直接连 CentOS 的 PostgreSQL(不需在 CentOS 装 pgAdmin)
  • 使用 SSH 隧道(更安全,不开放 5432)

如果你用的是 CentOS 7 / 8 / Stream 或 特定 PostgreSQL 版本,可以告诉我,我可以给你精确命令。

0 踩