1. 项目概述:为什么需要私有化SSL证书管理?
SSL证书管理是每个运维工程师的必修课。过去几年我经手过数百个证书的部署和续期,最头疼的就是证书过期导致的业务中断。去年我们一个核心业务因为证书过期宕机47分钟,直接损失六位数。传统人工管理方式在证书数量超过20个时就显得力不从心,这正是Certd这类自动化工具的价值所在。
Certd作为开源的证书管理平台,相比商业方案最大的优势是支持私有化部署。这意味着:
- 企业可以完全掌控证书私钥,满足金融、政务等行业的合规要求
- 能与内部CMDB、监控系统深度集成
- 避免将证书管理这种核心业务依赖第三方服务
2. 私有化部署全流程详解
2.1 基础环境准备
推荐使用以下配置(实测稳定运行3年+):
# 最低配置 CPU: 4核 内存: 8GB 存储: 100GB SSD OS: Ubuntu 20.04 LTS # 生产环境建议 CPU: 8核 内存: 16GB 存储: 200GB SSD RAID1关键依赖安装:
# 必须组件 sudo apt update && sudo apt install -y \ docker-ce \ docker-compose-plugin \ nginx \ certbot # 验证Docker docker run --rm hello-world特别注意:所有涉及证书操作的服务器必须确保时间同步,建议部署NTP服务。我们曾遇到因时间不同步导致ACME验证失败的案例。
2.2 Certd核心组件部署
下载最新release包(以v1.3.2为例):
wget https://github.com/certd/certd/releases/download/v1.3.2/certd-server.tar.gz tar -zxvf certd-server.tar.gz cd certd-server配置文件修改要点:
# configs/application-prod.yml acme: email: admin@yourcompany.com # Let's Encrypt通知邮箱 server: https://acme-v02.api.letsencrypt.org/directory storage: type: s3 # 推荐生产环境使用 s3: endpoint: https://your-s3-endpoint bucket: certd-bucket accessKey: AKIAxxxxxxxx secretKey: xxxxxxxxxxxxxxx启动命令:
docker-compose up -d验证服务:
curl http://localhost:8080/api/health | jq # 正常返回:{"status":"UP"}3. 证书自动化管理实战
3.1 证书申请流程配置
通过API申请证书的完整示例:
curl -X POST "http://certd.yourdomain.com/api/certificates" \ -H "Authorization: Bearer your-api-token" \ -H "Content-Type: application/json" \ -d '{ "domains": ["example.com", "www.example.com"], "provider": "letsencrypt", "autoRenew": true, "notifyBeforeExpire": 30, "notifyChannels": ["email", "webhook"], "webhookUrl": "https://your-monitor-system/alerts" }'关键参数说明:
autoRenew: 开启自动续期(默认提前30天)notifyBeforeExpire: 过期前N天通知webhookUrl: 与内部监控系统集成的关键配置
3.2 证书自动部署方案
Nginx自动部署配置示例:
server { listen 443 ssl; server_name example.com; ssl_certificate /etc/nginx/certs/example.com/fullchain.pem; ssl_certificate_key /etc/nginx/certs/example.com/privkey.pem; # Certd自动更新触发reload location /certd-webhook { allow 10.0.0.0/8; deny all; proxy_pass http://127.0.0.1:8080; } }对应的Certd webhook配置:
deployHooks: - type: nginx target: web01.yourdomain.com reloadCmd: "sudo systemctl reload nginx" credential: type: ssh username: deploy privateKey: "{{ env.SSH_PRIVATE_KEY }}"4. 生产环境运维要点
4.1 高可用架构设计
建议的集群部署方案:
+-----------------+ | Load Balancer | +--------+--------+ | +---------------+---------------+ | | | +-------+-------+ +-----+-------+ +-----+-------+ | Certd Node1 | | Certd Node2 | | Certd Node3 | | (MySQL Slave) | | (MySQL Slave) | | (MySQL Master) | +-------+-------+ +-----+-------+ +-----+-------+ | | | +---------------+---------------+ | +--------+--------+ | Shared Storage | | (S3/NFS) | +-----------------+4.2 监控与告警配置
Prometheus监控指标示例:
- job_name: 'certd' metrics_path: '/actuator/prometheus' static_configs: - targets: ['certd01:8080', 'certd02:8080']关键监控项:
certd_cert_expire_days: 证书剩余天数certd_acme_challenge_failures: ACME验证失败次数certd_renewal_attempts: 续期尝试次数
4.3 常见故障排查
典型问题1:ACME验证失败
ERROR [ACME Challenge] Failed to verify domain example.com: Connection refused (Challenge type: http-01)解决方案:
- 检查80端口是否开放
- 验证
.well-known/acme-challenge/目录可访问 - 确保DNS解析正确
典型问题2:证书续期失败
WARN [Certificate Renew] Renew failed for cert_id=12345: Rate limit exceeded (Error code: 429)解决方案:
- 检查同一域名是否在7天内申请超过5次
- 临时切换至其他ACME服务商(如BuyPass)
- 使用
certd-cli force-renew --cert-id 12345
5. 进阶应用场景
5.1 与Kubernetes集成
通过Cert-Manager联动方案:
apiVersion: cert-manager.io/v1 kind: Issuer metadata: name: certd-issuer spec: acme: server: https://certd.yourdomain.com/acme/directory email: admin@yourcompany.com privateKeySecretRef: name: certd-issuer-account-key solvers: - http01: ingress: class: nginx5.2 企业内部CA集成
配置私有CA的示例:
ca: enabled: true rootCert: | -----BEGIN CERTIFICATE----- MIIDXTCCAkWgAwIBAgIJAJC1HiIAZAiUMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV ... -----END CERTIFICATE----- rootKey: | -----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC7V9... -----END PRIVATE KEY-----签发内部证书的API调用:
curl -X POST "http://certd.yourdomain.com/api/ca/issue" \ -H "Authorization: Bearer your-api-token" \ -d '{ "commonName": "internal-app01", "dnsNames": ["app01.internal"], "validDays": 365 }'6. 安全加固建议
密钥存储安全
- 使用HashiCorp Vault管理私钥
- 开启S3存储桶加密
- 限制SSH密钥访问范围
访问控制
-- 数据库权限示例 CREATE USER 'certd_rw'@'10.%' IDENTIFIED BY 'complex-password-here'; GRANT SELECT, INSERT, UPDATE ON certd.* TO 'certd_rw'@'10.%';审计日志配置
logging: level: root: INFO org.springframework.security: DEBUG file: path: /var/log/certd/audit.log max-history: 30
在实施自动化证书管理后,我们的运维团队成功将证书相关事故降为零。有个实用建议:对于首次部署,可以先在测试环境用--dry-run参数验证整个流程。记得定期检查ACME账户的rate limit状态,这个细节曾让我们避免了生产环境的中断风险。