我想在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
运行它时,它会正确启动。
该应用程序使用“让我们加密”证书,我不知道这是否重要。
我认为,没有运行Tomcat的权限。 :-(
我不知道该怎么办。
谢谢您的帮助。
答案 0 :(得分:0)
随着堆栈跟踪的读取,您将无法访问该文件:
/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
语句始终是异常的根本原因。
如果您的服务器将以root以外的[user]
身份运行,这绝对是个好主意,请使该文件可用于特定的[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
来自动完成
或您用来获取“让我们加密”证书的工具。
编辑:certbot deploy hook
似乎是in an answer on superuser.com指出的一个很好的下一个搜索词