spring cloud eureka集群,空白主页,available-replicas为空

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tangyaliang11/article/details/80333861

如果在一台机器上配置集群,那么请注意。

单工程多eureka(配置写在一个配置文件或多个配置文件)如以下代码(官网示例代码):

---
spring:
  profiles: peer1#官网这个配置为什么我用不好使,主页都打不开
eureka:
  instance:
    hostname: peer1
  client:
    serviceUrl:
      defaultZone: http://peer2/eureka/

---
spring:
  profiles: peer2
eureka:
  instance:
    hostname: peer2
  client:
    serviceUrl:
      defaultZone: http://peer1/eureka/

运行时一定要指定--spring.profiles.active=你的值,eclipse在run configureactions中配置。
或者使用命令java -jar 打包后的jar --spring.profiles.active=你的值。

主页available-replicas为空,请看看hostname项目有没有填写,尝试把配置项spring.profiles修改为spring.profiles.active。

贴下我的配置,我是分成两个项目做的:
peer1

spring:
  application:
    name: register
  profiles:
    active:
    - peer1
server:
  port: 8001
eureka:
  client:
    serviceUrl: 
      defaultZone: http://peer2:8002/eureka/
  instance:
    hostname: peer1


peer2

spring:
  application:
    name: register
  profiles:
    active:
    - peer2
server:
  port: 8002
eureka:
  client:
    serviceUrl:
      defaultZone: http://peer1:8001/eureka/
  instance:
    hostname: peer2


pom

         <parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.2.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
		<spring-cloud.version>Finchley.BUILD-SNAPSHOT</spring-cloud.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka-server</artifactId>
			<version>1.4.4.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</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>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

	<repositories>
		<repository>
			<id>spring-snapshots</id>
			<name>Spring Snapshots</name>
			<url>https://repo.spring.io/snapshot</url>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>
		<repository>
			<id>spring-milestones</id>
			<name>Spring Milestones</name>
			<url>https://repo.spring.io/milestone</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>

最后运行效果图



阅读更多

没有更多推荐了,返回首页