场景:验证 PostgreSQL 服务器
场景:验证 PostgreSQL 服务器
我们建议您使用 TLS 证书对 PostgreSQL 服务器进行身份验证。您可以使用来自可信证书颁发机构 (CA) 的证书或自签名证书。请使用来自可信 CA 的证书,因为自签名证书仅提供有限保护。
管理服务器支持 PostgreSQL 的单向和双向 SSL 身份验证。
请按照以下步骤为 PostgreSQL 配置 SSL 身份验证:
- 为 PostgreSQL 服务器生成证书。
运行以下命令:
openssl req -new -x509 -days 365 -nodes -text -out psql.crt -keyout psql.key -subj "/CN=psql"
chmod og-rwx psql.key
- 为管理服务器生成证书。
运行以下命令。CN 值应与代表管理服务器连接到 PostgreSQL 的用户名匹配。默认情况下,用户名设置为 postgres。
openssl req -new -x509 -days 365 -nodes -text -out postgres.crt -keyout postgres.key -subj "/CN=postgres"
chmod og-rwx postgres.key
- 配置客户端证书身份验证。
修改 pg_hba.conf 如下:
hostssl all all 0.0.0.0/0 md5
确保 pg_hba.conf 不包含以
host
开头的记录。 - 指定 PostgreSQL 证书。
- 重新启动 PostgreSQL 守护进程。
运行以下命令:
systemctl restart postgresql-14.service
- 指定管理服务器的服务器标志。
- 重启管理服务器服务。
Did you find this article helpful?
What can we do better?
Thank you for your feedback! You're helping us improve.
Thank you for your feedback! You're helping us improve.