在发现服务中注册多个 IP
Registering in Discovery Service for multiple IPs
我们正在我们当前的项目中使用 Netflix OSS,该项目将在几周内上线。一切都很好,直到上周。服务在发现中注册,网关能够将流量路由到所需的服务,门户工作正常。但是当每台服务器都安装了备份网卡时。当我重新启动服务时,服务正在使用第二个 nat IP 地址(10.1.220.125)而不是主机名(以前是)注册。我搜索了 google 并找到了很多配置,但是当我申请时我没有得到 successful/expected 结果。一种这样的配置如下:
spring:
cloud:
inetutils:
ignoredInterfaces:
- p2p.*
这是我的 application.yml 发现服务器文件。
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.*
当我看到日志时,我看到正在注册发现服务,如下所示:
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)
其中 10.1.220.125 是新的 nat IP。
之前我曾经在只有一个nat IP(10.1.115.8)并且没有备份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)
其中 KOLSRV1 是具有 IP 10.1.115.8 和 10.1.220.125 的服务器主机名。
如何使用主机名而不是 IP 注册我的服务?
我们正在使用 spring 云的 Dalston.SR1 版本。
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.*
我收到以下错误:
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!
为了您的参考,我提供了服务器的 ifconfig 详细信息。
[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
主应用程序
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServiceApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryServiceApplication.class, args);
}
}
@spencergib,我找到了解决方案。
在 /etc/hosts 文件中,我输入了
KOLSRV1 10.1.220.125
现在服务正在使用名称而不是 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)
谢谢..
我们正在我们当前的项目中使用 Netflix OSS,该项目将在几周内上线。一切都很好,直到上周。服务在发现中注册,网关能够将流量路由到所需的服务,门户工作正常。但是当每台服务器都安装了备份网卡时。当我重新启动服务时,服务正在使用第二个 nat IP 地址(10.1.220.125)而不是主机名(以前是)注册。我搜索了 google 并找到了很多配置,但是当我申请时我没有得到 successful/expected 结果。一种这样的配置如下:
spring:
cloud:
inetutils:
ignoredInterfaces:
- p2p.*
这是我的 application.yml 发现服务器文件。
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.*
当我看到日志时,我看到正在注册发现服务,如下所示:
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)
其中 10.1.220.125 是新的 nat IP。
之前我曾经在只有一个nat IP(10.1.115.8)并且没有备份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)
其中 KOLSRV1 是具有 IP 10.1.115.8 和 10.1.220.125 的服务器主机名。
如何使用主机名而不是 IP 注册我的服务?
我们正在使用 spring 云的 Dalston.SR1 版本。
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.*
我收到以下错误:
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!
为了您的参考,我提供了服务器的 ifconfig 详细信息。
[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
主应用程序
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServiceApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryServiceApplication.class, args);
}
}
@spencergib,我找到了解决方案。
在 /etc/hosts 文件中,我输入了
KOLSRV1 10.1.220.125
现在服务正在使用名称而不是 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)
谢谢..