zoukankan      html  css  js  c++  java
  • 阿里云负载均衡SLB上用免费的Let's Encrypt的SSL证书

    Let's Encrypt是很火的一个免费SSL证书发行项目,自动化发行证书,证书有90天的有效期。Let's Encrypt已经发布了工具certbot,用此工具生成证书、证书续期非常简单。

    以下是用certbot生成通配符域名证书的使用方法(Centos7为例):

    执行:

    certbot certonly -d *.domain.com --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory
    Are you OK with your IP being logged?
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    (Y)es/(N)o: Y
    Please deploy a DNS TXT record under the name
    _acme-challenge.domain.com with the following value:
    
    *************
    
    Before continuing, verify the record is deployed.

    根据提示,这里需要手动到域名解析的地方添加域名的TXT解析,完成后过几分钟等待生效,并使用nslookup命令检查一下是否生效:

    nslookup -q=TXT _acme-challenge.domain.com

    若TXT解析已生效,在certbot命令行界面敲入回车,进行校验,证书生成成功后提示如下如下:

    IMPORTANT NOTES:
     - Congratulations! Your certificate and chain have been saved at:
       /etc/letsencrypt/live/domain.com/fullchain.pem
       Your key file has been saved at:
       /etc/letsencrypt/live/domain.com/privkey.pem
       Your cert will expire on 2019-11-19. To obtain a new or tweaked
       version of this certificate in the future, simply run certbot
       again. To non-interactively renew *all* of your certificates, run
       "certbot renew"
     - 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

    然后回到阿里云SLB中,找到添加证书的地方,选择已有证书方式进行添加。

    cat命令查看公钥、私钥,并复制到阿里云添加证书的界面中。

    查看公钥:

    cat /etc/letsencrypt/live/domain.com/fullchain.pem

    阿里云要求私钥是-----BEGIN RSA PRIVATE KEY-----开头,所以需要先处理以下私钥文件,转换成RSA私钥,执行以下命令:

    openssl rsa -in /etc/letsencrypt/live/domain.com/privkey.pem -out /etc/letsencrypt/live/domain.com/privkey.rsa.pem

    查看私钥:

    cat /etc/letsencrypt/live/domain.com/privkey.rsa.pem

    以后若需要续SSL证书,只需在该服务器上执行以下命令,并按提示继续:

    certbot renew

    以下是certbot-auto的使用方法,内容来源于网络,供参考借鉴:

    安装方法:
    如果是CentOS 6、7,先执行:yum install epel-release

    cd /root/
    wget https://dl.eff.org/certbot-auto --no-check-certificate
    chmod +x ./certbot-auto
    ./certbot-auto -n
    ./certbot-auto -n只是用来安装依赖包的,也可以跳过直接到下面的生成证书的步骤,国内VPS或服务器上使用的话建议先修改为国内的pip源。

    单域名生成证书:
    ./certbot-auto certonly --email youemail@vpser.net --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.vpser.net -d www.vpser.net

    多域名单目录生成单证书:(即一个网站多个域名使用同一个证书)

    ./certbot-auto certonly --email youemail@vpser.net --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.vpser.net -d www.vpser.net -d bbs.vpser.net

    多域名多目录生成一个证书:(即一次生成多个域名的一个证书)

    ./certbot-auto certonly --email youemail@vpser.net --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.vpser.net -d www.vpser.net -d bbs.vpser.net -w /home/wwwroot/lnmp.org -d www.lnmp.org -d lnmp.org

    证书续期
    cerrbot的续期比原来的更加简单,因为证书只有90天,所以建议使用crontab进行自动续期:

    crontab 里加上如下规则:0 3 */5 * * /root/certbot-auto renew --disable-hook-validation --renew-hook "/etc/init.d/nginx reload" 这样每5天就会执行一次所有域名的续期操作。当然时间也可以自行进行调整,建议别太频繁,因为他们都有请求次数的限制,如果需要强制更新可以在前面命令上加上 --force-renew 参数。

  • 相关阅读:
    Microsoft To-Do无法同步问题 ke xue上网导致
    学习希尔排序
    查找docker无法启动的原因
    挂载只读分区为可读写
    批量重建索引脚本
    frp nginx 80 端口共用
    vue部署nginx 404
    阿里云服务器,数据库热备、暖备、冷备实战-镜像篇(域环境下配置)
    码农老婆的网店
    Wcf调用方式
  • 原文地址:https://www.cnblogs.com/Don/p/11387896.html
Copyright © 2011-2022 走看看