在 CentOS 上配置 pgAdmin 远程访问 PostgreSQL,通常有两种常见方式:
前提:PostgreSQL 安装在 CentOS 上,你从 Windows / Mac / 另一台 Linux 用 pgAdmin 连接
编辑配置文件(路径可能略有不同):
vi /var/lib/pgsql/<版本>/data/postgresql.conf
修改:
listen_addresses = '*'
编辑:
vi /var/lib/pgsql/<版本>/data/pg_hba.conf
添加(示例:允许所有 IP 使用密码连接):
host all all 0.0.0.0/0 md5
⚠ 生产环境建议限制 IP,例如
192.168.1.0/24
firewall-cmd --add-port=5432/tcp --permanent
firewall-cmd --reload
systemctl restart postgresql
CentOS服务器IP5432sudo rpm -i https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-2-1.noarch.rpm
sudo yum install pgadmin4-web -y
sudo /usr/pgadmin4/bin/setup-web.sh
按提示设置登录邮箱和密码。
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
http://CentOS_IP/pgadmin4
0.0.0.0pg_hba.conf 未允许远程setenforce 0
如果你能告诉我:
我可以给你更精确的步骤。