集群节点数目:2
Maven依赖
<dependencies>
<!--Eureka server依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
双节点配置
#eureka server1服务端口
server:
port: 8761
spring:
application:
name: cloud-eureka-server # 应用名称,应用名称会在Eureka中作为服务名称
# eureka 客户端配置(和Server交互),Eureka Server 其实也是一个Client
eureka:
instance:
hostname: CloudEurekaServerA # 当前eureka实例的主机名
client:
service-url:
# 配置客户端所交互的Eureka Server的地址(Eureka Server集群中每一个Server其实相对于其它Server来说都是Client)
# 集群模式下,defaultZone应该指向其它Eureka Server,如果有更多其它Server实例,逗号拼接即可
defaultZone: http://CloudEurekaServerB:8762/eureka
register-with-eureka: true # 集群模式下可以改成true
fetch-registry: true # 集群模式下可以改成true
dashboard:
enabled: true
----------------------------------------------------------------------------
#eureka server2服务端口
server:
port: 8762
spring:
application:
name: cloud-eureka-server # 应用名称,应用名称会在Eureka中作为服务名称
# eureka 客户端配置(和Server交互),Eureka Server 其实也是一个Client
eureka:
instance:
hostname: CloudEurekaServerB # 当前eureka实例的主机名
client:
service-url: # 配置客户端所交互的Eureka Server的地址
defaultZone: http://CloudEurekaServerA:8761/eureka
register-with-eureka: true
fetch-registry: true
windows hosts文件ip别名配置
![](https://i-blog.csdnimg.cn/blog_migrate/5e95865352bc02e621ba9ed85281a1d1.png)
Main函数注解配置
![](https://i-blog.csdnimg.cn/blog_migrate/966d6730e07b09a8d61d97a7e4ffc90a.png)
![](https://i-blog.csdnimg.cn/blog_migrate/bb4977bc04392e7713186d85d22403a0.png)
项目启动后页面查看
![](https://i-blog.csdnimg.cn/blog_migrate/27d23926e01d8a2d08a46d6f23fbc146.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d7ca91e3e1bbcb87ca7f6fa113dc07ac.png)