天天看點

SpringCloud學習筆記(一、初識)SpringCloud是什麼?分布式、叢集、微服務為什麼SpringCloud如此流行?

SpringCloud是什麼?

官方文檔這麼寫道:

Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems (e.g. configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, control bus, one-time tokens, global locks, leadership election, distributed sessions, cluster state). Coordination of distributed systems leads to boiler plate patterns, and using Spring Cloud developers can quickly stand up services and applications that implement those patterns. They will work well in any distributed environment, including the developer’s own laptop, bare metal data centres, and managed platforms such as Cloud Foundry.

翻譯一下:

Spring Cloud為開發人員提供了快速建構分布式系統中的一些常見模式的工具(例如配置管理、服務發現、斷路器、智能路由、微代理、控制總線、一次性令牌、全局鎖、上司層選舉、分布式會話、叢集狀态)。分布式系統的協調導緻了鍋爐闆模式,使用Spring Cloud開發人員可以快速建立實作這些模式的服務和應用程式。它們在任何分布式環境中都能很好地工作,包括開發人員自己的筆記本電腦、裸機資料中心和雲計算等托管平台。

SpringCloud是一套工具,是一系列架構的有序集合,SpringCloud 就是一套工具,幫助大家很容易地搭建出這麼一個叢集和分布式的架子出來

問題又來了,分布式和叢集又是什麼?

分布式、叢集、微服務

  • 分布式:一個業務分拆多個子業務,部署在不同的伺服器上
  • 叢集:同一個業務,部署在多個伺服器上
  • 微服務的意思也就是将子產品拆分成一個獨立的服務單元通過接口來實作資料的互動。

分布式是指将不同的業務分布在不同的地方。而叢集指的是将幾台伺服器集中在一起,實作同一業務。分布式中的每一個節點,都可以做叢集。而叢集并不一定就是分布式的。

分布式示意圖

SpringCloud學習筆記(一、初識)SpringCloud是什麼?分布式、叢集、微服務為什麼SpringCloud如此流行?

分布式,從窄意上了解,也跟叢集差不多,但是它的組織比較松散,不像叢集,有一個組織性,一台伺服器垮了,其它的伺服器可以頂上來.分布式的每一個節點,都完成不同的業務,一個節點垮了,那這個業務就不可通路了。好的設計應該是分布式和叢集的結合,先分布式再叢集,具體實作就是業務拆分成很多子業務,然後針對每個子業務進行叢集部署,這樣每個子業務如果出了問題,整個系統完全不會受影響。

高可用叢集示意圖

微服務的設計是為了不因為某個子產品的更新和BUG影響現有的系統業務。微服務與分布式的細微差别是,微服務的應用不一定是分散在多個伺服器上,他也可以是同一個伺服器。分布式和微服的架構很相似,隻是部署的方式不一樣而已。

SpringCloud特性

從官網我們可以看到,SpringCloud有以下特性和功能:

Spring Cloud focuses on providing good out of box experience for typical use cases and extensibility mechanism to cover others.

  • Distributed/versioned configuration
  • Service registration and discovery
  • Routing
  • Service-to-service calls
  • Load balancing
  • Circuit Breakers
  • Global locks
  • Leadership election and cluster state
  • Distributed messaging

Spring Cloud takes a very declarative approach, and often you get a lot of features with just a classpath change and/or an annotation.

Spring Cloud專注于為典型用例提供良好的開箱即用體驗,并提供擴充機制來覆寫其他用例。

  • 分布式/版本配置
  • 服務注冊及發現
  • 路由
  • service - to - service調用
  • 負載平衡
  • 斷路器
  • 全局鎖
  • 分布式消息

Spring Cloud采用了一種非常聲明性的方法,通常隻需更改類路徑和/或注釋就可以獲得很多特性。

為了實作這些特性和功能,SpringCloud有很多元件和子產品,主要如下:

• Eureka :服務注冊中心,用于服務管理

• Ribbon :基于用戶端的負載均衡元件

• Hystrix :容錯架構,能夠防止服務的 崩效應

• Feign: Web 服務用戶端,能夠簡 Http 接口的調用

• Zuul: API 網關 ,提供路由轉發、請求過濾等功能

• Config 分布式配置管理

• Sleuth :服務跟蹤

• Stream :建構消息驅動的微服務應用程式的架構

• Bus :消息代理的叢集消息總線。

為什麼SpringCloud如此流行?

  • 社群的支援:
    • 首先 Spring Cloud 有強大的社群支援,在 Java 生态圈必定離不開 Spring ,且

      Spring Cloud 的更新頻率也越來越高

  • 關注内容:
    • Spring Cloud 關注的是整個服務架構會涉及的方方面面,在 Spring Cloud 中各種

      元件應有盡有,進而使其具有可快速內建、友善 成本低等優勢

  • 性能問題
    • Spring Cloud 帶來的性能損耗對于大部分應用來說是可以接受的,而它具有的

      Http 風格的 API 互動,在不同的語言中是通用的,且對每個微服務的測試來說是

      非常友善的,也就是說 Spring Cloud 用小的性能損耗換來了更多好處 。

接下來通過實踐和學習來進一步認識SpringCloud。

參考:

【1】、

分布式和叢集 / SpringCloud / SpringCloud系列教材 (一)- 介紹

【2】、

springcloud(一):大話Spring Cloud

【3】、

Spring Cloud Hoxton SR6

【4】、

三分鐘讀懂TT貓分布式、微服務和叢集之路

【5】、

分布式-微服務-叢集 的概念和差別