1、问题描述
将Tomcat端口号更改为80不能启动,报错如下
代码语言:javascript复制25-Feb-2020 16:17:46.737 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-80"]
25-Feb-2020 16:17:46.748 SEVERE [main] org.apache.catalina.core.StandardService.initInternal Failed to initialize connector [Connector[HTTP/1.1-80]]
org.apache.catalina.LifecycleException: Protocol handler initialization failed
at org.apache.catalina.connector.Connector.initInternal(Connector.java:995)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
at org.apache.catalina.core.StandardService.initInternal(StandardService.java:552)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:848)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
at org.apache.catalina.startup.Catalina.load(Catalina.java:639)
at org.apache.catalina.startup.Catalina.load(Catalina.java:662)
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.apache.catalina.startup.Bootstrap.load(Bootstrap.java:303)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:473)
Caused by: java.net.SocketException: Permission denied
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:221)
at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:1118)
at org.apache.tomcat.util.net.AbstractJsseEndpoint.init(AbstractJsseEndpoint.java:223)
at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:581)
at org.apache.coyote.http11.AbstractHttp11Protocol.init(AbstractHttp11Protocol.java:70)
at org.apache.catalina.connector.Connector.initInternal(Connector.java:993)
... 13 more
25-Feb-2020 16:17:46.750 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
将端口号改为默认的8080后,可以正常访问。
2、原因
1024以下的端口只能由root用户使用,普通权限的用户没有权限。恰好80端口号小于1024,而8080端口号大于1024。 再检查一下当前用户,恰好非root用户。
原因找到。
3、解决办法
推荐解决方案:使用sudo命令
代码语言:javascript复制[appadmin@app apache-tomcat-8.5.50]$ sudo bin/startup.sh
[sudo] password for appadmin:
Using CATALINA_BASE: /tpdata/app/apache-tomcat-8.5.50
Using CATALINA_HOME: /tpdata/app/apache-tomcat-8.5.50
Using CATALINA_TMPDIR: /tpdata/app/apache-tomcat-8.5.50/temp
Using JRE_HOME: /
Using CLASSPATH: /tpdata/app/apache-tomcat-8.5.50/bin/bootstrap.jar:/tpdata/app/apache-tomcat-8.5.50/bin/tomcat-juli.jar
Tomcat started.
[appadmin@app apache-tomcat-8.5.50]$ netstat -tlnp|grep 80
(No info could be read for "-p": geteuid()=1001 but you should be root.)
tcp6 0 0 :::8009 :::* LISTEN -
tcp6 0 0 :::80 :::* LISTEN -
tcp6 0 0 127.0.0.1:8005 :::* LISTEN -
[appadmin@app apache-tomcat-8.5.50]$
80端口已经正常启动了。