1、pom.xml
pom文件和之前的EurekaServer的一致
2、application.yml
spring.profiles:可以理解为给这一段配置起了个名字,在我们运行代码的时候,可以选择一段配置去启动
---
spring:
profiles: peer1
application:
name: peer1
eureka:
instance:
hostname: peer1
client:
serviceUrl:
defaultZone: http://peer2:8762/eureka/
server:
port: 8761
---
spring:
profiles: peer2
application:
name: peer2
eureka:
instance:
hostname: peer2
client:
serviceUrl:
defaultZone: http://peer1:8761/eureka/
server:
port: 8762
3、启动类添加注解并启动
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerTogetherApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerTogetherApplication.class, args);
}
}
4、启动时,配置
在此处配置你要用的配置
5、先启动的EurekaServer都会报错,属于正常现象,我们访问EurekaServer页面正常即为正常
第二次启动的EurekaServer不会报错
6、结果
DS Replicas代表本服务器从哪里同步数据