一、POM主要依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
二、YML
eureka.client.service-url.defaulZone 配置注册中心地址(多个以逗号分隔)
集群:相互注册 A->B,B->A
如果有三个及以上(B,C,D同样向除开自己的注册中心进行注册)
server:
port: 7002
eureka:
instance:
hostname: eureka7002.com
client:
service-url:
defaultZone: http://eureka7001.com:7001/eureka/
register-with-eureka: false
fetch-registry: false
server:
port: 7001
eureka:
instance:
hostname: eureka7001.com
client:
service-url:
defaultZone: http://eureka7002.com:7002/eureka/
register-with-eureka: false
fetch-registry: false
三、启动类
标注@EnableEurekaServer
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaServer7001 {
public static void main(String[] args) {
SpringApplication.run(EurekaServer7001.class,args);
}
}
四、测试
如以下效果则成功![在这里插入图片描述](https://img-blog.csdnimg.cn/20200617173414649.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDIxNjcwNg==,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/2020061717343175.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDIxNjcwNg==,size_16,color_FFFFFF,t_70)