certbot自动签发ssl证书
安装certbot
[root@ecs ~]# yum install -y certbot证书操作
http-01验证
签发证书
[root@ecs ~]# certbot certonly -d wiseidc.com -d www.wiseidc.com --webroot -w /data/wwwroot/wiseidc注:使用http-01验证方式,必须保证
http://www.wiseidc.com和http://wiseidc.com能够正常访问。续签证书
[root@ecs ~]# certbot renew --deploy-hook "systemctl restart nginx" [root@ecs ~]# certbot renew --renew-hook "/usr/local/nginx/sbin/nginx -s reload"删除证书
[root@ecs ~]# certbot delete --cert-name wiseidc.com
dns-01验证
安装aliyun-cli
[root@ecs ~]# cd /usr/local/src [root@ecs src]# wget https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgz [root@ecs src]# tar xzvf aliyun-cli-linux-latest-amd64.tgz [root@ecs src]# mv aliyun /usr/local/bin [root@ecs src]# aliyun version 3.4.11配置凭证
[root@ecs ~]# aliyun configure set --profile default --mode AK \ --access-key-id ****** \ --access-key-secret ****** \ --region cn-shanghai--profile default:配置profile名称为default,cat ~/.aliyun/config.json可以看到有多个profiles,通过描述名区分不同的profile。验证ak凭证是否生效,查看当前region区域内的ecs列表:
[root@ecs ~]# aliyun ecs DescribeInstances --profile default安装certbot-dns-aliyun
[root@ecs ~]# cd /usr/local/src [root@ecs ~]# wget http://cdn.jsdelivr.net/gh/justjavac/certbot-dns-aliyun@main/alidns.sh [root@ecs ~]# mv alidns.sh /usr/local/bin [root@ecs ~]# chmod +x /usr/local/bin/alidns.sh [root@ecs ~]# ln -s /usr/local/bin/alidns.sh /usr/local/bin/alidns签发证书
[root@ecs ~]# certbot certonly -d wiseidc.com -d *.wiseidc.com \ --manual --preferred-challenges dns \ --manual-auth-hook "alidns" \ --manual-cleanup-hook "alidns clean" \ --dry-run-d wiseidc.com:指定域名,可以指定多个域名。manual:手动模式。preferred-challenges dns:使用DNS-01方式验证。manual-auth-hook "alidns":在DNS验证时调用alidns脚本。manual-cleanup-hook "alidns clean":在DNS验证完成后调用alidns clean脚本。--dry-run:模拟签发过程,不会实际签发证书,正式签发不需要此参数。
续期证书
[root@ecs ~]# certbot renew --quiet --preferred-challenges dns \ --manual-auth-hook "alidns" \ --manual-cleanup-hook "alidns clean" \ --deploy-hook "systemctl restart nginx"