第一步:我们新建两个注册中心工程一个叫eureka_register_service_master、另外一个叫eureka_register_service_backup
eureka_register_service_master的application.properties配置 server.port=7998 eureka.client.register-with-eureka=false eureka.client.fetch-registry=false spring.application.name=eureka-server eureka.instance.hostname=master eureka.client.serviceUrl.defaultZone=http://backup:7999/eureka/
eureka_register_service_backup的application.properties配置如下 [Java] 纯文本查看 复制代码 server.port=7999
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
spring.application.name=eureka-server
eureka.instance.hostname=backup
#这里配置的是master的地址
eureka.client.serviceUrl.defaultZone=http://master:7998/eureka/
上面的配置端口分别是
master端口是7998 backupr端口是7999
由于我用的是同一台机器所以需要绑定下host 127.0.0.1 master 127.0.0.1 backup
第二步:添加启动文件分别是ApplicationMaster.java,ApplicationBackUp.java 里面代码内容是一样的 [Java] 纯文本查看 复制代码 @EnableEurekaServer
@SpringBootApplication
public class ApplicationMaster {
public static void main(String[] args) {
SpringApplication.run(ApplicationMaster.class, args);
}
}
@EnableEurekaServer
@SpringBootApplication
public class ApplicationBackUp {
public static void main(String[] args) {
SpringApplication.run(ApplicationBackUp.class, args);
}
}
|