日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring Data Redis:Sentinel的高可用性

發布時間:2023/12/3 javascript 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring Data Redis:Sentinel的高可用性 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.概述

為了使Redis具有高可用性,我們可以使用Spring Data Redis對Redis Sentinel的支持。 借助Sentinel,我們可以創建自動抵御某些故障的Redis部署。

Redis Sentinel還提供其他附帶任務,例如監視,通知,并充當客戶端的配置提供程序。

在較高級別,Sentinel的功能是:

  • 自動故障轉移 。 當主服務器無法正常工作時,Sentinel會為我們啟動故障轉移過程,將從服務器升級為主服務器。 此外,其他從屬服務器也被重新配置為使用新的主服務器,并且使用Redis服務器的應用程序將被告知要使用的新地址。
  • 配置源 。 故障轉移發生時,Sentinels將報告新地址。 這是因為Sentinel充當客戶端的授權來源。 客戶端進行服務發現時,它們會連接到Sentinels,以請求負責給定服務的當前Redis主服務器的地址。
  • 監控 。 Sentinel會定期檢查我們的主實例和從實例是否按預期工作。
  • 通知 。 可以將Sentinel配置為在Redis實例之一發生錯誤時通知各種目標。 這些目標包括其他應用程序,系統管理員或API。

2.如何運行前哨

自Redis 2.8起,Redis附帶了Sentinel的穩定版本。

啟動Sentinel非常容易。 當我們在上一篇文章中回顧Spring Data Redis(使用Spring Boot)時,我們在Mac上使用homebrew安裝了Redis。 此命令使我們可以在該安裝中運行Sentinel:

redis-sentinel /path/to/sentinel.conf

如果我們使用的是redis-sentinel可執行文件(或者如果有一個使用該名稱的符號鏈接到redis-server的可執行文件),那么我們也可以使用上述命令運行Sentinel。

另外,我們可以使用redis-server可執行文件并以Sentinel模式啟動它,如下所示:

redis-server /path/to/sentinel.conf --sentinel

3.部署Sentinel之前需要了解的關鍵概念

在部署到Sentinel之前,我們應該檢查的一些概念包括:

  • 我們至少需要三個Sentinel實例才能進行持久的Redis部署。
  • 我們應該將三個Sentinel實例放置在據信會獨立而不是一起失敗的計算機或虛擬機中。 例如,這可能意味著不同的可用區。
  • Redis使用異步復制,因此即使在使用Sentinel時,Redis也不能保證在故障期間會保持接收到的寫入。 但是,我們可以部署Sentinel來減少寫入丟失的時間。
  • 任何高可用性設置都必須定期進行測試,并且Sentinel不變。 我們需要在開發環境和生產環境中進行測試。 通過計劃和測試故障,我們可以限制故障。
  • 4. Spring數據中的配置

    當我們使用基于Sentinels的配置時,我們不會向Spring Data Redis提供Redis主機/端口信息。 相反,我們提供了主服務器的屬性和Sentinel URL列表。 每個Sentinel進程都有其自己的配置文件,該文件列出了主Redis服務器,例如:

    sentinel monitor themaster 127.0.0.1 6379 2 sentinel down-after-milliseconds themaster 60000 sentinel failover-timeout themaster 180000 sentinel parallel-syncs themaster 1

    一旦配置好了主服務器,從服務器和Sentinels,我們就需要在應用程序中更改spring數據redis配置,以與哨兵一起工作。

    4.1 Java配置

    可以使用Jedis和Lettuce來完成Java配置:

    /*** Jedis*/ @Bean public RedisConnectionFactory jedisConnectionFactory() {RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration().master("themaster").sentinel("127.0.0.1", 26579).sentinel("127.0.0.1", 26580);return new JedisConnectionFactory(sentinelConfig); }/*** Lettuce*/ @Bean public RedisConnectionFactory lettuceConnectionFactory() {RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration().master("themaster").sentinel("127.0.0.1", 26579).sentinel("127.0.0.1", 26580);return new LettuceConnectionFactory(sentinelConfig); }

    4.2屬性配置

    ProperySource (例如application.properties )可用于配置。 例如,如果我們使用本地主機:

    spring.redis.sentinel.master= themaster # Name of our Redis server. spring.redis.sentinel.nodes= localhost:26579, localhost:26580, localhost:26581 # Comma-separated list of host:port pairs.

    5.結論

    今天,我們回顧了如何通過使用Sentinel使用Redis實現高可用性,以及Spring Data Redis如何在Spring應用程序中支持這一點。 有關Sentinel的更多信息, Redis網站是一個很好的來源。

    在我的網站上,還有從Spring Data Redis和Spring Boot開始的信息以及有關Spring Framework的幾篇文章。

    翻譯自: https://www.javacodegeeks.com/2019/01/spring-data-redis-high-availability-sentinel.html

    總結

    以上是生活随笔為你收集整理的Spring Data Redis:Sentinel的高可用性的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。