zimbra8.7 Let’s Encrypt ssl证书续期脚本 | 艾利克斯部落

首页 » 邮件服务器 » Zimbra » 正文

zimbra8.7 Let’s Encrypt ssl证书续期脚本

我的zimbra8.7使用的是Let’s Encrypt的ssl证书,使用起来完全没有问题,但其缺点是有效期只有3个月,每3个月需要再次续期,为了避免续期时再次执行复杂的命令,我把它整理为一个脚本,要续期时执行一下脚本即可,脚本如下,如域名不同时只需修改一下脚本开头domain为你的域名即可:

# cat renew_ssl.sh

#!/bin/bash
# Description: this script is for renew zimbra8.7 mail server https ssl, doc please via https://wiki.zimbra.com/wiki/Installing_a_LetsEncrypt_SSL_Certificate
# Note: only tested on zimbra8.7

domain=mail.yourdomain.com

su - zimbra -c 'zmproxyctl stop'
su - zimbra -c 'zmmailboxdctl stop'
cd /opt/software/letsencrypt/
./letsencrypt-auto certonly --standalone

echo "SSL Certificate Files under below:"
ls -a /etc/letsencrypt/live/$domain/

echo '''
-----BEGIN CERTIFICATE-----
MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow
PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD
Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O
rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq
OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b
xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw
7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD
aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV
HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG
SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69
ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr
AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz
R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5
JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo
Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ
-----END CERTIFICATE-----
''' >> /etc/letsencrypt/live/$domain/chain.pem

mkdir /opt/zimbra/ssl/letsencrypt/
cp /etc/letsencrypt/live/$domain/* /opt/zimbra/ssl/letsencrypt/
chown zimbra:zimbra /opt/zimbra/ssl/letsencrypt/*

su - zimbra -c 'cd /opt/zimbra/ssl/letsencrypt/ && /opt/zimbra/bin/zmcertmgr verifycrt comm privkey.pem cert.pem chain.pem '

echo "Backup Zimbra SSL directory"
cp -a /opt/zimbra/ssl/zimbra /opt/zimbra/ssl/zimbra.$(date "+%Y%m%d")

echo "Copy the private key under Zimbra SSL path"
cp /opt/zimbra/ssl/letsencrypt/privkey.pem /opt/zimbra/ssl/zimbra/commercial/commercial.key

echo "Final SSL deployment"
su - zimbra  -c 'cd /opt/zimbra/ssl/letsencrypt/ /opt/zimbra/bin/zmcertmgr deploycrt comm cert.pem chain.pem'

echo "restart zimbra"
su - zimbra -c 'zmcontrol restart'


说明:如果没有成功,请参考原文 https://wiki.zimbra.com/wiki/Installing_a_LetsEncrypt_SSL_Certificate 进行配置。


发表评论

*