阅读更多
Centos 7.4 操作系统
1、安装Certbot客户端
使用Certbot官方提供的对应平台的RPM包安装Certbot非常简单方便, 进入Certbot官网,在下拉框中选择服务器和操作系统,然后会出现安装代码,如下为CentOS7 Nginx对应的代码
1)安装EPEL软件源,Certbot软件包包含在EPEL软件源中
>yum install epel-release
2)安装Certbot,同时安装Certbot Nginx插件
>yum install certbot-nginx
>pip install --upgrade pip
ImportError: No module named 'requests.packages.urllib3'
>pip install --upgrade --force-reinstall 'requests==2.6.0' urllib3
3)获取证书,并修改Apache服务器配置
sudo certbot --nginx
2、自动更新Let's Encrypt证书
Let's Encrypt证书的有效期为三个月,所以Let's Encrypt证书到期时,要使用Certbot更新证书,Certbot推荐使用Cron或者Systemd Timer每天运行两次更新证书命令,当证书不到期时,不会更新证书,当证书到期后,会自动更新证书。
1)定义Systemd服务certbot.service
>vim /usr/lib/systemd/system/certbot.service
内容如下:
[Unit]
Description=Let's Encrypt renewal
[Service]
Type=oneshot
ExecStart=/usr/bin/certbot renew --quiet --agree-tos
2)定义Systemd Timer:
>vim /usr/lib/systemd/system/certbot.timer
内容如下:
[Unit]
Description=Twice daily renewal of Let's Encrypt's certificates
[Timer]
OnCalendar=0/12:00:00
RandomizedDelaySec=1h
Persistent=true
[Install]
WantedBy=timers.target
3)使Timer开机自动运行
>sudo systemctl enable certbot.timer
4)启动Timer
>sudo systemctl start certbot.timer
5)查看Timer状态
>sudo systemctl status certbot.timer
6)停止Timer
>sudo systemctl stop certbot.timer
7)重启Timer
>sudo systemctl restart certbot.timer