java.net.BindException:地址已在使用中:JVM_Bind

2022-01-16 00:00:00 jvm java tomcat tomcat7

我的服务器中有 2 个 tomcat 正在运行

I have 2 tomcats running in my server

一个是tomcat 7,一个是tomcat 8,第一个的配置文件server.xml是:

one Tomcat 7 and the other is tomcat 8, the configuration file server.xml for the first is:

           <Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
             ...
           <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

在第二个tomcat中有:

In the second tomcat have:

            <Connector port="8080" protocol="HTTP/1.1"
            connectionTimeout="20000"
            redirectPort="8443" />
            ...
            <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

但是当我运行第一个 tomcat 时,控制台说

but when I run the first tomcat the console say

java.net.BindException: Address already in use: JVM_Bind
at java.net.DualStackPlainSocketImpl.bind0(Native Method)
at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
at java.net.PlainSocketImpl.bind(Unknown Source)
at java.net.ServerSocket.bind(Unknown Source)
at java.net.ServerSocket.<init>(Unknown Source)
at org.apache.catalina.core.StandardServer.await(StandardServer.java:420)
at org.apache.catalina.startup.Catalina.await(Catalina.java:713)
at org.apache.catalina.startup.Catalina.start(Catalina.java:659)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)

但第二次运行良好,我使用命令 netstate -t​​nao 并验证端口是免费的

but the second run good, i using the command netstate -tnao and i verified that the ports are free

推荐答案

<Connector port="8080" protocol="HTTP/1.1"
       connectionTimeout="20000"
       redirectPort="8443" />

8080 是服务器将运行的端口号.只有一个服务器(您将首先启动)将运行.其他的会抛出 Jvm Bind Exception.

8080 is the port number on which server will run. Only one server (which you will start first) would run. Other one will throw Jvm Bind Exception.

所以,更改端口号,使它们是唯一的.

So, change the port number so that they are unique.

你运行第一台服务器然后使用 netstat 命令查看正在使用的端口.

One you run first server then use netstat command to see the ports which are in use.

相关文章