SECURITY
CentOS 7 上使用Certbot申请通配符证书
在CentOS7上安装Certbot有三种方式: 使用Certbot官方提供的对应平台的RPM包安装 使用Certbot官方的提供的certbot-auto安装 使用pip安装Certbot,因为Certbot是Python程序 本文使用虚拟环境,使用pip安装Certbot 创建虚拟环境:可参考https://meaninglive.com/2020/06/15/%E5%88%9B%E5%BB%BA%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83-ansible-python3-and-virtualenvs-on-centos-and-rhel/ 创建所需环境:
1 2 3 4 |
mkvirtualenv certbot workon certbot pip install -U setuptools pip pip install certbot-dns-route53 参考:https://wsgzao.github.io/post/certbot/ |
用如下命令申请证书 注意替换成自己的域名;执行该命令时不依赖nginx:
1 2 3 4 5 |
certbot -d meaninglive.com \ -d *.meaninglive.com \ --manual --preferred-challenges dns-01 \ --server https://acme-v02.api.letsencrypt.org/directory \ certonly --agree-tos |
介绍下相关参数: certonly,表示安装模式,Certbot 有安装模式和验证模式两种类型的插件。 –manual 表示手动安装插件,Certbot 有很多插件,不同的插件都可以申请证书,用户可以根据需要自行选择 -d 为那些主机申请证书,如果是通配符,输入 *.devapi.haoshiqi.net(可以替换为你自己的域名) –preferred-challenges dns,使用 DNS 方式校验域名所有权 –server,Let’s Encrypt ACME v2 版本使用的服务器不同于 v1 版本,需要显示指定。 输入应急邮箱,证书到期前会有邮件提示 如果想跳过输入邮箱的步骤,可在申请命令后面加上:
1 |
--register-unsafely-without-email |
之后出现如下提示:要公开记录申请该证书的IP地址,是否同意?不同意就无法继续。 同意之后,出现如下提示,第一个“Press Enter to Continue”处直接回车,第二个“Press Enter to Continue”不要按回车:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
------------------------------------------------------------------------------- Please deploy a DNS TXT record under the name _acme-challenge.co1dawn.com <span class="hljs-keyword">with</span> the following value: iLS0NjcdP3RR1KphB6xbbVnKS_NS2uMW-xdDRzz85OM Before continuing, verify the record is deployed. ------------------------------------------------------------------------------- Press Enter to Continue #此处直接回车 ------------------------------------------------------------------------------- Please deploy a DNS TXT record under the name _acme-challenge.co1dawn.com <span class="hljs-keyword">with</span> the following value: f3V7aw5GPm5yzNsJFanQQaUFMyVQcqriUe3UjIDUHn0 Before continuing, verify the record is deployed. ------------------------------------------------------------------------------- Press Enter to Continue #此处不要按回车 |
为DNS解析增加TXT记录 进入自己域名的DNS记录管理页面,增加两条TXT记录,多数情况下,仅需在域名(Name)处填入_acme-challenge,在内容(Target)处填入上一步Certbot生成的内容即可(记得填写两个,多个文本记录之间以换行符(Enter键)分隔),不同DNS提供商处可能会略有不同,根据实际情况修改, 如果是www.name.com的域名的话, 就分别写两条相同主机名的记录, 填写不同的记录 稍等片刻,等TXT记录解析生效。查看是否生效的命令和生效后的查询结果如下: host -t Read more…