DBAtlas · 数据库运维图谱

TLS / 证书过期

症状

出现 'certificate has expired'、'SSL handshake failed',客户端突然无法连接(代码没有任何变更)。

1. 问题出在哪里:服务器、客户端还是 CA?

是服务器证书过期、客户端证书过期,还是证书链中的某个 CA 过期?典型症状是“昨天还能用,今天不行了,代码没改过”。

2. 检查到期时间

直接从服务器读取证书的到期日期(一种快速且与数据库无关的方法)。

PostgreSQL

openssl s_client -connect host:5432 -starttls postgres </dev/null 2>/dev/null | openssl x509 -noout -dates

MongoDB

openssl s_client -connect host:27017 </dev/null 2>/dev/null | openssl x509 -noout -enddate

Redis

openssl s_client -connect host:6379 </dev/null 2>/dev/null | openssl x509 -noout -enddate

3. 安装并加载新证书

替换证书,大多数情况下无需重启即可重新加载服务。

PostgreSQL

-- Renew ssl_cert_file/ssl_key_file, then:
SELECT pg_reload_conf();

MySQL

ALTER INSTANCE RELOAD TLS;

SQL Server

-- SQL Server Configuration Manager > Certificate; a service restart is required

MongoDB

// Renew the net.tls.certificateKeyFile file (at the same path), then load it without a restart (5.0+):
db.adminCommand({rotateCertificates: 1})

Redis

CONFIG SET tls-cert-file /path/new.crt
CONFIG SET tls-key-file /path/new.key

Elasticsearch

# ES watches the certificate/key files (PEM, PKCS#12) defined under xpack.security.*.ssl and
# reloads them automatically when the file at the SAME path changes (no restart needed).
# If the path, file name or keystore password changes, a rolling restart is required.
# Note: POST _nodes/reload_secure_settings is only for reloadable keystore settings, not for TLS certificates.
# Verify: check the new expiry date with openssl s_client and look in the ES logs for
# an entry showing the certificate was reloaded.

4. 验证

用上面的 openssl 命令确认使用新证书的 TLS 握手成功且到期时间已延长;用客户端进行端到端连接。

5. 永久措施:杜绝再次发生

在证书到期前 30 天设置告警;使用自动续期(ACME/Let's Encrypt、HashiCorp Vault、cert-manager)。将续期后的重新加载自动化。

在 DBAtlas 中打开 →