I am trying to create two instance of Eureka server.But when i run it they are unable to register each other. Error i am getting is:
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]
Main application file is:
@SpringBootApplication
@EnableEurekaServer
public class RegistrationServer {
public static void main(String[] args) {
System.setProperty("spring.config.name", "registration-server");
SpringApplication.run(RegistrationServer.class, args);
}
}
registration-server.yml is:
---
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 file is:
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 [email protected]</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>
Both instance of eureka i.e. server-1 and server-2 are running fine. but they are not registering each other.