When deploying Eureka high availability solution on the Linux host, I found that the service IP registered to the service center was random. Since there are multiple network cards on the host, the random IP was not what I wanted. I searched some information online and summarized as follows:
1 Ignore network card: spring.cloud.inetutils.ignored-interfaces
#Ignore eth0, support regular expression spring.cloud.inetutils.ignored-interfaces[0]=eth0
2 Specify IP: spring.cloud.inetutils.preferred-networks
#preferred-networks refers to the IP address that tends to be used, receiving an array of regular expressions to select the IP address of the native machine used by Spring Cloud applications. spring.cloud.inetutils.preferredNetworks[0]=^192/.168
3 Modify the Host file
When the network search traversal logic does not find the appropriate ip, it will go to JDK's InetAddress.getLocalHost(). This method will return the hostname of the current host, and then parse the corresponding ip based on the hostname. Therefore, the second solution is to configure the hostname and /etc/hosts files of the machine, and directly map the hostname of the machine to the valid IP address.
4 Specify the instance IP
#Specify the ipeureka.instance.ip-address=#Use ip instead of hostname eureka.instance.prefer-ip-address=true for registration
5 Pass the jar command parameter
java -jar xxx.jar --spring.cloud.inetutils.preferred-networks= #The IP address that needs to be set or java -jar xxx.jar --spring.cloud.inetutils.ignored-interfaces= #The network card that needs to be filtered out
The above novice has been struggling for an afternoon, and everyone has a good way to communicate together. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.