We are using Netflix OSS in our current project which is about to go live within a few weeks. Everything was good until last week. services were getting registered in discovery, the gateway was able to route traffic to required services, the portal was working fine. But when a backup NIC card is installed in each of the servers. When I am restarting the services, the services are getting registered with 2nd nat IP address (10.1.220.125), instead of the hostname (earlier it used to be). I searched google and found many configurations, but when I applied I am not getting the successful/expected result. One such configuration is as below:
spring:
cloud:
inetutils:
ignoredInterfaces:
- p2p.*
Here is my application.yml file of the discovery server.
spring:
application:
name: discovery-service
server:
port: 8761
eureka:
client:
registerWithEureka: true
fetchRegistry: true
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://10.1.115.8:8761/eureka/
instance:
registryFetchIntervalSeconds: 30
leaseRenewalIntervalInSeconds: 10
leaseExpirationDurationInSeconds: 30
zuul.sensitiveHeaders:
hystrix:
command:
default:
execution:
isolation:
strategy: THREAD
thread:
timeoutInMilliseconds: 500000
spring:
cloud:
inetutils:
ignoredInterfaces:
- p2p.*
When I see the log, I see that discovery-service is being registered like below:
Registered instance DISCOVERY-SERVICE/10.1.220.125:discovery-service:8761 with status UP (replication=false)
DiscoveryClient_DISCOVERY-SERVICE/10.1.220.125:discovery-service:8761 - registration status: 204
Registered instance DISCOVERY-SERVICE/10.1.220.125:discovery-service:8761 with status UP (replication=true)
Where 10.1.220.125 is the new nat IP.
Earlier I used to get the message in log when there was only one nat IP (10.1.115.8) and no backup IP:
Registered instance DISCOVERY-SERVICE/KOLSRV1:discovery-service:8761 with status UP (replication=false)
DiscoveryClient_DISCOVERY-SERVICE/KOLSRV1:discovery-service:8761 - registration status: 204
Registered instance DISCOVERY-SERVICE/KOLSRV1:discovery-service:8761 with status UP (replication=true)
Where KOLSRV1 is the server host name having IP 10.1.115.8 and 10.1.220.125.
How can I register my services with host name instead of IP?
We are using Dalston.SR1 version of spring cloud.
Edited: With verion Greenwich.RC2
server:
port: 8761
eureka:
environment: prod
client:
registerWithEureka: true
fetchRegistry: true
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://10.1.115.8:8761/eureka/
instance:
registryFetchIntervalSeconds: 30
leaseRenewalIntervalInSeconds: 10
leaseExpirationDurationInSeconds: 30
hostname: KOLSRV1
ip-address: 10.1.115.8
preferIpAddress: false
#preferredNic: bond0
#forceHostAddress: 10.1.115.8
zuul.sensitiveHeaders:
hystrix:
command:
default:
execution:
isolation:
strategy: THREAD
thread:
timeoutInMilliseconds: 500000
spring:
cloud:
inetutils:
ignoredInterfaces:
- p2p.*
I am getting the below error:
Request execution failed with message: A message body reader for Java class com.netflix.appinfo.InstanceInfo, and Java type class com.netflix.appinfo.InstanceInfo, and MIME media type text/html; charset=utf-8 was not found
DiscoveryClient_DISCOVERY-SERVICE/10.1.220.125:discovery-service:8761 - was unable to send heartbeat!
For your reference, I am providing the ifconfig details of the server.
[user@KOLSRV1 ~]$ ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500
inet 10.1.115.8 netmask 255.255.255.128 broadcast 10.1.115.127
ether 00:0a:f7:e7:88:40 txqueuelen 1000 (Ethernet)
RX packets 976056244 bytes 249957809358 (232.7 GiB)
RX errors 0 dropped 0 overruns 0 frame 193559
TX packets 937501062 bytes 243749426487 (227.0 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
em1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 00:0a:f7:e7:88:40 txqueuelen 1000 (Ethernet)
RX packets 975667166 bytes 249931945975 (232.7 GiB)
RX errors 0 dropped 0 overruns 0 frame 193559
TX packets 937501062 bytes 243749426487 (227.0 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
em2: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 00:0a:f7:e7:88:41 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
em3: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 00:0a:f7:e7:88:3e txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16
em4: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 00:0a:f7:e7:88:3f txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 17
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 23915308 bytes 7603519514 (7.0 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 23915308 bytes 7603519514 (7.0 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
p2p1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 00:0a:f7:e7:88:40 txqueuelen 1000 (Ethernet)
RX packets 389078 bytes 25863383 (24.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
p2p2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.1.220.125 netmask 255.255.254.0 broadcast 10.1.221.255
ether 00:0a:f7:f3:03:01 txqueuelen 1000 (Ethernet)
RX packets 81021 bytes 14512406 (13.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 196820 bytes 265515182 (253.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:ad:3c:27 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[user@KOLSRV1 ~]$
Update 2
pom.xml
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/>
</parent>
<artifactId>discovery-service</artifactId>
<name>discovery-service</name>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RC2</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>discovery-service</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>application.yml</exclude>
<exclude>*.xml</exclude>
<exclude>*.properties</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.sample.DiscoveryServiceApplication</mainClass>
<addResources>true</addResources>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${argLine} -noverify</argLine>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
</project>
bootstrap.yml
spring:
application:
name: discovery-service
MainApplication
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServiceApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryServiceApplication.class, args);
}
}
@spencergib, I found the solution.
In /etc/hosts file I put the entry like,
KOLSRV1 10.1.220.125
Now the services are getting registered in discovery services using name instead of IP.
Registered instance DISCOVERY-SERVICE/KOLSRV1:discovery-service:8761 with status UP (replication=false)
DiscoveryClient_DISCOVERY-SERVICE/KOLSRV1:discovery-service:8761 - registration status: 204
Registered instance DISCOVERY-SERVICE/KOLSRV1:discovery-service:8761 with status UP (replication=true)
Thanks..