certbot使用教程笔记大全

《certbot使用教程笔记大全》

官方文档:

https://certbot.eff.org/docs/using.html

//安装
# yum install -y certbot

目录结构

# cd /etc/letsencrypt
|  –  accounts 账号文件目录 用于保存创建证书时的信息
|  –  archive 所有生成的证书保存到此目录下(较早版本和所有新版本)
       |  – test1.com 域名对应生成的证书目录
       |  – test2.com 域名对应生成的证书目录
       |  – test3.com 域名对应生成的证书目录
       ...
|  –  csr 证书记录文件夹
       |  – 0000_csr-certbot.pem 生成的证书记录
       ...
|  –  keys 密钥记录文件夹
       |  – 0000_key-certbot.pem 生成的密钥记录
       ...
|  –  live  当前在用的证书(由archive生成的软链接指向此目录)
       |  – test1.com 域名对应生成的证书目录软链
       |  – test2.com 域名对应生成的证书目录软链
       |  – test3.com 域名对应生成的证书目录软链
       ...
|  –  renewal 证书续订目录
       |  – test1.com.conf 域名对应生成证书的续订设置
       |  – test2.com.conf 域名对应生成证书的续订设置
       |  – test3.com.conf 域名对应生成证书的续订设置
       ...
|  –  renewal-hooks  续订钩挂目录
....

DNS插件,主要用于自动更新

查看所有生成的证书

//要查看Certbot知道的证书列表,请运行certificates子命令
# certbot certificates
  Certificate Name: example.com
    Domains: example.com, www.example.com
    Expiry Date: 2017-02-19 19:53:00+00:00 (VALID: 30 days)
    Certificate Path: /etc/letsencrypt/live/example.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/example.com/privkey.pem

标识

标识:
certonly 创建
renew    更新
delete   删除

创建证书 如果存在则更新

# certbot certonly \
 --cert-name example.com  //指定证书名称 
//如果使用run或certonly指定了已经存在的证书名称来请求证书,则Certbot将更新现有证书。
//否则,将创建一个新证书并为其指定指定名称。
//如果证书已存在,可以从下面三个选项中选择其中一个:
--force-renewal : (强制更新)使用与现有证书相同的域的新证书 此证书将与较早的证书一起保存,并且符号链接(“ live”引用)
--duplicate     : (副本)建一个单独的,不相关的证书,该证书的域与现有证书的域相同。该证书与之前的证书完全分开保存。在正常情况下,大多数用户将不需要发出此命令
--expand        : (扩展)用包含所有旧域和一个或多个其他新域的新证书更新现有证书
 certbot --expand -d existing.com,example.com,newdomain.com
 certbot --expand -d existing.com -d example.com -d newdomain.com
--allow-subset-of-names : 如果只能获得某些指定的域授权,则继续进行证书生成。如果证书中指定的某些域不再指向该系统,这可能会很有用

通过插件来生成证书

//接下来在/etc/letsencrypt目录中创建一个包含CloudFlare电子邮件和API密钥的配置文件
# vi /etc/letsencrypt/cloudflareapi.ini
dns_cloudflare_email = xxx@qq.com
dns_cloudflare_api_key = 33baxxx3f79daa97d7xxxxxa79xxxd
# chmod 600 /etc/letsencrypt/cloudflareapi.ini

# certbot certonly \
	--cert-name xxxx.cn \
	--dns-cloudflare \
	--dns-cloudflare-credentials /etc/letsencrypt/cloudflareapi.ini \
	--server https://acme-v02.api.letsencrypt.org/directory \
	-d "xxxx.cn" \
	-d "*.xxxx.cn"

更改证书的域

# certbot certonly \
 --cert-name example.com \
 -d example.com   //(--domains的简写为-d)
//可以使用相同的格式来扩展证书包含的域集,或完全替换该域集
#certbot certonly \
 --cert-name example.com \
 -d example.org,www.example.org

吊销证书

//如果您的帐户密钥已被盗用,或者您另外需要吊销证书,请使用revoke命令来这样做。
//请注意,该revoke命令采用证书路径(以结尾cert.pem),而不是证书名称或域
# certbot revoke \   //(吊销标识)
 --cert-path /etc/letsencrypt/live/CERTNAME/cert.pem  //注意是指定的路径而不是域名

删除证书

//吊销证书(或用于其他证书管理任务)后,可以使用delete子命令从系统中删除证书的所有相关文件
# certbot delete \   //(删除标识)
 --cert-name example.com
//如果您没有使用delete删除证书,那么它将在下一次续订事件时自动续签

续订证书

//该命令尝试续订在30天内到期的所有先前获得的证书。
//除非您指定其他插件或选项,否则将使用与最初颁发证书时使用的插件和选项相同的插件和选项。
//不同于certonly,它renew作用于多个证书,并始终考虑每个证书是否即将到期。
//因此,renew适合(并设计为)自动使用,以允许系统在适当时自动续订每个证书。
//由于renew仅更新即将到期的证书,因此可以根据需要频繁运行它-因为通常不会采取任何措施。
# certbot renew \
 --pre-hook "service nginx stop" \
 --post-hook "service nginx start"
//强制更新
# certbot renew --force-renewal
//强制指定更新
# certbot renew --force-renewal --cert-name example.com
点赞

发表评论

邮箱地址不会被公开。 必填项已用*标注