首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在发现服务中注册多个IP

在发现服务中注册多个IP
EN

Stack Overflow用户
提问于 2019-05-01 11:04:42
回答 1查看 1.1K关注 0票数 1

我们在目前的项目中使用Netflix,该项目将在几周内投入使用。上周之前一切都很好。服务在发现号中注册,网关能够将流量路由到所需的服务,门户运行良好。但是当在每个服务器上安装备份NIC卡时。当我重新启动服务时,服务将使用第二个nat IP地址(10.1.220.125)注册,而不是主机名(以前是)。我搜索了谷歌,发现了许多配置,但当我申请时,我并没有得到成功/预期的结果。其中一种配置如下:

代码语言:javascript
复制
spring:
  cloud:
    inetutils:
      ignoredInterfaces:
        - p2p.*

这是我的发现服务器的application.yml文件。

代码语言:javascript
复制
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.*

当我看到日志时,我看到发现服务正在注册,如下所示:

代码语言:javascript
复制
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时,我会在日志中获取消息:

代码语言:javascript
复制
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注册我的服务?

我们正在使用Dalston.SR1版本的spring。

编辑:使用verion Greenwich.RC2

代码语言:javascript
复制
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.*

我得到了以下错误:

代码语言:javascript
复制
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详细信息。

代码语言:javascript
复制
[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 ~]$

更新2

pom.xml

代码语言:javascript
复制
<?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

代码语言:javascript
复制
spring:
  application:
    name: discovery-service

MainApplication

代码语言:javascript
复制
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(DiscoveryServiceApplication.class, args);
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-30 10:23:05

@spencergib,我找到了解决办法。

在/etc/host文件中,我将条目放置如下:

代码语言:javascript
复制
KOLSRV1   10.1.220.125

现在,这些服务正在使用名称而不是IP在发现服务中注册。

代码语言:javascript
复制
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)

谢谢..

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55935236

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档