温馨提示×

centos怎样配置pgadmin

小樊
40
2026-09-21 10:59:47
栏目: 智能运维

在 CentOS 上配置 pgAdmin(以 pgAdmin 4 为例,目前主流版本)通常有两种方式:

  1. 桌面模式(本地使用)
  2. Web 模式(服务器部署,推荐服务器使用)

下面以 CentOS 7 / CentOS 8 / Rocky / Alma 类似系统 为例说明。


一、安装 PostgreSQL 官方 YUM 源(推荐)

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(rpm -E %{rhel})-x86_64/pgdg-redhat-repo-latest.noarch.rpm

CentOS 7 用:

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

二、安装 pgAdmin 4

方式一:Web 模式(最常用)

sudo dnf install -y pgadmin4-web

或 CentOS 7:

sudo yum install -y pgadmin4-web

三、初始化 pgAdmin Web 服务

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

过程中会提示:

  • 设置 pgAdmin 登录邮箱(管理员账号)
  • 设置密码
  • 是否启用 Apache 配置(一般选 yes)

四、启动并配置防火墙

1. 启动 Apache

sudo systemctl enable httpd
sudo systemctl start httpd

2. 开放防火墙端口

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

五、访问 pgAdmin

浏览器访问:

http://服务器IP/pgadmin4

使用初始化时设置的邮箱和密码登录。


六、连接 PostgreSQL 数据库

  1. 登录 pgAdmin
  2. 右侧 Add New Server
  3. 填写:
    • Name:自定义
    • Host:localhost 或数据库 IP
    • Port:5432
    • Username:postgres
    • Password:数据库密码

若连接 localhost 失败,检查 PostgreSQL 是否允许本地连接: /var/lib/pgsql/<版本>/data/pg_hba.conf


七、常见问题

1. 页面 403 / 无法访问

sudo setsebool -P httpd_can_network_connect on
sudo chown -R apache:apache /var/lib/pgadmin

2. PostgreSQL 未启动

sudo systemctl start postgresql-15

3. 只想要桌面版

sudo dnf install -y pgadmin4-desktop

如果你说的是 CentOS 具体版本 或 Docker 方式 / 离线安装,可以告诉我,我可以给你更精确的配置步骤。

0 踩