【SpringCloud NetFlix】Eureka集群搭建

Eureka集群搭建

​ 为了突出Eureka的高可用性,对其进行集群部署

两个服务器实例、两个服务提供者实例

这里写图片描述

在本机的“C:\Windows\System32\drivers\etc”下的hosts文件中添加如下配置:

127.0.0.1 slave1 slave2

Eureka服务注册中心

server:
  port: 8761
spring:
  application:
    name: cloud-114
  profiles: slave1
eureka:
  client: 
    serviceUrl:
      defaultZone: http://slave2:8762/eureka
---
server:
  port: 8762
spring:
  application:
    name: cloud-114
  profiles: slave2
eureka:
  client: 
    serviceUrl:
      defaultZone: http://slave1:8761/eureka

Eureka注册中心启动类:

@SpringBootApplication
@EnableEurekaServer
public class ServerApp {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String profiles = scan.nextLine();
        new SpringApplicationBuilder(ServerApp.class).profiles(profiles).run(args);
    }

}

若idea不能对同一个程序启动多次,做如下配置:

这里写图片描述

分别启动Eureka

这里写图片描述

这里写图片描述

启动过程中会报如下错误,不用管:

2018-08-14 09:03:29.794 ERROR 13664 --- [           main] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
    at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]

启动成功效果图:

这里写图片描述

这里写图片描述

若服务注册中心不想注册自己,可以修改配置如下:

server:
  port: 8761
spring:
  application:
    name: cloud-114
  profiles: slave1
eureka:
  client:
    serviceUrl:
      defaultZone: http://slave2:8762/eureka
    register-with-eureka: false
    fetch-registry: false
---
server:
  port: 8762
spring:
  application:
    name: cloud-114
  profiles: slave2
eureka:
  client:
    serviceUrl:
      defaultZone: http://slave1:8761/eureka
    register-with-eureka: false
    fetch-registry: false

修改服务注册者配置,分别注册到两个服务注册中心:

spring:
  application:
    name: cloud-police
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/, http://localhost:8762/eureka/

修改服务调用者配置

server:
  port: 9000
spring:
  application:
    name: cloud-person
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/, http://localhost:8762/eureka/

以上为疯狂SpringCloud微服务架构实战学习笔记
感谢杨恩雄老师:https://my.oschina.net/JavaLaw

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

女汉纸一枚

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值