我正在尝试远程连接到一个JMX端口,但即使该端口已打开,似乎仍无法连接。它是在Nomad工作节点上运行的容器内Java进程,正在运行于 29406
端口。
下面是 netstat
显示的信息:
netstat -tulpn | grep 29406
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 10.137.2.166:29406 0.0.0.0:* LISTEN -
udp 0 0 10.137.2.166:29406 0.0.0.0:* -
这是位于
/etc/hosts
中的内容。cat /etc/hosts
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
我已经在服务器上下载了jmxterm
,并尝试连接它时发现了一个有趣的行为。当我尝试使用localhost
来连接端口时,会得到以下结果:
#RuntimeIOException: Runtime IO exception: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
java.net.ConnectException: Connection refused (Connection refused)]
当我使用自己的IP地址时,它似乎可以正常工作:
$>open 10.137.2.166:29406
#Connection to 10.137.2.166:29406 is opened
$>
想了解为什么在服务器本身上运行时本地主机(localhost)无法使用...
我唯一成功让我的笔记本电脑上运行的 jconsole
连接到它的方式是使用 ssh 隧道,像这样:
ssh -Nf -D 7777 10.137.2.166
jconsole -J-DsocksProxyHost=localhost -J-DsocksProxyPort=7777 service:jmx:rmi:///jndi/rmi://10.137.2.166:29406/jmxrmi -J-DsocksNonProxyHosts=
我感觉应该能够在不创建隧道的情况下连接到它,但不确定为什么不能。如果我从我的笔记本电脑本地运行telnet到主机,连接似乎是打开的...
telnet 10.137.2.166 29406
Trying 10.137.2.166...
Connected to 10.137.2.166.
Escape character is '^]'.