温馨提示×

centos pgadmin怎么远程访问

小樊
43
2026-10-12 00:46:13
栏目: 智能运维

在 CentOS 上配置 pgAdmin 远程访问,通常有两种常见场景:

  1. pgAdmin 安装在 CentOS 服务器,通过浏览器远程访问(pgAdmin 4 Web 模式)
  2. pgAdmin 安装在你的本地电脑,远程连接 CentOS 上的 PostgreSQL

下面分别说明。


一、pgAdmin 4 Web 模式(推荐服务器部署)

1. 安装 pgAdmin 4(CentOS)

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y pgadmin4-web

2. 配置 pgAdmin

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

按提示设置:

  • 登录邮箱
  • 登录密码

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

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

4. 远程访问

浏览器访问:

http://服务器IP/pgadmin4

✅ 适合团队使用,不依赖本地安装


二、本地 pgAdmin 远程连接 CentOS PostgreSQL

1. CentOS 上 PostgreSQL 允许远程

编辑配置文件:

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

(版本号按实际)

修改:

listen_addresses = '*'

2. 配置 pg_hba.conf

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. 开放防火墙

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

5. 本地 pgAdmin 添加服务器

  • Host:CentOS 公网/内网 IP
  • Port:5432
  • Username / Password

三、安全建议(重要)

  • ✅ 不要用 0.0.0.0/0,改为具体 IP
  • ✅ 使用 SSH 隧道更安全
  • ✅ Web 模式建议加 Nginx + HTTPS

如果你能告诉我:

  • CentOS 版本
  • PostgreSQL 版本
  • pgAdmin 是 Web 还是桌面版

我可以给你更精确的命令。

0 踩