tomcat启动成功,但是http://localhost:8080/页面打不开

今天遇到一个问题:

$ ./startup.sh
$ Tomcat started.

启动tomcat显示,tomcat成功,但是页面http://localhost:8080/却打不开

查看日志:catalina.log,发现:

27-Dec-2018 21:22:51.181 严重 [main] org.apache.catalina.core.StandardServer.await 
Failed to create server shutdown socket on address [localhost] and port [8005] 
(base port [8005] and offset [0])
 java.net.BindException: Can't assign requested address (Bind failed)
	at java.net.PlainSocketImpl.socketBind(Native Method)
	at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
	at java.net.ServerSocket.bind(ServerSocket.java:375)
	at java.net.ServerSocket.<init>(ServerSocket.java:237)
	at org.apache.catalina.core.StandardServer.await(StandardServer.java:453)
	at org.apache.catalina.startup.Catalina.await(Catalina.java:783)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:729)
	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.start(Bootstrap.java:350)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)

原来tomcat报错,实际上tomcat并没有启动成功,

绑定地址localhost失败,然后在iterms终端ping一下localhost,果然失败(而ping 127.0.0.1 是成功的)

17 packets transmitted, 0 packets received, 100.0% packet loss

解决方案:sudo vim /etc/hosts 修改hosts文件,添加:
 

127.0.0.1 localhost

然后启动一下tomcat,成功

ps:关于localhost和127.0.0.1的知识点可参考:https://blog.csdn.net/w657395940/article/details/50241693

猜你喜欢

转载自blog.csdn.net/nanbiandehe/article/details/85311916