gpt4 book ai didi

tomcat - 在 VPS 上使用 Let's Encrypt 证书运行 spring boot 时出现问题

转载 作者:行者123 更新时间:2023-11-28 22:15:55 25 4
gpt4 key购买 nike

我想在 Spring Boot 服务中添加一个应用程序,但我希望它只以 root 身份运行。当我尝试以不同的用户身份运行它时,出现错误:

Failed to start component [Connector[HTTP/1.1-8081]]

org.apache.catalina.LifecycleException: Protocol handler start failed

https://pastecode.xyz/view/2410ddfc

当我使用 sudo 运行它时,它会正确启动。

该应用程序使用 Let's Encrypt 证书,我不知道它是否重要。

在我看来,没有运行Tomcat的权限。 :-(

我不知道该怎么办了。

感谢您的帮助。

最佳答案

在读取堆栈跟踪时,您无权访问该文件:

/etc/letsencrypt/live/dawid.cloud/keystore.p12 (权限被拒绝)

org.apache.catalina.LifecycleException: Protocol handler start failed
at org.apache.catalina.connector.Connector.startInternal(Connector.java:960) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225) [tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:259) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:197) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:300) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) [spring-context-5.1.2.RELEASE.jar!/:5.1.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at dawid.cloud.spotkanieklasowe.SpotkanieklasoweApplication.main(SpotkanieklasoweApplication.java:10) [classes!/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [spotkanieklasowe-0.0.1.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [spotkanieklasowe-0.0.1.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [spotkanieklasowe-0.0.1.jar:na]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [spotkanieklasowe-0.0.1.jar:na]
Caused by: java.lang.IllegalArgumentException: /etc/letsencrypt/live/dawid.cloud/keystore.p12 (Permission denied)
at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:114) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.AbstractJsseEndpoint.initialiseSsl(AbstractJsseEndpoint.java:85) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:224) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1108) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:550) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.connector.Connector.startInternal(Connector.java:957) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
... 22 common frames omitted
Caused by: java.io.FileNotFoundException: /etc/letsencrypt/live/dawid.cloud/keystore.p12 (Permission denied)
at java.io.FileInputStream.open0(Native Method) ~[na:1.8.0_191]
at java.io.FileInputStream.open(FileInputStream.java:195) ~[na:1.8.0_191]
at java.io.FileInputStream.<init>(FileInputStream.java:138) ~[na:1.8.0_191]
at java.io.FileInputStream.<init>(FileInputStream.java:93) ~[na:1.8.0_191]
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90) ~[na:1.8.0_191]
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188) ~[na:1.8.0_191]
at org.apache.tomcat.util.file.ConfigFileLoader.getInputStream(ConfigFileLoader.java:89) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.SSLUtilBase.getStore(SSLUtilBase.java:141) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.SSLHostConfigCertificate.getCertificateKeystore(SSLHostConfigCertificate.java:204) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.jsse.JSSEUtil.getKeyManagers(JSSEUtil.java:184) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:112) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
... 27 common frames omitted

最底层的 caused by 语句始终是异常的根本原因

如果您的服务器将以 [user] 而不是 root 身份运行,这确实是个好主意,请让该特定 [user] 可以访问此文件。

作为 root 的解决方法:

mkdir /home/[user]/key
cp -p /etc/letsencrypt/live/dawid.cloud/keystore.p12 /home/[user]/key/
chown -R [user].[user] /home/[user]/key

[user] 是您的用户名。

我敢打赌,有一个更直接的解决方案可以使用 certbot 自动执行此操作 或者您使用什么工具来获取 Let's Encrypt 证书。

编辑:certbot deploy hook 似乎是一个很好的下一个搜索词,正如指出的那样 in an answer on superuser.com

关于tomcat - 在 VPS 上使用 Let's Encrypt 证书运行 spring boot 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53321575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com