无法注册多个尤里卡实例
Unable to register multiple instance of eureka
我正在尝试创建两个 Eureka server.But 实例,但我 运行 它们无法相互注册。我得到的错误是:
com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2017-11-02 15:51:14.125 ERROR 34 --- [ main] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused)
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar!/:1.19.1]
主要应用文件是:
@SpringBootApplication
@EnableEurekaServer
public class RegistrationServer {
public static void main(String[] args) {
System.setProperty("spring.config.name", "registration-server");
SpringApplication.run(RegistrationServer.class, args);
}
}
注册-server.yml是:
---
spring.profiles: server-1
eureka:
instance:
hostname: localhost #eureka-server
server:
enableSelfPreservation: false
client:
register-with-eureka: true
fetch-registry: true
serviceUrl:
defaultZone: http://server-2:2424/eureka/
server:
port: 2323 # HTTP (Tomcat) port
spring:
application:
name: eureka-server1
---
spring.profiles: server-2
eureka:
instance:
hostname: localhost #eureka-server
server:
enableSelfPreservation: false
client:
register-with-eureka: true
fetch-registry: true
serviceUrl:
defaultZone: http://server-1:2323/eureka/
server:
port: 2424 # HTTP (Tomcat) port
spring:
application:
name: eureka-server2
---
docker-撰写文件为:
version: '2'
services:
lb:
image: dockercloud/haproxy
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "80:80"
- "1936:1936"
eureka-service-1:
image: qaregistry.test.com/registration-server:0.0.2
ports:
- "2323:2323"
environment:
- APPBINARY=registration-server.jar
- "SPRING_PROFILES_ACTIVE=server-1"
extra_hosts:
- "server-1:127.0.0.1"
- "server-2:127.0.0.1"
entrypoint:
- /usr/bin/jarrun.sh
- QA
eureka-service-2:
image: qaregistry.test.com/registration-server:0.0.2
ports:
- "2424:2424"
environment:
- APPBINARY=registration-server.jar
- "SPRING_PROFILES_ACTIVE=server-2"
extra_hosts:
- "server-1:127.0.0.1"
- "server-2:127.0.0.1"
entrypoint:
- /usr/bin/jarrun.sh
- QA
pox.xml 是:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>registration-server</artifactId>
<version>0.0.2</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<!-- Setup Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<!-- Setup Spring MVC & REST, use Embedded Tomcat -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<!-- Spring Cloud starter -->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<!-- Eureka service registration -->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- added by linux team for docker integration with maven -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<serverId>dockerhub</serverId>
<imageName>qaregistry.test.com/${project.artifactId}:${project.version}</imageName>
<pullOnBuild>true</pullOnBuild>
<registryUrl>https://qaregistry.test.com</registryUrl>
<baseImage>qaregistry.test.com/test-jdk:8u121</baseImage>
<maintainer>USER user@test.com</maintainer>
<labels>
<label>ProductName=${project.build.finalName}</label>
</labels>
<user>test</user>
<entryPoint>["/usr/bin/jarrun.sh"]</entryPoint>
<resources>
<resource>
<targetPath>/data/test/run/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>
eureka 的两个实例,即 server-1 和 server-2 运行都很好。但是他们没有互相注册。
Screenshots are attached for more info: server-1
server-2
我不确定 Eureka 是否可以注册另一个 Eureka,但从概念上看它也是一个服务 运行。因此可以同时充当服务和服务器(尤里卡)。但我不是很确定。
无论如何,我认为你应该在你的 Eureka 服务器应用程序中尝试这个
@SpringBootApplication
@EnableEurekaClient
@EnableEurekaServer
public class RegistrationServer {
public static void main(String[] args) {
System.setProperty("spring.config.name", "registration-server");
SpringApplication.run(RegistrationServer.class, args);
}
}
只需尝试将 @EnableEurekaClient
或 @EnableDiscoveryClient
用于启动应用程序。由于您的应用程序应该同时充当客户端和服务器。
所以,我认为这些注释很重要。
不确定,尝试更改
eureka:
instance:
hostname
相应地 'server-1' 和 'server-2'
尝试修改您的注册-server.yml 如下,您在 defaultZone
之前错过了 ONE space 两个 .yml 文件。顺便说一句,这些文件中还有很多语法错误。
对于 eureka-server-1:
eureka:
...
client:
...
serviceUrl:
defaultZone: http://server-2:2424/eureka/
对于 eureka-server-2:
eureka:
...
client:
...
serviceUrl:
defaultZone: http://server-1:2323/eureka/
这是我的 eureka 服务器设置之一,两个服务器相互注册时效果很好:
spring:
application:
name: registry
server:
port: 2323
eureka:
server:
eviction-interval-timer-in-ms: 15000
client:
fetch-registry: true
register-with-eureka: true
serviceUrl:
defaultZone: ${eureka_url:http://localhost:2424/eureka}
instance:
instance-id: ${spring.application.name}:${random.value}
hostname: ${eureka_host:localhost}
secure-port: ${server.port}
non-secure-port-enabled: true
non-secure-port: ${server.port}
看看这个post
我正在尝试创建两个 Eureka server.But 实例,但我 运行 它们无法相互注册。我得到的错误是:
com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server 2017-11-02 15:51:14.125 ERROR 34 --- [ main] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused) at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar!/:1.19.1]
主要应用文件是:
@SpringBootApplication
@EnableEurekaServer
public class RegistrationServer {
public static void main(String[] args) {
System.setProperty("spring.config.name", "registration-server");
SpringApplication.run(RegistrationServer.class, args);
}
}
注册-server.yml是:
---
spring.profiles: server-1
eureka:
instance:
hostname: localhost #eureka-server
server:
enableSelfPreservation: false
client:
register-with-eureka: true
fetch-registry: true
serviceUrl:
defaultZone: http://server-2:2424/eureka/
server:
port: 2323 # HTTP (Tomcat) port
spring:
application:
name: eureka-server1
---
spring.profiles: server-2
eureka:
instance:
hostname: localhost #eureka-server
server:
enableSelfPreservation: false
client:
register-with-eureka: true
fetch-registry: true
serviceUrl:
defaultZone: http://server-1:2323/eureka/
server:
port: 2424 # HTTP (Tomcat) port
spring:
application:
name: eureka-server2
---
docker-撰写文件为:
version: '2'
services:
lb:
image: dockercloud/haproxy
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "80:80"
- "1936:1936"
eureka-service-1:
image: qaregistry.test.com/registration-server:0.0.2
ports:
- "2323:2323"
environment:
- APPBINARY=registration-server.jar
- "SPRING_PROFILES_ACTIVE=server-1"
extra_hosts:
- "server-1:127.0.0.1"
- "server-2:127.0.0.1"
entrypoint:
- /usr/bin/jarrun.sh
- QA
eureka-service-2:
image: qaregistry.test.com/registration-server:0.0.2
ports:
- "2424:2424"
environment:
- APPBINARY=registration-server.jar
- "SPRING_PROFILES_ACTIVE=server-2"
extra_hosts:
- "server-1:127.0.0.1"
- "server-2:127.0.0.1"
entrypoint:
- /usr/bin/jarrun.sh
- QA
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>registration-server</artifactId>
<version>0.0.2</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<!-- Setup Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<!-- Setup Spring MVC & REST, use Embedded Tomcat -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<!-- Spring Cloud starter -->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<!-- Eureka service registration -->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- added by linux team for docker integration with maven -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<serverId>dockerhub</serverId>
<imageName>qaregistry.test.com/${project.artifactId}:${project.version}</imageName>
<pullOnBuild>true</pullOnBuild>
<registryUrl>https://qaregistry.test.com</registryUrl>
<baseImage>qaregistry.test.com/test-jdk:8u121</baseImage>
<maintainer>USER user@test.com</maintainer>
<labels>
<label>ProductName=${project.build.finalName}</label>
</labels>
<user>test</user>
<entryPoint>["/usr/bin/jarrun.sh"]</entryPoint>
<resources>
<resource>
<targetPath>/data/test/run/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>
eureka 的两个实例,即 server-1 和 server-2 运行都很好。但是他们没有互相注册。
Screenshots are attached for more info: server-1
server-2
我不确定 Eureka 是否可以注册另一个 Eureka,但从概念上看它也是一个服务 运行。因此可以同时充当服务和服务器(尤里卡)。但我不是很确定。
无论如何,我认为你应该在你的 Eureka 服务器应用程序中尝试这个
@SpringBootApplication
@EnableEurekaClient
@EnableEurekaServer
public class RegistrationServer {
public static void main(String[] args) {
System.setProperty("spring.config.name", "registration-server");
SpringApplication.run(RegistrationServer.class, args);
}
}
只需尝试将 @EnableEurekaClient
或 @EnableDiscoveryClient
用于启动应用程序。由于您的应用程序应该同时充当客户端和服务器。
所以,我认为这些注释很重要。
不确定,尝试更改
eureka:
instance:
hostname
相应地 'server-1' 和 'server-2'
尝试修改您的注册-server.yml 如下,您在 defaultZone
之前错过了 ONE space 两个 .yml 文件。顺便说一句,这些文件中还有很多语法错误。
对于 eureka-server-1:
eureka:
...
client:
...
serviceUrl:
defaultZone: http://server-2:2424/eureka/
对于 eureka-server-2:
eureka:
...
client:
...
serviceUrl:
defaultZone: http://server-1:2323/eureka/
这是我的 eureka 服务器设置之一,两个服务器相互注册时效果很好:
spring:
application:
name: registry
server:
port: 2323
eureka:
server:
eviction-interval-timer-in-ms: 15000
client:
fetch-registry: true
register-with-eureka: true
serviceUrl:
defaultZone: ${eureka_url:http://localhost:2424/eureka}
instance:
instance-id: ${spring.application.name}:${random.value}
hostname: ${eureka_host:localhost}
secure-port: ${server.port}
non-secure-port-enabled: true
non-secure-port: ${server.port}
看看这个post