前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Linux服务器上Tomcat配置SSL证书并自动续期

Linux服务器上Tomcat配置SSL证书并自动续期

作者头像
JaneYork
发布于 2023-10-11 06:14:04
发布于 2023-10-11 06:14:04
66700
代码可运行
举报
运行总次数:0
代码可运行
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
本文最后编辑时间:2019-11-12

1.环境:centos7 BCC

Tomcat+MySQL+jdk

2.lets encrypt官网地址:https://letsencrypt.org

3.安装。

推荐使用编译方式安装新版本Githttps://blog.csdn.net/qq_31708763/article/details/103007119

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
查看是否安装git
git --version
卸载
yum remove git
安装git
yum install -y git

1.使用git获取,比较慢,请等待
git clone https://github.com/letsencrypt/letsencrypt
2.进入目录
cd letsencrypt
3.查看工具用法
./letsencrypt-auto --help
4.运行(会安装一大推依赖,如果国内主机请更换源),如果有端口占用443,请停止
./letsencrypt-auto certonly
然后,Installing Python packages…会卡顿

如果是干净的系统,以上都走的通;
之后,根据提示:输入验证方式,邮箱,是否订阅,域名,网站根目录等。
我输入的是tomcat的ROOT目录,成功之后出现如下信息:
[root@host letsencrypt]# ./certbot-auto certonly --webroot -w /usr/tomcat7.0.92/webapps/ROOT -d www.xxx.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for www.xxx.com
Using the webroot path /usr/tomcat7.0.92/webapps/ROOT for all unmatched domains.
Waiting for verification...
Cleaning up challenges

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

[root@host letsencrypt]# 

终于卡顿结束:

执行成功后:在/etc/letsencrypt/live/xx.com 目录下有5个文件

/etc/letsencrypt/live/janeyork.qicp.vip

cert.pem  服务器证书

chain.pem  根证书中继证书

fullchain.pem  ssl证书

privkey.pem  私钥key

我们需要的是3和4,将他们转化为tomcat支持的.jks

进入目录 cd /etc/letsencrypt/live/www.xxx.com

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#生成p12
openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out fullchain_and_key.p12 -name tomcat_letsencrypt -passin pass:123456 -passout pass:123456
#生成jks
keytool -importkeystore -deststorepass '123456' -destkeypass '123456' -destkeystore tomcat_letsencrypt.jks -srckeystore fullchain_and_key.p12 -srcstoretype PKCS12 -srcstorepass '123456' -alias tomcat_letsencrypt

更改tomcat配置文件:server.xml
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"
keystoreFile="/etc/letsencrypt/live/www.xxx.com/tomcat_letsencrypt.jks"
keystorePass="123456" />

#重启tomcat

<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" URIEncoding="UTF-8" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="/pogaizai/MyDSKeyStore.jks" keystorePass="yourJKSpass" keyAlias="tomcat" keyPass="yourKeyPass"/>

在浏览器中输入网址测试:https://yourDomain:8443/

https://pgz.beginmind.club/

成功显示:一把小锁子,点击可以看到证书信息等。

访问:http://yourDomain 还是未加密状态

tomcat强制https:

更改web.xml,在welcome-file-list标签后面添加

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<login-config>
    <!-- Authorization setting for SSL -->
    <auth-method>CLIENT-CERT</auth-method>
    <realm-name>Client Cert Users-only Area</realm-name>
</login-config>
<security-constraint>
    <!-- Authorization setting for SSL -->
    <web-resource-collection >
        <web-resource-name >SSL</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

强制之后,再次http访问会提示:

而且强制redirect port 8443

 更改server.xml 8443——>443

443类似80,可以不输入。

再次访问,都将强制跳转https://yourDomain.com

openssl详细命令:https://blog.csdn.net/liao20081228/article/details/77159039  PKCS12

插曲 start

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
how to check your pip version:
# pip -V

my pip version is 8.1.1, but the latest version is 9.0.1, so I ran following command to upgrade it:
# pip install --upgrade pip

Now check the pip version again:

# pip -V
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)

https://blog.csdn.net/anukram/article/details/78176614

https://blog.csdn.net/lyq8479/article/details/79022888

https://www.cnblogs.com/lzpong/p/6433189.html

https://www.iaodun.com/faq/technical/3008.html

如果是国内主机请更换国内源:(重要)

更换yum源;

http://blog.51cto.com/xiaogongju/2086328

解决pip更新慢;(会卡顿install Python package...)

https://blog.csdn.net/qq_31708763/article/details/102999031

报错:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[root@JaneYork letsencrypt]# ./letsencrypt-auto certonly
Bootstrapping dependencies for RedHat-based OSes... (you can skip this with --no-bootstrap)
yum is /usr/bin/yum
yum is hashed (/usr/bin/yum)
Loaded plugins: langpacks, versionlock
Package gcc-4.8.5-36.el7.x86_64 already installed and latest version
Package augeas-libs-1.4.0-6.el7.x86_64 already installed and latest version
Package 1:openssl-1.0.2k-16.el7.x86_64 already installed and latest version
Package 1:openssl-devel-1.0.2k-16.el7.x86_64 already installed and latest version
Package libffi-devel-3.0.13-18.el7.x86_64 already installed and latest version
Package redhat-rpm-config-9.1.0-87.el7.centos.noarch already installed and latest version
Package ca-certificates-2018.2.22-70.0.el7_5.noarch already installed and latest version
Package python-devel-2.7.5-76.el7.x86_64 already installed and latest version
Package python-virtualenv-15.1.0-2.el7.noarch already installed and latest version
Package python-tools-2.7.5-76.el7.x86_64 already installed and latest version
Package python2-pip-8.1.2-6.el7.noarch already installed and latest version
Nothing to do
Creating virtual environment...
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 2327, in <module>
    main()
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 712, in main
    symlink=options.symlink)
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 944, in create_environment
    download=download,
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 900, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/usr/lib/python2.7/site-packages/virtualenv.py", line 796, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /opt/eff.org/certbot/venv/bin/python2.7 - setuptools pip wheel failed with error code 1
[root@JaneYork letsencrypt]# ^C

插曲 end

4.续期证书:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#/bin/sh
#续期   说明:只用renew的话,会先检查证书是否需要更新,大概是距离到期还有三天或者十几天之内才会执行更新,否则会提示不需要更新。(昨天更新了证书,今天直接用renew,提示不允许更新)
#这里方便测试,增加参数--force-renew,能够强制立即更新,官网好像有命令可以用于test
#./certbot-auto renew --force-renew
cd /www/letsencrypt/
./certbot-auto renew
#生成p12
cd /etc/letsencrypt/live/yourDomain && openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out fullchain_and_key.p12 -name tomcat_letsencrypt -passin pass:123456 -passout pass:123456
#移动新生成的证书文件
cp /etc/letsencrypt/live/yourDomain/fullchain.pem /mnt/web/letsTemp
cp /etc/letsencrypt/live/yourDomain/privkey.pem /mnt/web/letsTemp
#生成jks文件
#备份并删除原jks文件
mv /etc/letsencrypt/live/yourDomain/tomcat_letsencrypt.jks /etc/letsencrypt/live/www.xxx.com/tomcat_letsencrypt`date '+%Y-%m-%d'`.jks
cd /etc/letsencrypt/live/yourDoamin && keytool -importkeystore -deststorepass '123456' -destkeypass '123456' -destkeystore tomcat_letsencrypt.jks -srckeystore fullchain_and_key.p12 -srcstoretype PKCS12 -srcstorepass '123456' -alias tomcat_letsencrypt
#重启服务器
/usr/tomcat7.0.92/bin/restartup.sh

使用定时任务crontab,执行上述脚本 crontab -e 在打开的编辑器中添加如下内容(每个月1号凌晨3点更新) 0    0  3 *  *  sh /ts/ssl_auto.sh >/dev/null 2>&1 &

00 12 * * * sh /home/text.sh >> //home/logs/log_$(date +\%Y-\%m-\%d).log 2>&1

2>&1 表示把标准错误输出重定向到与标准输出一致,即xxx.log

详细crontab:https://blog.csdn.net/qq_31708763/article/details/86516523

友情推荐:

Linux上安装Java web开发环境:https://blog.csdn.net/qq_31708763/article/details/86366445

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-10-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Let's Encrypt 安装配置教程,免费的 SSL 证书
要求配置 DNS TXT 记录,从而校验域名所有权,也就是判断证书申请者是否有域名的所有权。
用户6884826
2021/07/09
4.2K0
SSL证书自动化如此简单-certbot实践
方式一:用指定根目录的方式,会在根目录下创建一个.well-known来验证域名的所有权
用户10002156
2024/01/05
8300
SSL证书自动化如此简单-certbot实践
如何在 CentOS 8 上使用 Let's Encrypt 保护 Nginx
Let’s Encrypt 是一个免费的,自动的,开源证书供应商,它由 Internet Security Research Group (ISRG)开发。
雪梦科技
2020/05/11
2.2K0
如何在 CentOS 8 上使用 Let's Encrypt 保护 Nginx
Docker获取Let`s Encrypt SSL 证书
为了方便维护、升级,同时也避免破坏本地的开发环境,我这里使用docker方式来运行certbot。整个过程分为两步:首次申请证书和证书更新。
孟斯特
2023/11/15
8210
设置私人 Burp 协作服务器
现在collaborator.config在/collaborator目录下创建一个文件并使用以下内容对其进行编辑。
Khan安全团队
2021/12/31
1.4K0
获取Let's Encrypt免费TLS/SSL证书的那点事儿
Let's Encrypt是一个于2015年三季度推出的数字证书认证机构,旨在以自动化流程消除手动创建和安装证书的复杂流程,并推广使万维网服务器的加密连接无所不在,为安全网站提供免费的SSL/TLS证书。 -- 引自维基百科
用户1456517
2019/03/05
1.6K0
使用Let's Encrypt的SSL证书配置HTTPS手记
前段时间,看见很多大会都在分享全站HTTPS的经验。HTTPS固然好,前提是SSL证书,并且签发证书的机构要靠谱。沃通的CA证书就相继被Mozilla和Google封杀了。曾经对于普通用户,权威,安全,并且免费的证书无疑就像天上的星星,可望而不可及。现在,这些星星变成了馅饼掉了下来。没错,我们可以申请安全免费的ssl证书--- Let's Encrypt。 Let’s Encrypt是电子前哨基金会(EFF)发布的免费 SSL 证书服务,Google,Mozilla和Microsoft都极力支持。很早之前就
李海彬
2018/03/19
2.5K0
使用Let's Encrypt的SSL证书配置HTTPS手记
免费https证书安装(Nginx)
对于站点来说,使用https访问能增强数据传输的安全性,避免一些安全事故,同时拥有了https认证,在主流浏览器中都被被标记为可信任的安全的网站,也能加强搜索引擎的对https站点的收录。
肓己
2021/08/12
1.6K0
linux centos debain nginx自动ssl证书配置 软件 snapd
# sudo apt-get remove certbot、sudo dnf remove certbot或sudo yum remove certbot。
eisc
2022/03/06
1.2K0
在 CentOS 8 上使用 Let’s Encrypt 保护 Apache
Let’s Encrypt 是一个免费的,自动的,开放证书供应商。它由提供免费 SSL 证书的 Internet Security Research Group(ISRG)开发。
雪梦科技
2020/05/11
1.4K0
在 CentOS 8 上使用 Let’s Encrypt 保护 Apache
SSL证书申请与使用
描述:服务器CentOS7.x,Nignx,Let’s Encrypt做免费的HTTPS证书。 Let’s Encrypt官网: https://letsencrypt.org/ 操作流程:
全栈工程师修炼指南
2022/09/29
1.2K0
https证书
获取certbot wget https://dl.eff.org/certbot-auto chmod a+x certbot-auto 安装nginx yum -y install nginx 生成证书 ./certbot-auto certonly --standalone --email syf@alexorz.com --agree-tos -d alexorz.com 查看生成的证书 ll /etc/letsencrypt/live/alexorz.com/privkey.pem lrwxrwx
零月
2018/04/25
2.7K0
https证书
Let’s Encrypt免费ssl证书申请
Let’s Encrypt是一个免费并且开源的CA,且已经获得Mozilla、微软等主要浏览器厂商的根授信。它极大低降低DV证书的入门门槛,进而推进全网的HTTPS化。
爱游博客
2019/08/07
4.2K0
如何在Ubuntu 16.04上使用Let加密SSL证书配置GoCD
GoCD是一个功能强大的持续集成和交付平台,旨在自动化测试和发布流程。GoCD具有许多高级功能,例如比较构建,可视化复杂工作流以及自动构建版本跟踪,是一种灵活的工具,可以帮助团队将经过良好测试的软件提供给生产环境。
编程男孩
2018/09/21
1.3K0
使用Let's Encrypt -- 免费的https证书
老高的证书快过期了(2016-12-11),本着节约资(R)源(MB)的精神,准备使用Let's Encrypt。
老高的技术博客
2022/12/27
1.2K0
使用Let's Encrypt  -- 免费的https证书
快速配置Let's encrypt通配符证书
利用certbot工具配置Let’s encrypt通配符证书,所域名下所有的子域名都能方便的使用 https证书,而且完全免费。值得关注的是,Let’s encrypt通配符证书只是针对二级域名,并不能针对主域名,如*.hubinqiang.com和hubinqiang.com 被认为是两个域名,如果和我一样使用的是主域名,在申请的时候需要注意都要申请。
OwenZhang
2021/12/08
2.2K0
快速配置Let's encrypt通配符证书
nginx HTTPS反向代理
configure arguments里的with-http_ssl_module是必须的,在./configure时必须添上该选项启用ssl模块,否则比较麻烦(没有类似于phpize这种东西,只能添上参数重新编译按需覆盖)
ayqy贾杰
2019/06/12
3.4K0
certbot免费证书-1:centos7部署并申请免费证书certbot
我们需要在zenlayer,aws-lb上配置certbot证书,因为是免费的,便宜。
千里行走
2022/08/31
1.9K0
certbot免费证书-1:centos7部署并申请免费证书certbot
CentOS7-Nginx配置Let's-Encrypt-SSL证书
为http站点添加https支持,需要从证书发行机构获取SSL/TLS 证书。常见的免费证书有两种:
职场亮哥
2020/10/10
2.2K0
使用 Certbot 安装 Letsencrypt 证书
1、拥有一个域名,例如 mydomain.com 2、在域名服务器创建一条A记录,指向云主机的公网IP地址。例如 demo.mydomain.com 指向 192.168.0.1 的IP地址 3、要等到新创建的域名解析能在公网上被解析到
SkyRiN
2018/11/20
4.7K0
推荐阅读
相关推荐
Let's Encrypt 安装配置教程,免费的 SSL 证书
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验