加入依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>eurekaServer</module>
<module>eurekaServer-ha</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>lcl_hosted</id>
<url>http://localhost:8081/repository/lcl_hosted/</url>
</repository>
</distributionManagement>
启动类
package com.liu.fukua;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
配置
spring.application.name=eureka-server
server.port=8761
eureka.instance.hostname=eureka1
#设置服务注册中心地址,指向另一个注册中心
eureka.client.serviceUrl.defaultZone=http://user:123456@eureka2:8761/eureka/
# 安全认证
#开启基于http basic的安全认证
security.basic.enabled=true
security.user.name=user
security.user.password=123456
spring.application.name=eureka-server
server.port=8761
eureka.instance.hostname=eureka2
#设置服务注册中心地址,指向另一个注册中心
eureka.client.serviceUrl.defaultZone=http://user:123456@eureka1:8761/eureka/
# 安全认证
#开启基于http basic的安全认证
security.basic.enabled=true
security.user.name=user
security.user.password=123456
启动
java -jar eurekaServer-ha-0.0.1-SNAPSHOT.jar --spring.profiles.active=eureka2
java -jar eurekaServer-ha-0.0.1-SNAPSHOT.jar --spring.profiles.active=eureka1
效果

