简体   繁体   English

如何在 Debian 上以非 root 用户身份运行 SpringBoot 应用程序?

[英]How to run SpringBoot app as non-root user on Debian?

Using Debian 10.使用 Debian 10.

I am trying to run SpringBoot app.jar application i made on a server as non-root user.我正在尝试以非 root 用户身份在服务器上运行 SpringBoot app.jar应用程序。

I created new user called SpringBootApp .我创建了名为SpringBootApp的新用户。

Application is supposed to run on 443 port.应用程序应该在 443 端口上运行。

I changed owned of this.jar file to SpringBootApp and changed permissions to 770 with these commands:我将 this.jar 文件的所有权更改为SpringBootApp ,并使用以下命令将权限更改为 770:

chown springbootapp app.jar

chmod 770 app.jar

However while trying to start application as this user, I get this exception: java.net.BindException: "permission denied" .但是,在尝试以该用户身份启动应用程序时,出现此异常: java.net.BindException: "permission denied" What other permissions do i need to change to run it as non-root user?我需要更改哪些其他权限才能以非 root 用户身份运行它?

The way i run application: java -jar app.jar我运行应用程序的方式: java -jar app.jar

Output: Output:

Application run failed

org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.12.jar!/:5.3.12]
        at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.12.jar!/:5.3.12]
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.3.12.jar!/:5.3.12]
        at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[spring-context-5.3.12.jar!/:5.3.12]
        at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.3.12.jar!/:5.3.12]
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935) ~[spring-context-5.3.12.jar!/:5.3.12]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.12.jar!/:5.3.12]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.6.jar!/:2.5.6]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.6.jar!/:2.5.6]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.6.jar!/:2.5.6]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.6.jar!/:2.5.6]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-2.5.6.jar!/:2.5.6]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[spring-boot-2.5.6.jar!/:2.5.6]
        at ispf.webapp.WebappApplication.main(WebappApplication.java:10) ~[classes!/:0.0.1-SNAPSHOT]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[app.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[app.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[app.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[app.jar:0.0.1-SNAPSHOT]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:229) ~[spring-boot-2.5.6.jar!/:2.5.6]
        at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43) ~[spring-boot-2.5.6.jar!/:2.5.6]
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.12.jar!/:5.3.12]
        ... 22 common frames omitted
Caused by: java.lang.IllegalArgumentException: standardService.connector.startFailed
        at org.apache.catalina.core.StandardService.addConnector(StandardService.java:238) ~[tomcat-embed-core-9.0.54.jar!/:na]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:282) ~[spring-boot-2.5.6.jar!/:2.5.6]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:213) ~[spring-boot-2.5.6.jar!/:2.5.6]
        ... 24 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
        at org.apache.catalina.connector.Connector.startInternal(Connector.java:1075) ~[tomcat-embed-core-9.0.54.jar!/:na]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.54.jar!/:na]
        at org.apache.catalina.core.StandardService.addConnector(StandardService.java:234) ~[tomcat-embed-core-9.0.54.jar!/:na]
        ... 26 common frames omitted
Caused by: java.net.BindException: Permission denied
        at java.base/sun.nio.ch.Net.bind0(Native Method) ~[na:na]
        at java.base/sun.nio.ch.Net.bind(Net.java:552) ~[na:na]
        at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:336) ~[na:na]
        at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:294) ~[na:na]
        at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:271) ~[tomcat-embed-core-9.0.54.jar!/:na]
        at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:226) ~[tomcat-embed-core-9.0.54.jar!/:na]
        at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1208) ~[tomcat-embed-core-9.0.54.jar!/:na]
        at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1294) ~[tomcat-embed-core-9.0.54.jar!/:na]
        at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:614) ~[tomcat-embed-core-9.0.54.jar!/:na]
        at org.apache.catalina.connector.Connector.startInternal(Connector.java:1072) ~[tomcat-embed-core-9.0.54.jar!/:na]
        ... 28 common frames omitted

With a root user, there is no problem.使用root用户,没有问题。

Which port is your application configured to run on?您的应用程序配置为在哪个端口上运行?

The BindException is suggesting it to be a privileged port . BindException 表明它是一个特权端口 If this is the case, you could try to set it to another port by command line argument (see https://www.baeldung.com/spring-boot-change-port#command-line )如果是这种情况,您可以尝试通过命令行参数将其设置为另一个端口(请参阅https://www.baeldung.com/spring-boot-change-port#command-line

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以非root用户身份运行Kafka? - How to run Kafka as non-root user? 如何在CentOs 6上以非root用户身份运行Java服务 - How to run java service as a non-root user on CentOs 6 Java 应用程序无法以 debian 中的非 root 用户身份连接到 mysql - Java application fails to connect to mysql as non-root user in debian 如何以root身份启动Java程序,但降级为非root用户 - How to start Java program as root but downgrade to non-root user 如何为非 root 用户配置 Dockerfile 但授予他们访问权限以写入根目录中的文件? - How to configure Dockerfile for non-root user but give them access privileges to write to a file in the root dir? 使用Java程序如何以非root用户身份以编程方式在端口80上启动Jetty - Using Java Program How to programmatically start Jetty on port 80 as non-root user 以非root用户身份使用Solaris SMF运行Java应用程序 - Running Java Application with Solaris SMF as Non-Root User 使用Spring以非root用户身份在端口80上启动bootRun进程 - Starting a bootRun process on port 80 as non-root user with Spring 可以使用Chef以非root用户身份安装Java吗? - Can Java be installed as non-root user with Chef? ANTLR4:如何解析非根节点? - ANTLR4: How to parse non-root node?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM