Spring Cloud Eureka Server集群Demo级搭建

将上篇随笔Spring Cloud Eureka服务Demo级搭建进行改造,改造成一个在本机的伪集群

1.修改hosts文件(windows10 hosts文件位置:C:\Windows\System32\drivers\etc),加入

127.0.0.1 peer1
127.0.0.1 peer2

2.修改eurekaserver工程中的application.yml文件为

spring:
  application:
    name: eurekaserver
---
server:
  port: 8761
spring:
  profiles: peer1
eureka:
  instance:
    hostname: peer1
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://peer2:8762/eureka/
---
server:
  port: 8762
spring:
  profiles: peer2
eureka:
  instance:
    hostname: peer2
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://peer1:8761/eureka/

 

3.打开eurekaserver的启动类

启动peer1:右键→Run As→Run Configuration...,向Arguments内加入--spring.profiles.active=peer1,Run

启动peer2:重复上述操作,将Arguments内参数改为 --spring.profiles.active=peer2,Run

 

 

 3.接下来启动eurekaclient

4.分别访问 http://localhost:8761http://localhost:8761,发现8761(peer1)中有peer2节点,8762(peer2)中有peer1节点,说明Eureka集群搭建成功

 

posted @ 2017-12-08 16:41  码界小小学生  阅读(3554)  评论(0编辑  收藏  举报