温馨提示×

centos怎么配置pgadmin

小樊
42
2026-09-09 05:22:42
栏目: 智能运维

CentOS 上配置 pgAdmin(以 pgAdmin 4 为例,目前最常用),常见有两种方式:

  1. Web 模式(推荐,服务器常驻)
  2. 桌面模式(仅桌面环境)

下面以 CentOS 7 / 8 / Stream + pgAdmin 4 (Web) 为例说明。


一、环境准备

1. 安装 EPEL 源

sudo yum install -y epel-release

2. 安装 PostgreSQL 官方源(可选,但推荐)

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

二、安装 pgAdmin 4(Web 模式)

1. 安装 pgAdmin 4

sudo yum install -y pgadmin4-web

三、初始化 pgAdmin 4

1. 执行初始化脚本

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

过程中会提示:

  • 设置 pgAdmin 登录邮箱
  • 设置 登录密码

示例:

Email address: admin@local.com
Password: ********

四、配置 Nginx(可选但推荐)

1. 安装 Nginx

sudo yum install -y nginx

2. 示例 Nginx 配置

server {
    listen 80;
    server_name pgadmin.example.com;

    location / {
        proxy_pass http://127.0.0.1:5050;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
sudo systemctl restart nginx

五、启动 pgAdmin

1. 启动服务

sudo systemctl start httpd        # 如果使用 Apache
# 或
sudo systemctl start nginx

pgAdmin 默认监听:

http://服务器IP:5050

六、防火墙配置

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

七、登录 pgAdmin

浏览器访问:

http://服务器IP:5050

使用初始化时设置的:

  • 邮箱
  • 密码

八、添加 PostgreSQL 服务器

  1. 登录 pgAdmin
  2. 左侧 Servers → Add New Server
  3. 填写:
    • Host: 127.0.0.1 或远程 IP
    • Port: 5432
    • Username / Password

九、常见问题

1. 页面打不开

  • 检查服务是否启动
  • 检查防火墙
  • 查看日志:
/var/log/pgadmin/pgadmin4.log

2. 远程无法连接 PostgreSQL

修改:

# postgresql.conf
listen_addresses = '*'

# pg_hba.conf
host all all 0.0.0.0/0 md5

如果你用的是 CentOS 哪个版本pgAdmin 3 还是 4Web 还是桌面,可以告诉我,我可以给你更精确的步骤。

0