CentoS 8 安装
安装 Enable EPEL
官网地址:https://certbot.eff.org/
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
# ARCH=$( /bin/arch )
# subscription-manager repos --enable "codeready-builder-for-rhel-8-${ARCH}-rpms"
# dnf config-manager --set-enabled PowerTools
安装 Certbot
dnf install certbot python3-certbot-nginx
运行 Certbot,并且自动配置证书
certbot --nginx
运行后效果如下图所示:
只需要获取证书,然后自己安装
certbot certonly --nginx
自动续签
这个证书只有三个月有效期,所有要自动续签,自动续签也很简单,添加定时任务即可
echo "0 0,12 * * * root python3 -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew -q" | sudo tee -a /etc/crontab > /dev/null
CentoS 7 安装
安装 Enable EPEL
# 启用软件源
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum-config-manager repos --enable "rhel-*-optional-rpms" --enable "rhel-*-extras-rpms" --enable "rhel-ha-for-rhel-*-server-rpms"
# 安装 Certbot for Nginx
yum install certbot python2-certbot-nginx
运行 Certbot,并且自动配置证书,到这里就 GG 了,哈哈哈
certbot --nginx
因为年代久远的问题,Python 包很多不可用了,最好是卸载后重新安装最新的,不介绍
备用办法:采用脚本安装
-
获取安装脚本
wget https://dl.eff.org/certbot-auto
-
赋予可执行权限
sudo chmod a+x ./certbot-auto
-
运行脚本
./certbot-auto
运行后如下所示: 会自动将 http 重定向到 HTTPS ,如果不想,自己取消即可
Complete!
Creating virtual environment...
Installing Python packages...
Installation succeeded.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): sxy@shuxiaoyuan.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: dev-test.shuxiaoyuan.com
2: yapi.shuxiaoyuan.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1,2
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for dev-test.shuxiaoyuan.com
http-01 challenge for yapi.shuxiaoyuan.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/dev-test.shuxiaoyuan.com.conf
Deploying Certificate to VirtualHost /etc/nginx/conf.d/YApi.shuxiaoyuan.com.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/dev-test.shuxiaoyuan.com.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/YApi.shuxiaoyuan.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://dev-test.shuxiaoyuan.com
and https://yapi.shuxiaoyuan.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Subscribe to the EFF mailing list (email: sxy@shuxiaoyuan.com).
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/dev-test.shuxiaoyuan.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/dev-test.shuxiaoyuan.com/privkey.pem
Your cert will expire on 2020-10-19. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again with the "certonly" option. To non-interactively renew *all*
of your certificates, run "certbot-auto renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- 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