springcloud之服务集群注册与发现 Eureka

[复制链接]
发表于 2026-1-7 23:38:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
前言
1:对于能提供完备范畴服务接口功能的RPC而言,比方;gRPC、Thrift、Dubbo等,服务的注册与发现都是焦点功能中非常紧张的一环,使得微服务得到同一管理。
2:在分布式范畴中有个闻名的CAP理论;同等性(Consistency)、可用性(Availability)、分区容错性(Partition tolerance),这三个要素在分布式体系中,最多满意两个,不大概三者分身。
3:通常我们在使用dubbo时zookeeper作为注册中央以选主设置为焦点,包管CP特性,即任何时间对 Zookeeper 的访问哀求能得到同等的数据结果,同时体系对网络分割具备容错性,但是它不能包管每次服务哀求的可用性。
4:而 Spring Cloud Netflix 在计划 Eureka 时服从的就是 AP 原则,由于对于服务发现而言,可用性比数据同等性显得尤为紧张。
案例阐明

案列使用版本如下
1:jdk 1.8
2:Spring Boot 2.0.6.RELEASE
3:Spring Cloud Finchley.SR2
新建应用启动类
EurekaServerApplication.java | 三组node代码同等,只须要一个平凡的springboot添加@EnableEurekaServer即可启动
  1. @SpringBootApplication
  2. @EnableEurekaServer
  3. public class EurekaServerApplication {
  4.     public static void main(String[] args) {
  5.         SpringApplication.run( EurekaServerApplication.class, args );
  6.     }
  7. }
复制代码
application.yml | node1 指向别的两台服务,registerWithEureka、fetchRegistry和单实例差异须要设置为true
  1. spring:
  2.   application:
  3.     name: demo-eureka-server
  4. server:
  5.   port: 8081
  6. eureka:
  7.   instance:
  8.     hostname: node01
  9.   client:
  10.     registerWithEureka: true
  11.     fetchRegistry: true
  12.     serviceUrl:
  13.       defaultZone: http://node02:8082/eureka/,http://node03:8083/eureka/
复制代码
application.yml | node2 指向别的两台服务
  1. spring:
  2.   application:
  3.     name: demo-eureka-server
  4. server:
  5.   port: 8082
  6. eureka:
  7.   instance:
  8.     hostname: node02
  9.   client:
  10.     registerWithEureka: true
  11.     fetchRegistry: true
  12.     serviceUrl:
  13.       defaultZone: http://node03:8083/eureka/,http://node01:8081/eureka/
复制代码
application.yml | node3 指向别的两台服务
  1. spring:
  2.   application:
  3.     name: demo-eureka-server
  4. server:
  5.   port: 8083
  6. eureka:
  7.   instance:
  8.     hostname: node03
  9.   client:
  10.     registerWithEureka: true
  11.     fetchRegistry: true
  12.     serviceUrl:
  13.       defaultZone: http://node01:8081/eureka/,http://node02:8082/eureka/
复制代码
测试验证
1:设置host;127.0.0.1 node01 node02 node03
2:分别启动node1、node2、node3
3:访问;http://localhost:8081/

好了到这里就竣事了一偏概述告诉你SpringCloud是什么的学习,各人肯定要跟着动手使用起来。须要源码的 可si我获取;
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表