java.net.SocketException: 权限不够

一切问题的根源都是缺乏常识  0.0…..
背景:今天部署一个spring cloud服务,tanainaide 服务的端口为80,然后我建了个tomcat用户来启动,但是死活起不来,搞了好久还以为是环境问题都重新建了台新机子,还是不行,然后换root用户起来可以,很奇怪。报错如下:

12-12 19:44:58.792|INFO|c.netflix.discovery.DiscoveryClient:813|DiscoveryClient-InstanceInfoReplicator-0||DiscoveryClient_TPP-ZUUL-PRE/10.90.6.95:80 – registration status: 204
12-12 19:44:58.795|INFO|o.s.b.a.e.jmx.EndpointMBeanExporter:678|main||Located managed bean ‘configurationPropertiesReportEndpoint’: registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=configurationPropertiesReportEndpoint]
12-12 19:44:58.797|INFO|o.s.c.s.DefaultLifecycleProcessor:343|main||Starting beans in phase 2147483647
12-12 19:44:58.801|INFO|o.s.c.n.h.HystrixCircuitBreakerConfiguration$HystrixMetricsPollerConfiguration:138|main||Starting poller
12-12 19:44:58.816|INFO|o.s.s.a.ScheduledAnnotationBeanPostProcessor:262|main||No TaskScheduler/ScheduledExecutorService bean found for scheduled processing
12-12 19:44:58.825|INFO|o.a.coyote.http11.Http11NioProtocol:179|main||Initializing ProtocolHandler [“http-nio-80”]
12-12 19:44:58.836|INFO|o.a.coyote.http11.Http11NioProtocol:179|main||Starting ProtocolHandler [“http-nio-80”]
12-12 19:44:58.839|ERROR|o.a.coyote.http11.Http11NioProtocol:181|main||Failed to start end point associated with ProtocolHandler [“http-nio-80”]
java.net.SocketException: 权限不够
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:433)
    at sun.nio.ch.Net.bind(Net.java:425)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:210)
    at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:990)
    at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:635)
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:1022)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.addPreviouslyRemovedConnectors(TomcatEmbeddedServletContainer.java:250)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:193)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:297)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:145)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at com.pci.tpp.gateway.GatewayApplication.main(GatewayApplication.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
12-12 19:44:58.840|ERROR|o.a.catalina.core.StandardService:181|main||Failed to start connector [Connector[HTTP/1.1-80]]
org.apache.catalina.LifecycleException: Failed to start component [Connector[HTTP/1.1-80]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
    at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.addPreviouslyRemovedConnectors(TomcatEmbeddedServletContainer.java:250)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:193)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:297)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:145)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at com.pci.tpp.gateway.GatewayApplication.main(GatewayApplication.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: org.apache.catalina.LifecycleException: service.getName(): “Tomcat”;  Protocol handler start failed
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:1031)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    … 19 common frames omitted
Caused by: java.net.SocketException: 权限不够
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:433)
    at sun.nio.ch.Net.bind(Net.java:425)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:210)
    at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:990)
    at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:635)
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:1022)
    … 20 common frames omitted
12-12 19:44:58.847|INFO|o.a.coyote.http11.Http11NioProtocol:179|main||Pausing ProtocolHandler [“http-nio-80”]
12-12 19:44:58.848|INFO|o.a.catalina.core.StandardService:179|main||Stopping service [Tomcat]
12-12 19:44:58.852|WARN|o.a.c.loader.WebappClassLoaderBase:179|localhost-startStop-1||The web application [ROOT] appears to have started a thread named [spring.cloud.inetutils] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
 java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 java.lang.Thread.run(Thread.java:748)
12-12 19:44:58.855|INFO|o.apache.catalina.util.LifecycleBase:179|main||The stop() method was called on component [StandardServer[-1]] after stop() had already been called. The second call will be ignored.
12-12 19:44:58.855|INFO|o.a.coyote.http11.Http11NioProtocol:179|main||Stopping ProtocolHandler [“http-nio-80”]
12-12 19:44:58.855|INFO|o.a.coyote.http11.Http11NioProtocol:179|main||Destroying ProtocolHandler [“http-nio-80”]
12-12 19:44:58.857|INFO|o.s.b.a.l.AutoConfigurationReportLoggingInitializer:101|main||

Error starting ApplicationContext. To display the auto-configuration report re-run your application with ‘debug’ enabled.
12-12 19:44:58.860|ERROR|o.s.b.d.LoggingFailureAnalysisReporter:42|main||

原因其实是因为在linux下,如果使用1024以下的端口则需要root权限,所以因为我当前使用的不是root权限,所以权限不足而无法使用80端口,所以会报权限不够异常。把服务端口改为非80端口且大于1024的端口,比如8080即可。
在配置文件中修改端口号。

版权声明:本文为Dev0ps原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/Dev0ps/p/10124807.html