Centos 7 环境下 PostgreSQL 14 启用SSL加密

配置 PostgreSQL 14 的 SSL 加密通常涉及到生成 SSL 证书和私钥,然后配置 PostgreSQL 以使用这些证书。

1、生成 SSL 证书和私钥:

使用 OpenSSL 生成自签名 SSL 证书和私钥:

首先,你需要生成 SSL 证书和私钥。可以使用 OpenSSL 工具执行此操作。

openssl req -new -text -out server.req
openssl rsa -in privkey.pem -out server.key
openssl req -x509 -in server.req -text -key server.key -out server.crt

这将生成一个自签名的 SSL 证书 server.crt 和私钥 server.key。

2、将证书和私钥移动到安全位置:

将生成的 server.crt 和 server.key 文件移到一个安全的位置。

mv server.crt /mnt/ssl/private/
mv server.key /mnt/ssl/private/

3、配置 PostgreSQL 使用 SSL:

# 编辑 postgresql.conf 文件
vim /var/lib/pgsql/14/data/postgresql.conf

# 开启SSL
ssl = on
# 指定 SSL 证书和私钥文件的路径
ssl_cert_file = '/mnt/ssl/private/server.crt'
ssl_key_file = '/mnt/ssl/private/server.key'

# 重新加载 PostgreSQL 服务
systemctl restart postgresql-14

4、验证 SSL 配置:

可以使用以下命令连接到 PostgreSQL 数据库,并查看是否成功启用了 SSL:

# 替换 your_database 和 your_username 为你的实际数据库和用户名。
psql "sslmode=require host=localhost dbname=your_database user=your_username"

以上步骤应该允许 PostgreSQL 使用 SSL 加密。请确保证书和私钥是安全的,并仅用于预期的目的。在生产环境中,最好使用由受信任的证书颁发机构(CA)签发的证书。

相关推荐
魏 无羡3 小时前
k8s ssl 漏洞修复
容器·kubernetes·ssl
千墨4 小时前
VMware安装Centos 9虚拟机+设置共享文件夹+远程登录
linux·运维·centos
余衫马15 小时前
CentOS7 离线安装 Postgresql 指南
数据库·postgresql
去看日出1 天前
Linux(centos)系统安装部署MySQL8.0数据库(GLIBC版本)
linux·数据库·centos
weixin_387002151 天前
Openssl之SM2加解密命令
安全·ubuntu·密码学·ssl·命令模式
隔壁老王1561 天前
postgresql实时同步数据表mysql
数据库·mysql·postgresql
孤傲小二~阿沐1 天前
PostgreSQL的学习心得和知识总结(一百六十九)|深入理解PostgreSQL数据库之 Group By 键值消除 的使用和实现
数据库·postgresql
warton881 天前
centos下使用pyenv管理python版本
linux·运维·python·centos
 嘘 1 天前
Centos修改ip
linux·tcp/ip·centos
服务端相声演员1 天前
CentOS环境变量配置+解析
linux·运维·centos