# 下载certbot-auto wget -c https://dl.eff.org/certbot-auto -P /usr/local/bin # 设置可执行权限 chmod +x /usr/local/bin/certbot-auto # 查看版本,第一次运行certbot-auto会安装依赖 certbot-auto --version
certbot-auto certonly -d *.example.com --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory
certonly 安装模式
-d 申请证书的域名,如果是通配符域名输入 *.example.com
--manual 手动安装插件
--preferred-challenges dns 使用 DNS 方式校验域名所有权
--server,Let's Encrypt ACME v2 版本使用的服务器不同于 v1 版本,需要显示指定
# 输入电子邮箱,用于续费和安全通知 Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): xxx@163.com # 服务条款,A:同意,C:取消 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (A)gree/(C)ancel: A # 是否订阅相关的邮件 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing, once your first certificate is successfully issued, to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web,EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: N # IP绑定 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NOTE: The IP of this machine will be publicly logged as having requested this certificate. If you're running certbot in manual mode on a machine that is not your server, please ensure you're okay with that. Are you OK with your IP being logged? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y
配置DNS TXT记录
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please deploy a DNS TXT record under the name _acme-challenge.example.com with the following value: pzBqECpVNkjt8gx76qVAYevMFg6n_8dfq-Xqr2f9dI8 Before continuing, verify the record is deployed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press Enter to Continue
到购买域名的服务商控制台解析域名
添加一条TXT记录
主机记录:_acme-challenge.example.com
记录值:pzBqECpVNkjt8gx76qVAYevMFg6n_8dfq-Xqr2f9dI8
记录生效后,回车
Waiting for verification... Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem Your cert will expire on 2020-12-21. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
证书目录:/etc/letsencrypt/live/example.com
ls /etc/letsencrypt/live/example.com cert.pem chain.pem fullchain.pem privkey.pem README
创建续订证书脚本
touch /usr/local/bin/sslrenew.sh
编辑脚本内容
在sslrenew.sh文件中添加以下内容
certbot-auto renew
设置脚本可执行
chmod +x /usr/local/bin/sslrenew.sh
编辑定时任务,每月1号执行续订操作
crontab -e
添加定时逻辑
0 0 1 * * /usr/local/bin/sslrenew.sh
重新加载定时任务
service crond reload
查看定时任务列表
crontab -l
server { listen 443 ssl; server_name localhost; location / { root html; index index.html index.htm; } ssl on; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; ssl_prefer_server_ciphers on; ssl_certificate /etc/letsencrypt/live/example.com/cert.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; }
作者:dean_a6f5
链接:https://www.jianshu.com/p/7b65cc562bc3
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
微信
支付宝