一、问题描述
在Linux服务器(CentOS7系统)中配置并启动JMeter远程监控服务器资源所需的ServerAgent目录下的 startAgent.sh 文件时,系统出现异常提示,如下:
[root@fighter007 ServerAgent-2.2.1]# ./startAgent.sh
INFO 2019-05-28 20:21:47.946 [kg.apc.p] (): Binding UDP to 4444
ERROR 2019-05-28 20:21:47.966 [kg.apc.p] (): Can't 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:344)
at sun.nio.ch.DatagramChannelImpl.bind(DatagramChannelImpl.java:672)
at sun.nio.ch.DatagramSocketAdaptor.bind(DatagramSocketAdaptor.java:91)
at kg.apc.perfmon.PerfMonWorker.listenUDP(PerfMonWorker.java:154)
at kg.apc.perfmon.PerfMonWorker.startAcceptingCommands(PerfMonWorker.java:117)
at kg.apc.perfmon.AgentTool.processParams(AgentTool.java:69)
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:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at kg.apc.cmd.UniversalRunner.main(UniversalRunner.java:175)
INFO 2019-05-28 20:21:47.967 [kg.apc.p] (): Binding TCP to 4444
ERROR 2019-05-28 20:21:47.970 [kg.apc.p] (): Can't accept TCP connections
二、问题分析
从以上抛出的异常信息中提取关键的提示信息:
"Can't accept UDP connections
java.net.BindException: Address already in use"
分析:ServerAgent默认开始的是4444端口,提示“不能接收UDP连接,地址已在使用中”,很可能是该端口已被占用,需要修改为新的端口号再启用or先暂停该端口对应的进程,然后再启用ServerAgent服务
三、解决方案
方式1:先暂停4444端口,再启用ServerAgent服务
查询4444端口当前对应的进程:lsof -i:4444
[root@fighter007 ServerAgent-2.2.1]# lsof -i:4444
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
java 19720 root 19u IPv6 129879 UDP *:krb524
java 19720 root 20u IPv6 129880 TCP *:krb524 (LISTEN)
关闭指定PID号码的进程(4444端口进程):kill -9 104069
此时,亦可正常启用ServerAgent服务,如下:
[root@fighter007 ServerAgent-2.2.1]# ./startAgent.sh
INFO 2019-05-28 20:25:42.130 [kg.apc.p] (): Binding UDP to 4444
INFO 2019-05-28 20:25:43.169 [kg.apc.p] (): Binding TCP to 4444
INFO 2019-05-28 20:25:43.173 [kg.apc.p] (): JP@GC Agent v2.2.0 started
方式2:修改ServerAgent端口,再启用ServerAgent服务
./startAgent.sh –udp-port 0 –tcp-port xxxx ("xxxx" 为新端口号,如:4567)
./startAgent.sh –udp-port 0 –tcp-port 4567