看的certbot原文檔中說可以自動更新,但是按文檔做了以后自動更新一直沒有成功過议双,通過查找資料發(fā)現(xiàn)每次更新需要操作需要對域名解析做一些操作才行粱侣,所以有一個操作權(quán)限的問題,整理如下卫袒,成功更新證書。
0单匣、下載certbot-auto
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
1夕凝、下載腳本工具
git clone https://github.com/ywdblog/certbot-letencrypt-wildcardcertificates-alydns-au
cd certbot-letencrypt-wildcardcertificates-alydns-au
chmod 0777 au.sh autxy.sh augodaddy.sh python-version/au.sh
2、配置
根據(jù)要更新的域名的提供商户秤,選擇相應(yīng)的腳本:
阿里云(根據(jù)環(huán)境二選一即可):
au.sh (PHP 環(huán)境)
python-version/au.py:(Python環(huán)境码秉,兼容Python 2/3)
騰訊云:autxy.sh(PHP 環(huán)境)
GoDaddy:augodaddy.sh(PHP 環(huán)境)
備注:環(huán)境-代表要執(zhí)行腳本的服務(wù)器支持的環(huán)境
修改DNS API 密鑰:
alydns.php,修改 accessKeyId鸡号、accessSecrec 變量转砖, API key 和 Secrec 官方申請文檔。
txydns.php鲸伴,修改 txyaccessKeyId府蔗、txyaccessSecrec 變量, API 密鑰官方申請文檔汞窗。
python-version/alydns.py礁竞,修改 ACCESS_KEY_ID、ACCESS_KEY_SECRET杉辙, API key 和 Secrec 官方申請文檔。
godaddydns.php捶朵,修改 accessKeyId蜘矢、accessSecrec 變量,GoDaddy API 密鑰官方申請文檔综看。
備注:需要通過 API 操作阿里云 DNS 或騰訊云 DNS 的記錄品腹,所以需要去域名服務(wù)商哪兒獲取 API 密鑰。
4:申請證書
特別說明: –manual-auth-hook 指定的 hook 文件四個任選其一(au.sh红碑、autxy.sh舞吭、augodaddy.sh泡垃、python-version/au.sh),其他操作完全相同羡鸥。
測試是否有錯誤
$ ./certbot-auto certonly -d *.example.com –manual –preferred-challenges dns –dry-run –manual-auth-hook /腳本目錄/au.sh(autxy.sh 或 python-version/au.sh蔑穴,下面統(tǒng)一以 au.sh 介紹)
實(shí)際申請
$ ./certbot-auto certonly -d *.example.com –manual –preferred-challenges dns –manual-auth-hook /腳本目錄/au.sh
參數(shù)解釋:
certonly:表示采用驗(yàn)證模式,只會獲取證書惧浴,不會為web服務(wù)器配置證書
–manual:表示插件
–preferred-challenges dns:表示采用DNS驗(yàn)證申請者合法性(是不是域名的管理者)
–dry-run:在實(shí)際申請/更新證書前進(jìn)行測試存和,強(qiáng)烈推薦
-d:表示需要為那個域名申請證書,可以有多個衷旅。
–manual-auth-hook:在執(zhí)行命令的時候調(diào)用一個 hook 文件
如果你想為多個域名申請通配符證書(合并在一張證書中捐腿,也叫做 SAN 通配符證書),直接輸入多個 -d 參數(shù)即可柿顶,比如:
$ ./certbot-auto certonly -d *.liwf1.net -d *.liwf2.net -d liwf.net –manual –preferred-challenges dns –dry-run –manual-auth-hook /腳本目錄/au.sh
5茄袖、續(xù)期證書
1:對機(jī)器上所有證書 renew
$ ./certbot-auto renew –manual –preferred-challenges dns –manual-auth-hook /腳本目錄/au.sh
2:對某一張證書進(jìn)行續(xù)期
先看看機(jī)器上有多少證書:
$ ./certbot-auto certificates
renew 指定域名證書:
$ ./certbot-auto renew –cert-name simplehttps.com –manual-auth-hook /腳本目錄/au.sh
6、加入 crontab自動更新證書
編輯文件 /etc/crontab嘁锯,由于證書有效期是3個月宪祥,我們設(shè)置一個月進(jìn)行一次更新
crontab -e
0 19 1 * * /bin/sh /opt/script/autossl.sh
autossl.sh:
/root/certbot-auto renew –cert-name liwf.net -deploy-hook “nginx -s reload” –manual-auth-hook ./dev/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh
其中:renew成功后nginx自動重新加載配置
注意:只有單機(jī)建議這樣運(yùn)行,如果要將證書同步到多臺web服務(wù)器猪钮,需要有別的方案