connections java.net.BindException: Address already in use_解决方案

Posted insane-mr-li

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了connections java.net.BindException: Address already in use_解决方案相关的知识,希望对你有一定的参考价值。

一、问题描述

在Linux服务器(CentOS7系统)中配置并启动JMeter远程监控服务器资源所需的ServerAgent目录下的 startAgent.sh 文件时,系统出现异常提示,如

[[email protected] ServerAgent-2.2.3]# ./startAgent.sh
INFO    2018-12-15 10:29:17.634 [kg.apc.p] (): Binding UDP to 4444
ERROR   2018-12-15 10:29:17.686 [kg.apc.p] (): Cant accept UDP connections
java.net.BindException: Address already in use
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Net.java:433)
        at sun.nio.ch.DatagramChannelImpl.bind(DatagramChannelImpl.java:691)
        at sun.nio.ch.DatagramSocketAdaptor.bind(DatagramSocketAdaptor.java:91)
        at kg.apc.perfmon.PerfMonWorker.listenUDP(PerfMonWorker.java:144)
        at kg.apc.perfmon.PerfMonWorker.startAcceptingCommands(PerfMonWorker.java:107)
        at kg.apc.perfmon.AgentTool.processParams(AgentTool.java:72)
        at kg.apc.cmdtools.PluginsCMD.processParams(PluginsCMD.java:63)
        at kg.apc.cmdtools.PluginsCMD.processParams(PluginsCMD.java:23)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

二、问题分析

从以上抛出的异常信息中提取关键的提示信息:
"Can‘t accept UDP connections
java.net.BindException: Address already in use"

分析:ServerAgent默认开始的是4444端口,提示“不能接收UDP连接,地址已在使用中”,很可能是该端口已被占用,需要修改为新的端口号再启用or先暂停该端口对应的进程,然后再启用ServerAgent服务

三、解决方案

方式1:先暂停4444端口,再启用ServerAgent服务

查询4444端口当前对应的进程:lsof -i:4444


[[email protected] ServerAgent-2.2.3]# lsof -i:4444
COMMAND    PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
java    104069 root   18u  IPv6 3997358      0t0  UDP *:krb524
java    104069 root   19u  IPv6 3997549      0t0  TCP *:krb524 (LISTEN)

关闭指定PID号码的进程(4444端口进程):kill -9 104069
此时,亦可正常启用ServerAgent服务,如下:

[[email protected] ServerAgent-2.2.3]# kill -9 104069
[[email protected] ServerAgent-2.2.3]# lsof -i:4444
[[email protected] ServerAgent-2.2.3]# ./startAgent.sh
INFO    2018-12-15 10:41:51.043 [kg.apc.p] (): Binding UDP to 4444
INFO    2018-12-15 10:41:52.059 [kg.apc.p] (): Binding TCP to 4444
INFO    2018-12-15 10:41:52.066 [kg.apc.p] (): [email protected] Agent v2.2.3 started
方式2:修改ServerAgent端口,再启用ServerAgent服务

./startAgent.sh –udp-port 0 –tcp-port xxxx ("xxxx" 为新端口号,如:4567)
./startAgent.sh –udp-port 0 –tcp-port 4567






以上是关于connections java.net.BindException: Address already in use_解决方案的主要内容,如果未能解决你的问题,请参考以下文章

connect()的函数说明

QT connect函数的用法

io.on('connection',...) 与 io.sockets.on('connection',...)

HTTP 标头中的 Connection 和 Proxy-connection 有啥区别?

matlab中connect函数用法

max_connections 与 max_used_connections --ERROR 1040: Too many connections