let's encrypt 证书

 

参考:https://www.cnblogs.com/trblog/p/14690908.html

 
 
 
一. 安装方式
 
1. 使用snapd进行安装
 
报错无法更新证书
./certbot-auto renew --no-self-upgrade
 
ubuntu16安装snapd
apt-get update
apt-get -f install
apt-get install -y snapd snapcraft
 
c. 启用snapd.socket。
systemctl enable --now snapd.socket
 
d. 创建/var/lib/snapd/snap和/snap之间的链接。
ln -s /var/lib/snapd/snap /snap
 
e. 退出账号并重新登录,或者重启系统,确保snap启用。
 
f. 将snap更新至最新版本。
snap install core
snap refresh core
 
 
卸载已安装的certbot
如果之前在系统上已经部署过certbot,则需要先将其进行卸载。
a. 卸载certbot。
yum remove certbot
b. 根据certbot安装位置删除相关文件。
rm /usr/local/bin/certbot-auto
c. 删除certbot附加软件包。
rm -rf /opt/eff.org/certbot
 
安装certbot
a. 通过snap安装certbot。
snap install --classic certbot
b. 创建/snap/bin/certbot的软链接,方便certbot命令的使用。
ln -s /snap/bin/certbot /usr/bin/certbot
 
 
 
 
2. 使用pip安装snap, 官网:https://certbot.eff.org/lets-encrypt/pip-other.html
以ubuntu为例子
sudo apt update
sudo apt install python3 python3-venv libaugeas0   #如果已安装python3, 这里只需安装libaugeas0

sudo python3 -m venv /opt/certbot/
sudo /opt/certbot/bin/pip install --upgrade pip

sudo /opt/certbot/bin/pip install certbot

sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot

 

 
 
3. 阿里云插件实现cert证书自动更新(初次测试没成功)
cd certbot-dns-aliyun
sudo python3 setup.py install
 
 
 
 
 
 
二. 阿里云ssl证书自动添加txt,自动续期
 
目前只验证了证书申请,不用手动添加txt;续期和定时任务还没验证。
新老版本的certbot都支持
 
1. 下载
git clone https://github.com/ywdblog/certbot-letencrypt-wildcardcertificates-alydns-au
在au.sh中添加aliyun的key和secret
 
2. 申请证书,可先添加参数--dry-run进行测试
 
certbot-auto certonly --no-self-upgrade -d "*.smartfleet.inhandiot.com" -d "smartfleet.inhandiot.com" --manual --preferred-challenges dns --dry-run --manual-auth-hook "./au.sh python aly add" --manual-cleanup-hook "./au.sh python aly clean"
 
3. 续期
1)对机器上所有证书renew
 
certbot-auto renew  --no-self-upgrade --manual --preferred-challenges dns --manual-auth-hook "/脚本目录/au.sh python aly add" --manual-cleanup-hook "/脚本目录/au.sh python aly clean"
 
2) 对某个证书进行续期
 
certbot-auto certificates --no-self-upgrade  #先看看都有哪些证书,比如simplehttps.com
certbot-auto renew --no-self-upgrade --cert-name simplehttps.com  --manual-auth-hook "/脚本目录/au.sh python aly add" --manual-cleanup-hook "/脚本目录/au.sh python aly clean"
 
4. 添加定时任务
 
#证书有效期<30天才会renew,所以crontab可以配置为1天或1周
1 1 */1 * * root certbot-auto renew --no-self-upgrade --manual --preferred-challenges dns  --manual-auth-hook "/脚本目录/au.sh python aly add" --manual-cleanup-hook "/脚本目录/au.sh python aly clean"
 
如果certbot-auto和web服务器在同一台机器上,更新完证书后可重启相关服务
1 1 */1 * * root certbot-auto renew --no-self-upgrade --manual --preferred-challenges dns --deploy-hook  "cd /data/elements && docker-compose restart nginx emqttd ngrokd" --manual-auth-hook "/脚本目录/au.sh python aly add" --manual-cleanup-hook "/脚本目录/au.sh python aly clean"
 
 
 
 
 
 
 
posted @ 2020-12-14 10:23  坚强的小蚂蚁  阅读(353)  评论(0编辑  收藏  举报