springboot jar包运行在腾讯云ubuntu 机器上的问题

/ 2021-07-17 / 28人浏览 / 0人评论

 jar包问题

运行环境

ubuntu 18.04.1 64 位
    
jdk 1.8.0_291 
    
mysql 8.0

安装包为springboot jar包

报错信息:

2021-07-17 13:21:56.447  WARN 18745 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
2021-07-17 13:21:56.460  INFO 18745 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2021-07-17 13:21:56.475  INFO 18745 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2021-07-17 13:21:56.490  INFO 18745 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-07-17 13:21:56.491  INFO 18745 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : org.tuckey.web.filters.urlrewrite.UrlRewriteFilter INFO: destroy called
2021-07-17 13:21:56.522  INFO 18745 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-07-17 13:21:56.571 ERROR 18745 --- [           main] o.s.boot.SpringApplication               : 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.8.jar!/:5.3.8]
        at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.8.jar!/:5.3.8]
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.3.8.jar!/:5.3.8]
        at java.lang.Iterable.forEach(Iterable.java:75) ~[na:1.8.0_291]
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[spring-context-5.3.8.jar!/:5.3.8]
        at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.3.8.jar!/:5.3.8]
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935) ~[spring-context-5.3.8.jar!/:5.3.8]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.8.jar!/:5.3.8]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.1.jar!/:2.5.1]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.5.1.jar!/:2.5.1]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) [spring-boot-2.5.1.jar!/:2.5.1]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) [spring-boot-2.5.1.jar!/:2.5.1]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) [spring-boot-2.5.1.jar!/:2.5.1]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) [spring-boot-2.5.1.jar!/:2.5.1]
        at com.java78.tools.OnlineToolsApplication.main(OnlineToolsApplication.java:19) [classes!/:1.0.0]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_291]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_291]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_291]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_291]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) [app.jar:1.0.0]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) [app.jar:1.0.0]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) [app.jar:1.0.0]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) [app.jar:1.0.0]
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.1.jar!/:2.5.1]
        at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43) ~[spring-boot-2.5.1.jar!/:2.5.1]
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.8.jar!/:5.3.8]
        ... 22 common frames omitted
Caused by: java.lang.IllegalArgumentException: standardService.connector.startFailed
        at org.apache.catalina.core.StandardService.addConnector(StandardService.java:243) ~[tomcat-embed-core-9.0.46.jar!/:na]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:282) ~[spring-boot-2.5.1.jar!/:2.5.1]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:213) ~[spring-boot-2.5.1.jar!/:2.5.1]
        ... 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.46.jar!/:na]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.46.jar!/:na]
        at org.apache.catalina.core.StandardService.addConnector(StandardService.java:239) ~[tomcat-embed-core-9.0.46.jar!/:na]
        ... 26 common frames omitted
Caused by: java.net.SocketException: Permission denied
        at sun.nio.ch.Net.bind0(Native Method) ~[na:1.8.0_291]
        at sun.nio.ch.Net.bind(Net.java:438) ~[na:1.8.0_291]
        at sun.nio.ch.Net.bind(Net.java:430) ~[na:1.8.0_291]
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:225) ~[na:1.8.0_291]
        at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:300) ~[tomcat-embed-core-9.0.46.jar!/:na]
        at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:253) ~[tomcat-embed-core-9.0.46.jar!/:na]
        at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1204) ~[tomcat-embed-core-9.0.46.jar!/:na]
        at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1290) ~[tomcat-embed-core-9.0.46.jar!/:na]
        at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:614) ~[tomcat-embed-core-9.0.46.jar!/:na]
        at org.apache.catalina.connector.Connector.startInternal(Connector.java:1072) ~[tomcat-embed-core-9.0.46.jar!/:na]
        ... 28 common frames omitted

原因:

Ubuntu系统中,非root用户只能使用1024以上的端口。而jar包是使用的是tomcat且定义端口为80;

解决办法:

  1. 使用root用户开启tomcat;

  2. 进行端口映射;

#80端口映射到8080
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

#443端口映射到8443
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443

全部评论