最近由于想要同时部署多个服务到自己的主机上,而自己又懒得记ip地址,所以想要用子域名来代替,。,
这里安装的certbot是针对centos的,安装教程由certbot提供
证书申请
按照上面的教程安装完之后,主机会增加certbot
命令,运行命令
certbot certonly -d *.域名 --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory
这里也可以使用docker安装,使用这个命令(使用docker的话就省去了安装python包到自己主机,适合有强迫症的人,docker安装yum install -y docker
)
下面的命令直接运行即可,会自动拉取镜像并运行,运行结束后删除进程。
docker run -it --rm --name certbot
-v "/etc/letsencrypt:/etc/letsencrypt"
-v "/var/lib/letsencrypt:/var/lib/letsencrypt"
certbot/certbot certonly -d *.域名 --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory
按照提示确认,之后会出现DNS TXT验证
Please deploy a DNS TXT record under the name
_acme-challenge.域名 with the following value:
pbE8J3xMqc6AuyI1EcM70cpUCeXT91ubqu5LQrD_KHc
Before continuing, verify the record is deployed.
注意这里不要直接按回车。。。。。。
这个时候你需要打开你使用的域名解析的网站,如腾讯云,阿里云等,这里以腾讯云为例
接下来可以运行下面的命令,来实时检测自己的配置是否生效
watch -d -n 2 dig -t txt _acme-challenge.域名 @8.8.8.8
出现下面的;; ANSWER SECTION:
的内容即为配置生效,按下回车即可生成证书
Every 2.0s: dig -t txt _acme-challenge.madongyu.ml ... Sat Oct 13 10:44:00 2018
; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7_5.1 <<>> -t txt _acme-challenge.madongyu.ml
@8.8.8.8
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17549
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;_acme-challenge.madongyu.ml. IN TXT
;; ANSWER SECTION:
_acme-challenge.madongyu.ml. 537 IN TXT "OslTGuM0ETDx6S1Shwje5NZoj-MgR14
IB94JpoG8tdk"
;; Query time: 108 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: 六 10月 13 10:44:00 CST 2018
;; MSG SIZE rcvd: 112
证书更新
这里博主直接使用certbot renew
会报错。。。。。报的错误如下
Attempting to renew cert (xxx.xx) from /etc/letsencrypt/renewal/madongyu.ml-0001.conf produced an unexpected error: The manual plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.',). Skipping.
All renewal attempts failed. The following certs could not be renewed:
/etc/letsencrypt/live/xxxx.xx/fullchain.pem (failure)
最后通过使用下面的命令解决(和安装证书的时候一样)
docker版,不使用docker的话直接截取后面的命令运行即可。
docker run -it --rm --name certbot
-v "/etc/letsencrypt:/etc/letsencrypt"
-v "/var/lib/letsencrypt:/var/lib/letsencrypt"
certbot/certbot certonly --manual -d '*.madongyu.ml'
更新结束之后重启一下nginx(或者你使用的服务器)