首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法注册多个eureka实例

无法注册多个eureka实例
EN

Stack Overflow用户
提问于 2017-11-02 10:49:56
回答 4查看 3.5K关注 0票数 0

我正在尝试创建两个Eureka server.But实例,当我运行它时,它们无法相互注册。我所犯的错误是:

com.netflix.discovery.DiscoveryClient :从eureka服务器获取所有实例注册表信息2017-11-02 15:51:14.125错误34 -主c.n.d.s.t.d.RedirectingEurekaHttpClient :请求执行错误 com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException:连接被拒绝(连接被拒绝)在com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~jersey-apache-client4-1.19.1.jar!/:1.19.1

主要应用程序文件是:

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

代码语言:javascript
复制
---
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-compose文件是:

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

代码语言:javascript
复制
<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都运行良好。但他们没有注册对方。

屏幕截图随附以获得更多信息:服务器-1 服务器-2

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2017-11-03 01:50:24

尝试修改注册-server.yml如下,对于两个文件,您忽略了defaultZone之前的一个.yml空间。顺便说一下,这些文件中仍然有许多语法错误。

对于eureka-服务器-1:

代码语言:javascript
复制
eureka:
  ...
  client:
    ...
    serviceUrl:
      defaultZone: http://server-2:2424/eureka/

对于eureka-服务器-2:

代码语言:javascript
复制
eureka:
  ...
  client:
    ...
    serviceUrl:
      defaultZone: http://server-1:2323/eureka/

下面是我的eureka服务器设置之一,这两个服务器之间相互注册非常好:

代码语言:javascript
复制
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}
票数 1
EN

Stack Overflow用户

发布于 2017-11-02 11:02:36

我不确定Eureka是否可以注册另一个Eureka,但从概念上看,它也是一个正在运行的服务。因此,可以同时充当服务和服务器(Eureka)。但我不完全确定。

无论如何,我认为您应该在您的Eurekaserverapplication中尝试这一点。

代码语言:javascript
复制
@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即可。因为您的应用程序应该同时充当客户端和服务器。所以,我认为这些注释很重要。

票数 0
EN

Stack Overflow用户

发布于 2017-11-02 11:59:46

不确定,试着改变

代码语言:javascript
复制
eureka:
  instance:
    hostname

相应地指向“server-1”和“server-2”。

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

https://stackoverflow.com/questions/47073447

复制
相关文章

相似问题

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