Регистрация в службе обнаружения для нескольких IP-адресов - PullRequest
0 голосов
/ 01 мая 2019

Мы используем Netflix OSS в нашем текущем проекте, который будет запущен через несколько недель. Все было хорошо до прошлой недели. сервисы регистрировались в обнаружении, шлюз мог перенаправлять трафик на требуемые сервисы, портал работал нормально. Но когда на каждом из серверов установлена ​​резервная сетевая карта. Когда я перезапускаю сервисы, сервисы регистрируются с IP-адресом 2-го nat (10.1.220.125) вместо имени хоста (раньше это было). Я искал в Google и нашел много конфигураций, но когда я подал заявку, я не получил успешный / ожидаемый результат. Одна из таких конфигураций, как показано ниже:

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.*

Когда я вижу журнал, я вижу, что discovery-сервис регистрируется, как показано ниже:

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?

Мы используем версию весеннего облака Dalston.SR1.

Отредактировано: с веррионом Гринвичем.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 ~]$

Обновление 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);
    }
}

1 Ответ

1 голос
/ 30 мая 2019

@ 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)

спасибо ..

...