When thrown ehcache RMI cluster service java.rmi.ConnectException: Connection refused to host: 127.0.0.1 Abnormal causes and solutions

 

Recent jmx encounter a problem, client / server on the same machine, jmx client can successfully connect server, if the server transplanted to another machine on 192.168.134.128, throws the following exception:

java.net.ConnectException: Connection refused: connect  
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:   
    java.net.ConnectException: Connection refused: connect  
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)  
    at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)  
    at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)  
    at sun.rmi.server.UnicastRef.invoke(Unknown Source)  
    at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)  
    at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)  
    at $Proxy0.getAllSections(Unknown Source)  
    at ccg.boccrawler.rmi.TestClient.main(TestClient.java:21) 

The reason : This question is actually made rmi server will cause the end of the program. A client object request to the server when, Stub object returned which contains the hostname of the server, the subsequent operation of the client connection to the server according to this hostname. To know what the specific value of the hostname on the server side can bash into the directive: hostname -i If the return is 127.0.0.1 , then your clients will certainly throw an exception as the title.

Solution:

There are two solutions:

Method 1: / etc / hosts 127.0.0.1 modifications in the actual IP address (this approach may cause some applications can not be used, not recommended)

Method 2: first add a line in / etc / hosts, and then modify / etc / sysconfig / network file inside HOSTNAME

As your hosts file original content

[root@test132 /]# vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
  •  

The machine's actual IP is 192.168.134.132, you can add the following

192.168.134.132 test132 localhost
  •  

Then modify / etc / sysconfig / network file HOSTNAME = test, you can visit a success.

[root@test132 /]# vim /etc/sysconfig/network

# Created by anaconda
HOSTNAME=test132
  •  

Supplementary: http://scork520.blog.163.com/blog/static/49099202201081324215183/  this article talked about the role and the hosts hostname configuration file, it should look helpful.

Transfer: https://blog.csdn.net/liupeifeng3514/article/details/78998127

Guess you like

Origin blog.csdn.net/zhaofuqiangmycomm/article/details/88535690