Let’s Encrypt客户端 certbot-auto

问答中心分类: OneinStackLet’s Encrypt客户端 certbot-auto
xinren asked 7 年 ago
Hey,群主:
一直在关注oneinstack,由于沃通免费的SSL被火狐等处罚了,所以最近很关注Let’s Encrypt,我看了oneinstack的使用certbot-auto方法,我结合certbot官网最新说明,我提出了一些建议和修正方法:
安装Let’s Encrypt客户端:

一.安装客户端certbot:

yum install epel-release
cd /usr/local/bin/
wget https://dl.eff.org/certbot-auto
chmod a+x /usr/local/bin/certbot-auto
./certbot-auto --n

二.获取证书:

我看到oneinstack ./vhost.sh中有先建立.well-known/acme-chanllenge,然后用./certbot-auto certonly --standalone方式获取证书,
不明白为何这样做?因为用“standalone"plugin的方式就不需要.well-known/acme-chanllenge了。如果当前服务器已有网站的话,为了避免关闭服务器,certbot建议选择"webroot"plugin的方式较好:(测试发现:会自动创建:.well-known/acme-chanllenge,无需人为创建)。命令建议如下:

./certbot-auto certonly --webroot --agree-tos --email admin@example.com -w /var/www/example/ -d http://www.example.com -d example.com -w /var/www/other -d other.example.net -d another.other.example.net

如果一定要选择“standalone"plugin的方式:命令如下:

./certbot-auto certonly --standalone --agree-tos --email admin@example.com -d example.com -d http://www.example.com -d other.example.net

三.续期:

./certbot-auto renew :

官方解释:执行./certbot-auto renew的时候会默认采用获取证书时的方法,比如之前是用webroot方法的它还是会引用这种方法,如果之前是用standalone的方法的话,它仍然会引用这种方法,
所以该命令应该只加其他的一些选项即可,如:./certbot-auto renew --force-renewal或者./certbot-auto renew --renew-by-default等,但不建议这个命令加上该选项,因为./certbot-auto renew会自检所有的证书期限,如果满足30天以内的话,它才会执行更新动作,否则本次更新仍然跳过了,只会从所有证书中更新30天以内的证书,这种判断方法就非常好了,让它自然吧。如果强制性(--force-renewal,--renew-by-default)的话,有可能同一时间会更新多个证书(VPS上有很多网站,很多单独证书),造成次数超标)。
另外:我看到./vhost.sh中:echo "0 10 * * 1 /usr/local/bin/certbot-auto certonly -a webroot --agree-tos --renew-by-default --webroot-path=${wwwroot_dir}/${domain} -d ${domain} ${moredomainame_D};${Cron_Command}" >> $Cron_file,这种应该是强制性续期某具体证书吧,如果我服务器有多个证书呢?如何续期?还有就是:之前获取证书的时候oneinstack采取的是standalone的方式,在这里又采取了webroot的方法续期,与上述默认续期规律不符,假如没有手动创建.well-known/acme-chanllenge的话,可能webroot方式会失败!官方建议对具体证书续期的话:建议:
./certbot-auto certonly --keep-until-expiring --webroot -w /var/www/example.com -d example.com,www.example.com -w /var/www/thing -d thing.is,m.thing.is
或者:./certbot-auto certonly --renew-by-default --webroot -w /var/www/example.com -d example.com,www.example.com -w /var/www/thing -d thing.is,m.thing.is
(具体单个证书续期是可以执行强制性了,因为只有一个证书更新而已,不会对Let’s Encrypt次数限制造成影响,但这个命令不适合写入cronb中去,因为假如有多个证书的话,只更新一个具体证书也没有意义,如果有好事者,建议他们手动操作该命令罢了,)。
综上所需:证书续期的话,如果要自动续期,只在cronb里面添加./certbot-auto renew才有意义,这个命令会自动自检所有证书的时间,然后再决定是否有必要更新它?官方称是离过期30天内才可能真正去更新它!

neinstack越来越好!

 

10 Answers
oneinstack answered 7 年 ago
./certbot-auto certonly –webroot –agree-tos –email admin@example.com -w /var/www/example/ -d http://www.example.com -d example.com -w /var/www/other -d other.example.net -d another.other.example.net 测试过你这种方式 不行的。
.well-known/acme-chanllenge这个已经去掉。
续期改成certbot-auto renew
 

xinren answered 7 年 ago
群主:

我用的是: oneinstack包,试过"webroot"和"standalone"两种方式获取证书:均是通过的,
一."webroot"方式获取证书:通过验证/.well-known/acme-challenge来获取证书,当前直接用oneinstack安装包是可以的,没有发现无法访问/.well-known/acme-challenge的现象。
但有些人说:
默认虚拟主机里是禁止 . 开头的隐藏文件及目录的,所以访问http://abc.com/.well-known/acme-challenge/**** 这个链接的话返回403错误,所以必须要将对应虚拟主机配置文件里的:

location ~ /\.
{
deny all;
}
这段配置删掉或注释掉或在这段配置前面加上
location ~ /.well-known {
allow all;
}

我测试是没有遇到这种情况,我想这个方式的前提一定是要已经建立了虚拟主机了,且它已作域名解析通过了才可以,因为certbot是要访问/.well-known/acme-challenge。不解析应该是无法访问网站的。
webroot支持三种:
1.单域名生成证书:
./certbot-auto certonly --webroot --agree-tos --email admin@example.com -w /var/www/example/ -d http://www.example.com
2.多域名单目录生成单证书:(即一个网站多个域名使用同一个证书)
./certbot-auto certonly --webroot --agree-tos --email admin@example.com -w /var/www/example/ -d http://www.example.com -d example.com -d other.example.net -d another.other.example.net
3.多域名多目录生成多个证书:(即一次生成多个域名的多个证书)
./certbot-auto certonly --webroot --agree-tos --email admin@example.com -w /var/www/example/ -d http://www.example.com -d example.com -w /var/www/other -d other.example.net -d another.other.example.net
对于oneinstack,应该只有1和2两种情况适合,因为oneinstack一个网站对应一个网站目录,且添加虚拟主机的时候支持添加更多域名功能:注:该功能我还没有测试第二种情况,暂时不清楚添加更多域名的时候这些域名是否能正常获得证书和续期?
官方是建议用webroot的方式获取证书的。估计是考虑到临时停止webserver会造成其他网站短暂无法访问。
二."standalone"方式获取证书:
官方说明:To obtain a cert using a “standalone” webserver, you can use the standalone plugin by including certonly and --standalone on the command line.
This plugin needs to bind to port 80 or 443 in order to perform domain validation, so you may need to stop your existing webserver. To control
which port the plugin uses, include one of the options shown below on the command line.
所以该方式会临时停止webserver.我也用oneinstack里面测试过了standalone获取证书,也是成功的,至于"so you may need to stop your existing webserver",我是没有主动人为的stop的,估计采用standalone的方式获取证书的时候它会自己停止和重启webserver吧。无需人为干涉。
"standalone"方式获取证书命令:
./certbot-auto certonly --standalone --agree-tos --email admin@example.com -d example.com -d http://www.example.com -d other.example.net
=> 支持多域名获取证书。
三.续费
官方说明:
certbot-auto renew
This will attempt to renew any previously-obtained certificates that expire in less than 30 days. The same plugin and options that were used at the time the certificate was originally issued will be used for the renewal attempt, unless you specify other plugins or options.
所以,之前获取证书的方式会默认被certbot-auto renew使用。我看到最新的oneinstack中的./vhost.sh:
certbot-auto certonly --standalone --agree-tos --email ${Admin_Email} -w ${vhostdir} -d ${domain} ${moredomainame_D} --pre-hook "service ${S} stop" --post-hook "service ${S} start"
if [ -s "/etc/letsencrypt/live/${domain}/cert.pem" ]; then
[ -e "${PATH_SSL}/${domain}.crt" ] && rm -rf ${PATH_SSL}/${domain}.{crt,key}
ln -s /etc/letsencrypt/live/${domain}/fullchain.pem ${PATH_SSL}/${domain}.crt
ln -s /etc/letsencrypt/live/${domain}/privkey.pem ${PATH_SSL}/${domain}.key
if [ -e "${web_install_dir}/sbin/nginx" -a -e "${apache_install_dir}/conf/httpd.conf" ]; then
Cron_Command="/etc/init.d/nginx reload;/etc/init.d/httpd graceful"
elif [ -e "${web_install_dir}/sbin/nginx" -a ! -e "${apache_install_dir}/conf/httpd.conf" ]; then
Cron_Command="/etc/init.d/nginx reload"
elif [ ! -e "${web_install_dir}/sbin/nginx" -a -e "${apache_install_dir}/conf/httpd.conf" ]; then
Cron_Command="/etc/init.d/httpd graceful"
fi
[ "${OS}" == "CentOS" ] && Cron_file=/var/spool/cron/root || Cron_file=/var/spool/cron/crontabs/root
[ -z "$(grep 'certbot-auto renew' ${Cron_file})" ] && echo "0 0 1 * * /usr/local/bin/certbot-auto renew;${Cron_Command}" >> $Cron_file
既然上面获取证书是使用certbot-auto ceronly --standalone,那么certbot-auto renew也应该尝试采用该方法,既然上面的certbot-auto ceronly --standalone有执行--pre-hook "service ${S} stop" --post-hook "service ${S} start",那么现在执行:./certbot-auto renew是否也应该加上:certbot-auto renew --pre-hook "service ${S} stop" --post-hook "service ${S} start"
注:我用standalone测试过,没有--pre-hook "service ${S} stop" --post-hook "service ${S} start"也能成功获取证书,certbot-auto renew的时候我也没有加上certbot-auto renew,也能续期(注:我是执行强制性续期的),所以我怀疑standalone使用的时候应该是会自动--pre-hook "service ${S} stop" --post-hook "service ${S} start",无需人为操作。至于certbot-auto renew是不是无需加上--pre-hook "service ${S} stop" --post-hook "service ${S} start",我没有测试。我自己估计certbot-auto ceronly --standalone和certbot-auto renew要么都是加上--pre-hook "service ${S} stop" --post-hook "service ${S} start",要么都是不加--pre-hook "service ${S} stop" --post-hook "service ${S} start",请群主再了解一下!
如上是我经过测试和参考官网的最新指导得出的结论,希望对群主有所帮助,oneinstack中的Let’s Encrypt还是需要再改善改善!谢谢群主,谢谢oneinstack一键安装包!!

xinren answered 7 年 ago
另外:oneinstack的./vhost.sh中:
certbot-auto certonly --standalone --agree-tos --email ${Admin_Email} -w ${vhostdir} -d ${domain} ${moredomainame_D} --pre-hook "service ${S} stop" --post-hook "service ${S} start"
=》
1.standalone获取证书的方法无需使用"-w","-w"在webroot获取证书的方法时才有意义,因为webroot方法要使用 webroot path 中/.well-known/acme-challenge,
2.请测试建立虚拟主机中./vhost.sh的添加更多域名时是否能与命令中的${moredomainame_D}能正常使用?
 
 
具体很多操作参考官网:
https://certbot.eff.org/docs/
 

oneinstack answered 7 年 ago
已经改成webroot。。。感谢反馈

xinren answered 7 年 ago
群主,
  您好!不客气,都是为了让oneinstack更好!而且您也付出了不少心血了,辛苦了!!
我看了本次改动了不少地方,但是还有些地方需要修正:主要是强烈推荐使用./certbot-auto 脚本!
一.addons.sh:
强烈建议还是用回之前的:
yum install epel-release
cd /usr/local/bin/
wget https://dl.eff.org/certbot-auto
chmod a+x /usr/local/bin/certbot-auto
./certbot-auto --n
理由是:
官网说:certbot-auto accepts the same flags as certbot; it is a wrapper that installs all of its own dependencies and updates the client code automatically.
So you can just run: $ ./certbot-auto
1.1.用./certbot-auto的人应该是绝大部分,certbot-auto 与certbot命令拥有相同的命令行参数,certbot是yum或apt-get安装的,certbot-auto是自己下载的,自己下载的都是最新版本,apt-get或yum的版本会低一些,certbot 和 certbot-auto后面能带的参数都是一样,虽然Let’s Encrypt将会流行并取代免费的SSL,但由于其时间不久,故客户端certbot-auto会更新较快
以便于修复和提升功能等,而且./certbot-auto能较多和更好的支持操作系统,因为它是智能的(-auto),这点比./certbot强!
1.2.至于安装./certbot-auto --n很卡的问题:应该是中国主机存在这个问题,国外主机应该是很快的,我看本次您加上独立安装pip,也可以,但是:强烈建议保留优先从其官网下载安装,下载
失败后再选择从/src下载好的pip源码安装,因为这样才能兼顾国内和国外客户使用oneinstack.国外主机下载和安装它都是正常的,其实国内客户多尝试几次也是可以成功的安装的。
二./vhost.sh

同样:
certbot certonly --webroot --agree-tos --quiet --email ${Admin_Email} -w ${vhostdir} -d ${domain} ${moredomainame_D}
=>./certbot-auto certonly --webroot --agree-tos --email ${Admin_Email} -w ${vhostdir} -d ${domain} ${moredomainame_D}
(强烈推荐:./certbot-auto,去掉--quiet,--quiet参数是用在./certbot-auto renew 的.)
echo "0 0 1 * * certbot renew;${Cron_Command}" >> $Cron_file
=>echo "0 0 1 * * /usr/local/bin/certbot-auto renew;${Cron_Command}" >> $Cron_file
(定位路径:/usr/local/bin/会保险点)
三../certbot-auto renew
上面讲了:强烈建议用./certbot-auto renew。执行./certbot-auto renew的时候,除了尝试更新证书之外,它还会自动更新./certbot-auto脚本,但./certbot就做不到了,所以这也是强烈推荐./certbot-auto renew的原因,以后,为了提升certbot的安装,支持系统,修复bugs,功能添加等./certbot-auto脚本更新会经常发生,所以用./certbot-atuo是最好的选择。用它也提升了oneinstack一键安装包的自动化程度了。oneinstack的初衷也应该是方便用户,简单化,自动化。
 官方提到:
Usage: certbot-auto [OPTIONS]
A self-updating wrapper script for the Certbot ACME client. When run, updates
to both this script and certbot will be downloaded and installed. After
ensuring you have the latest versions installed, certbot will be invoked with
all arguments you have provided.
certbot-auto will always try to fetch the newest version of itself from its most recent release.
 
 
 
 

xinren answered 7 年 ago
群主:您好!
Let’s Encrypt客户端certbot按照您最新的安装方法根本无法安装成功,请您试试!
为了兼顾所有用户,建议您返回之前的安装方式:
yum install epel-release
cd /usr/local/bin/
wget https://dl.eff.org/certbot-auto
chmod a+x /usr/local/bin/certbot-auto
./certbot-auto –n
对于国内主机出现:
Creating virtual environment...
Installing Python packages...
一直等待状态,属于下载源出现了网络问题,国外主机是OK的:我使用国内主机试过几次,等待一下或者多试几次都是可以安装成功certbot-auto的,
建议您:默认先优先以如下执行:
yum install epel-release
cd /usr/local/bin/
wget https://dl.eff.org/certbot-auto
chmod a+x /usr/local/bin/certbot-auto
./certbot-auto –n
如果判断下载网络无法下载后,再转至oneinstack包里面的/src中安装已经存在pip源码,或者跳转其他镜像网站中。(所有的前提是官方下载源码并安装之为优先选择),当然这种方式是没有办法的办法,而且cetbot-auto安装的时候很多依赖包会被安装,我强烈建议让它自然运行为佳,人为判断依赖包会导致很多漏洞和错误,只要相关源码网站没有被墙,cetbot-auto应该都是可以安装成功的,另外运行./certbot-auto renew的时候./certbot-auto会自动更新自己,也许后续它也对pip的版本有更高的要求,也许oneinstack/src中pip源码并不能及时更新,无法跟随certbot-auto的更新呢。

故我强烈建议:
默认还是优先以如下执行:
yum install epel-release
cd /usr/local/bin/
wget https://dl.eff.org/certbot-auto
chmod a+x /usr/local/bin/certbot-auto
./certbot-auto –n
如果判断下载网络无法下载后,再转至oneinstack包里面的/src中安装已经存在pip源码,后者跳转其他镜像网站中索取pip源码。
=》如果这点难以做到的话,或者担心该措施并不十分可靠和安全的话,建议直接保留原始安装方式即可:即如下:(因为并不是完全不能安装成功,只是网络出现临时问题,最近国际网络都不好,也许跟美国选举有关系..........)
yum install epel-release
cd /usr/local/bin/
wget https://dl.eff.org/certbot-auto
chmod a+x /usr/local/bin/certbot-auto
./certbot-auto –n
如果安装失败,建立各大用户自行多运行几次即可!现在还没有到一定无法安装成功的情况,我是试了多次了,也成功了多次!有时候还是一次性成功呢~~。故该问题可以不做解决,直接还是引用官方推荐之方法:
yum install epel-release
cd /usr/local/bin/
wget https://dl.eff.org/certbot-auto
chmod a+x /usr/local/bin/certbot-auto
./certbot-auto –n
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

oneinstack answered 7 年 ago
--quiet 可以静默获取证书,vhost.sh体验好一些,这个参数可以用的
这个报错是因为依赖包没有安装
已经参考certbot-auto里面 安装依赖包

  if [ "${OS}" == "CentOS" ]; then
    pkgList="gcc dialog augeas-libs openssl openssl-devel libffi-devel redhat-rpm-config ca-certificates python python-devel python-virtualenv python-tools python-pip"
    for Package in ${pkgList}; do
      yum -y install ${Package}
    done
  elif [[ "${OS}" =~ ^Ubuntu$|^Debian$ ]]; then
    pkgList="python python-dev virtualenv python-virtualenv gcc dialog libaugeas0 augeas-lenses libssl-dev libffi-dev ca-certificates"
    for Package in ${pkgList}; do
      apt-get -y install $Package
    done
  fi

xinren answered 7 年 ago
 
群主,
  您好!本人最近比较闲,一直在关注您的oneinstack,也在关注Let’s Encrypt,两者真的很好!我还是来啰嗦两句了啊~~
1.–quiet 可以静默获取证书,vhost.sh体验好一些,这个参数可以用的!
=》这个参数是用在续期./certbot-auto renew上的,在获取证书的时候不会用它!如果想加的话,请加在cron中去:
./certbot-auto renew --quiet
 
--quiet 参数说明:
-q, --quiet              Silence all output except errors. Useful for
                            automation via cron. Implies --non-interactive.
                            (default: False)
2../certbot-auto相对于./cerbot 来说,有更多的智能性和操作系统支持性,也是官方推荐的:
   certbot-auto accepts the same flags as certbot; it is a wrapper that installs all of its own dependencies and updates the client code automatically.
 
不管是在安装和续期上,它都很智能化和傻瓜化,更重要的是:它还能与官方释放的版本自行同步。当前的pip源是国内主机发生的网络抽风问题,估计与最近美国大选有关系,且多试几次还是能成功的,运气好的话一次性能成功,该问题可以不解决的。或许后面网络又重新畅通起来了! 现在还没有到彻底无法安装的境地!本人一直在测试,还是能成功安装的!!检查了您最新的安装方式:安装certbot和卸载的时候已经在提示pip版本问题了。由于Let’s Encrypt是个年轻的公司,还在不断的改善客户端certbot-auto,不断的释放新版本,对依赖包等要求也可能会改变,如此,我们何不让certbot-auto自行解决呢?何况它自己能傻瓜和智能,能识别系统,能知道自己需要什么....省事省心............
所以,我仍然强烈建议群主返回到您之前的安装方式,这种方式是最佳的,最稳定,最智能的,使用最多的方式,特别对于很多国内主机的操作系统多样化,修改化,只有certbot-auto才能搞定这些“乱七八糟”的事,因为它足够智能,我也做了多种操作系统的测试,测试通过。certbot就无法胜任了,certbot需要人的“决定”太多。
 
oneinstack中:建议返回如下方式:
1.addons.sh:
yum install epel-release
cd /usr/local/bin/
wget https://dl.eff.org/certbot-auto
chmod a+x /usr/local/bin/certbot-auto
./certbot-auto --n

2.vhost.sh:

certbot certonly --webroot --agree-tos --quiet --email ${Admin_Email} -w ${vhostdir} -d ${domain} ${moredomainame_D}
=>./certbot-auto certonly --webroot --agree-tos --email ${Admin_Email} -w ${vhostdir} -d ${domain} ${moredomainame_D}

(去掉--quiet,./certbot更改为./certbot-auto)
echo "0 0 1 * * /usr/bin/certbot renew --renew-hook \"${Cron_Command}\"" >> $Cron_file
=>echo "0 0 1 * * /usr/bin/certbot-auto renew --quiet \"${Cron_Command}\"" >> $Cron_file
(去掉:--renew-hook,添加--quiet),
 
请群主能采纳该建议,把该Let’s Encrypt模块做完善和稳定,最终定下来吧!
 
  谢谢群主!
  2016-11-14  11 a.m
 
 
 

oneinstack answered 7 年 ago
--quiet测试过,没问题。静默获取证书,不加会弹出蓝色dialog框,否则难以忍受
certbot-auto会拉取官方python中源码包,速度极其慢,很多人已经放弃。稳定为王,改成现有方式。
而且certbot-auto和certbot没什么差别,certbot-auto里面是一个shell脚本,里面包含更多操作系统依赖包+安装python certbot,现有方式自己解决依赖包+pip安装certbot,后台调用安装原理一样,升级一样方便
ps:oneinstack只支持centos、ubuntu、debian

xinren answered 7 年 ago
Hey,群主,您好!
1. –quiet测试过,没问题。静默获取证书,不加会弹出蓝色dialog框,否则难以忍受
=》–quiet 确实是用在./certbot-auto renew --quiet或者./certbot renew --quiet 上,我截止到现在还没有发现任何人(包括官网)用在./certbot-auto certonly --webroot --agree-tos 或者./certbot-auto certonly --standalone --agree-to 上!
如果不想出现提示框之类的,还是有部分人用如下参数:带上--text将不出现框了。
-t, --text             Use the text output instead of the curses UI.
                         (default: False)
但我觉得框还是比较直观,能看清楚运作过程,挺好~~~~!
2. certbot-auto与certbot还是有区别的,除了操作系统支持(注:certbot命令不光与操作系统的分类有关系,还与同一操作系统的版本有关系,也与nginx,apache等所用软件有关系,详情请参考官网)多,依赖包自己搞定之外,它续期检查的时候也能自己更新至最新释放的版本。假如某用户安装了一年oneinstack包了,在这一年中certbot客户端必定更新,改善,提升等等动作,那么,该客户只能手工卸载之前安装的了,又重新手动安装一次。多麻烦,多复杂啊,让certbot-auto自己干这些复杂的事既不是更好?多智能啊,多省事,oneinstack也需要这样自动化吧!所以,没有必要为了一个pip源网络慢而去掉如此智能的东西,pip源网络慢还没有到那种彻底完蛋的地步呢?暂时的,暂时的,,,还能用,,,群主可以亲自试几次,我是亲自试了的。还有,现在新的方式指定一个镜像的pip源吧?我们不能保证其版本或者其他要求能与未来随时的释放的certbot-auto的要求能及时同步呢,这样新安装oneinstack用户也会出现问题,这些都是问题啊!
 
重要的事情我再啰嗦三遍~~~:请群主相信这样才是最好的。

返回之前您的安装方式
返回之前您的安装方式
返回之前您的安装方式
 
 
1.安装certbot-auto客户端:
yum install epel-release
cd /usr/local/bin/
wget https://dl.eff.org/certbot-auto
chmod a+x /usr/local/bin/certbot-auto
./certbot-auto –n
2.获取证书:
./certbot-auto certonly –webroot –agree-tos –email ${Admin_Email} -w ${vhostdir} -d ${domain} ${moredomainame_D}
或者:./certbot-auto certonly –webroot –agree-tos --text –email ${Admin_Email} -w ${vhostdir} -d ${domain} ${moredomainame_D}

3.续期:
echo “0 0 1 * * /usr/local/bin/certbot-auto renew;${Cron_Command}” >> $Cron_file
或者:echo “0 0 1 * * /usr/local/bin/certbot-auto renew –quiet;${Cron_Command}” >> $Cron_file