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)签发的证书。

相关推荐
圆山猫13 小时前
[VF2] Boot Ubuntu和Debian发行版
ubuntu·postgresql·debian
startdrift110615 小时前
docker run 命令,不接it选项,run一个centos没有显示在运行,而run一个nginx却可以呢?
nginx·docker·centos
焦思懿--19期--工职大17 小时前
VMWare和centOS的安装
linux·运维·centos
huazhixuthink19 小时前
PostgreSQL三种关闭方式的区别
数据库·postgresql
Orchestrator_me1 天前
CentOS交换区处理
linux·运维·centos
zru_96021 天前
centos 系统如何安装open jdk 8
java·linux·centos
FLS1681 天前
VMwaer虚拟机安装完Centos后无法联网问题
linux·运维·centos
OctopusMonster1 天前
centos下gdb调试python的core文件
linux·运维·centos
XMYX-01 天前
解决 Apache/WAF SSL 证书链不完整导致的 PKIX path building failed 问题
网络协议·apache·ssl
DCTANT2 天前
【报错记录】OpenGauss/磐维数据库连接报:org.postgresql.util.PSQLException: 致命错误: 账户被锁定
数据库·postgresql