SpringCloud Eureka Server 注册中心集群
本文以Windows环境下的三个实例作为三个节点说明注册中心配置
1.因为我们三个实例实际上是在同一个机器上所以我们的三个注册中心ip相同端口不同,这种配置模式有些类似zookeeper伪集群模式。
因此需要修改需要改变hosts,linux系统通过vim /etc/hosts ,加上:
hosts 文件路径 C:\Windows\System32\drivers\etc
添加信息如下:
127.0.0.1 peer1
127.0.0.1 peer2
127.0.0.1 peer3
peer1-peer3分别代表三个节点实例
2.注册中心配置文件列表如下
application.yml
spring: profiles: active: peer1
application-peer1.yml
server: port: 8761 eureka: instance: hostname: peer1 client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://peer2:8769/eureka/,http://peer3:8869/eureka/
application-peer2.yml
server: port: 8769 eureka: instance: hostname: peer2 client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://peer3:8869/eureka/,http://peer1:8761/eureka/ application-peer3.yml
server: port: 8869 eureka: instance: hostname: peer3 client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://peer2:8769/eureka/,http://peer1:8761/eureka/
配置规则为
peer1注册到peer2和peer3
peer2注册到peer1和peer3
peer3注册到peer1和peer2
我们修改application.yml文件中的active 值以此启动三个实例节点点
然后将一个服务注册到任意一个几点效果如下:
节点peer1
节点peer2
节点peer3
从结果中我们可以看到服务注册到了单个节点中。
发文目的主要是看到许多例子都是连个节点为例,因此想到三个节点或者更多的节点应该怎么配置,仅供参考,如有什么不对之处欢迎指正。
参考:http://blog.csdn.net/forezp/article/details/70183572