CentOS下使用ACME申请SSL证书

2024 年 3 月 19 日 225点热度 0人点赞 0条评论

1、ACME安装

# curl https://get.acme.sh | sh -s email=admin@fi32.com

收到警告提示:

[2024年 03月 18日 星期一 13:04:59 CST] It is recommended to install socat first.

建议先安装socat。

[2024年 03月 18日 星期一 13:04:59 CST] We use socat for standalone server if you use standalone mode.

如果您使用独立模式,我们使用 socat 作为独立服务器。

[2024年 03月 18日 星期一 13:04:59 CST] If you don't use standalone mode, just ignore this warning.

如果您不使用独立模式,请忽略此警告。

因为个人小白技术,虽然不使用独立模式,但不确定是否还有其他作用,干脆一并安装。

安装socat

# yum install socat -y

[2024年 03月 18日 星期一 13:08:22 CST] Install success!

再次安装ACME

curl https://get.acme.sh | sh -s email=admin@fi32.com

[2024年 03月 18日 星期一 13:25:46 CST] Good, bash is found, so change the shebang to use bash as preferred.

[2024年 03月 18日 星期一 13:25:48 CST] OK

[2024年 03月 18日 星期一 13:25:48 CST] Install success!

关闭并重新进入shell。

2、生成证书

2.1、http 方式

http 方式需要在你的网站根目录下放置一个文件, 来验证你的域名所有权,完成验证. 然后就可以生成证书了。只需要指定域名, 并指定域名所在的网站根目录. acme.sh 会全自动的生成验证文件, 并放到网站的根目录, 然后自动完成验证. 最后会聪明的删除验证文件. 整个过程没有任何副作用.

2.2、手动 dns 方式

手动 dns 方式, 手动在域名上添加一条 txt 解析记录, 验证域名所有权。这种方式的好处是, 你不需要任何服务器, 不需要任何公网 ip, 只需要 dns 的解析记录即可完成验证. 坏处是,如果不同时配置 Automatic DNS API,使用这种方式 acme.sh 将无法自动更新证书,每次都需要手动再次重新解析验证域名所有权。

2.3、dns api 方式(我采用的是这种方式)

dns 方式的真正强大之处在于可以使用域名解析商提供的 api 自动添加 txt 记录完成验证。acme.sh 目前支持 cloudflare, dnspod, cloudxns, godaddy 以及 ovh 等数十种解析商的自动集成.

我的域名托管在Cloudflare ,从此处获取api 并设置

[root@VM-0-12-centos ~]# export CF_Key="eec***ccd*****06d*****7c8a1b8c29****"
[root@VM-0-12-centos ~]# export CF_Email="admin@fi32.com"
[root@VM-0-12-centos acme.sh]# acme.sh --set-default-ca --server zerossl
[root@VM-0-12-centos acme.sh]# acme.sh --issue -d fi32.com -d *.fi32.com --dns dns_cf

此处错误提示

[2024年 03月 18日 星期一 14:55:44 CST] Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: 35

执行下面命令

yum -y update nss

查看证书并删除(因不确定上面的报错是否对证书有影响)

查看已安装证书

acme.sh --list

删除证书

acme.sh --remove -d fi32.com

重新安装证书

[root@VM-0-12-centos ~]# acme.sh --issue -d fi32.com -d *.fi32.com --dns dns_cf

3、至此安装完成

[2024年 03月 18日 星期一 15:07:35 CST] Cert success.
-----BEGIN CERTIFICATE-----
MIIEHDCCAwSgAwINAgISA/PJsMpJTtwi6d1f1+icVNoNMA0GCSqGSIb4DQAACwUA
......
eBn/I2YSyAduiPT2ANCmh+eGD/FVxa6TGRuGO11v9ItURZyJguNzFj6nqn/JCLPY
-----END CERTIFICATE-----
[2024年 03月 18日 星期一 15:07:35 CST] Your cert is in: /root/.acme.sh/fi32.com_ecc/fi32.com.cer
[2024年 03月 18日 星期一 15:07:35 CST] Your cert key is in: /root/.acme.sh/fi32.com_ecc/fi32.com.key
[2024年 03月 18日 星期一 15:07:35 CST] The intermediate CA cert is in: /root/.acme.sh/fi32.com_ecc/ca.cer
[2024年 03月 18日 星期一 15:07:35 CST] And the full chain certs is there: /root/.acme.sh/fi32.com_ecc/fullchain.cer

4、后续工作

安装证书到其他文件夹

acme.sh --install-cert -d fi32.com -d *.fi32.com --key-file /www/server/panel/vhost/ssl/my/fi32.com.key --cert-file /www/server/panel/vhost/ssl/my/fi32.com.cer --fullchain-file /www/server/panel/vhost/ssl/my/fullchain.cer --reloadcmd "nginx -s reload"

5、使用证书

查看fi32.com.key及fi32.com.cer并复制进宝塔面板该域名下任一网站的SSL内容填写区,会生成一个证书夹,选择该证书并应用到所有该域名下其他网站即可。

6、相关说明

fullchain.cer是证书链文件,fi32.com.key是证书私钥文件,fi32.com.cer是我们的证书,ca.cer是中级CA证书

自动升级acme.sh

acme.sh --upgrade --auto-upgrade

如有错误,恳请指正。

文章来源:https://www.fi32.com/diannao/146.html,转载请注明出处,谢谢!

贾小宝宝

这个人很懒,什么都没留下

文章评论