qindongliang1922 阅读(103) 评论(0)
在linux想要查看某个端口的占用情况,我们可以使用ps -ef | grep 端口号来查看某个进程的端口占用情况,那么在windows上,如何查看呢?

起因:散仙在win7上启动jetty时,发生端口占用,日志异常如下:
main{StandardDirectoryReader(segments_1:1:nrt)}
INFO  - 2014-11-18 11:11:29.780; org.apache.solr.core.CoreContainer; registering core: collection1
INFO  - 2014-11-18 11:11:29.786; org.apache.solr.servlet.SolrDispatchFilter; user.dir=D:\solr4.7-jetty
INFO  - 2014-11-18 11:11:29.788; org.apache.solr.servlet.SolrDispatchFilter; SolrDispatchFilter.init() done
INFO  - 2014-11-18 11:11:29.822; org.apache.solr.core.SolrCore; [collection1] webapp=null path=null params={event=firstSearcher&q=static+firstSearcher+warming+in+solrconfig.xml&distrib=false} hits=0 status=0 QTime=37 
WARN  - 2014-11-18 11:11:29.824; org.eclipse.jetty.util.component.AbstractLifeCycle; FAILED SocketConnector@0.0.0.0:8983: java.net.BindException: Address already in use: JVM_Bind
java.net.BindException: Address already in use: JVM_Bind
	at java.net.DualStackPlainSocketImpl.bind0(Native Method)
	at java.net.DualStackPlainSocketImpl.socketBind(DualStackPlainSocketImpl.java:96)
	at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:376)
	at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:175)
	at java.net.ServerSocket.bind(ServerSocket.java:376)
	at java.net.ServerSocket.<init>(ServerSocket.java:237)
	at java.net.ServerSocket.<init>(ServerSocket.java:181)
	at org.eclipse.jetty.server.bio.SocketConnector.newServerSocket(SocketConnector.java:96)
	at org.eclipse.jetty.server.bio.SocketConnector.open(SocketConnector.java:85)
	at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:316)
	at org.eclipse.jetty.server.bio.SocketConnector.doStart(SocketConnector.java:156)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at org.eclipse.jetty.server.Server.doStart(Server.java:291)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1259)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1182)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.eclipse.jetty.start.Main.invokeMain(Main.java:473)
	at org.eclipse.jetty.start.Main.start(Main.java:615)
	at org.eclipse.jetty.start.Main.main(Main.java:96)
INFO  - 2014-11-18 11:11:29.825; org.apache.solr.core.QuerySenderListener; QuerySenderListener done.
WARN  - 2014-11-18 11:11:29.850; org.eclipse.jetty.util.component.AbstractLifeCycle; FAILED org.eclipse.jetty.server.Server@66b6d1a8: java.net.BindException: Address already in use: JVM_Bind
java.net.BindException: Address already in use: JVM_Bind
	at java.net.DualStackPlainSocketImpl.bind0(Native Method)
	at java.net.DualStackPlainSocketImpl.socketBind(DualStackPlainSocketImpl.java:96)
	at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:376)
	at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:175)
	at java.net.ServerSocket.bind(ServerSocket.java:376)
	at java.net.ServerSocket.<init>(ServerSocket.java:237)
	at java.net.ServerSocket.<init>(ServerSocket.java:181)
	at org.eclipse.jetty.server.bio.SocketConnector.newServerSocket(SocketConnector.java:96)
	at org.eclipse.jetty.server.bio.SocketConnector.open(SocketConnector.java:85)
	at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:316)
	at org.eclipse.jetty.server.bio.SocketConnector.doStart(SocketConnector.java:156)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at org.eclipse.jetty.server.Server.doStart(Server.java:291)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1259)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1182)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)



从异常中,我们可以轻易看出是8983端口,被占用了,然后再次启动时,出现叠加端口,就会报上述异常,那么如何定位,查找,占用的端口号呢?



1,打开windows上的cmd窗口
2,使用netstat -aon | findstr "8983"查看端口所在进程
3,然后使用tasklist | findstr "进程id" 找出具体的程序所在主服务


截图如下:






定位到异常所在服务后,查看有关服务,是否冲突,然后关掉即可(关掉之前,确认是否真的可以停掉,以免影响一些其他的服务,正常运行)!