搜尋
首頁後端開發Python教學redis集群搭建教學及遇到的問題處理

redis集群搭建教學及遇到的問題處理

Sep 07, 2017 am 10:11 AM
redis教學遇到

本文主要跟大家講訴的是如何搭建redis集群的方法以及在此過程中需要注意的問題,非常不錯,推薦給大家,有需要的小伙伴可以來參考下

這裡,在一個Linux虛擬機器上搭建6個節點的redis偽集群,思路很簡單,一台虛擬機器上開啟6個redis實例,每個redis實例都有自己的連接埠。這樣的話,相當於模擬出了6台機器了,然後在以這6個實例組成redis集群就可以了。

前提:redis已經安裝,目錄為/usr/local/redis-4.0.1 如不會,可以參考一下文章  windows下安裝redis    Linux下安裝redis

redis叢集是用的ruby腳本,所以要想執行該腳本,需要ruby環境。對應redis的源碼src目錄下的redis-trib.rb,redis-trib.rb是redis官方推出的管理redis集群的工具,是基於redis提供的集群命令封裝成簡單、便捷、實用的操作工具。 so

安裝ruby環境:

  1.yum install ruby​​

   

  2 .yum install ruby​​gems

   

  3.gem install redis

     〔 #  Centos預設支援ruby到2.0.0,redis需要最低是2.2.2。解決方法是先安裝rvm 再把ruby版本升級到2.3.3 

       1.

sudo yum install curl

  〠# install curl

  〠# install curl

  ##curl -L get.rvm.io | bash -s stable 

  3.

   source /usr/local/rvm/scripts/rvm

##  4.查看rvm庫中已知的ruby版本

    rvm list known

  5.安裝一個1by版本

#  5.安裝一個版本

    5. ##rvm install 2.3.3

  6.使用一個ruby版本

    

rvm use 2.3.3

#知版本

   

rvm remove 2.0.0 

  8.查看版本

#   

ruby --version

#   ruby --version

# #  9.再安裝redis

   

gem install redis

##   

gem install redis

卷redis-8001,redis-8002,redis-8003節點目錄,再把redis-conf分別複製到節點目錄下

  

#      分別修改節點下redis-conf文件,由於

      分別修改節點下redis-conf文件,由於

      分別修改節點下redis-conf文件,由於

     在一台機器(192.16819.129)上,因此每個實例應該有不同的連接埠;同時,每個實例顯然會有自己的存放資料的地方;開啟AOF模式;開啟叢集配置;開啟後台模式;

  

  開啟redis服務,看看是否能啟動。 ok沒問題。

  

  建立startall.sh腳本(提示permission denied說明權限不足,執行指令chmod 777 startall.sh修改權限)

#  

#  啟動startall.sh腳本

  

#  建立stopall.sh腳本

  

  1.   

  2. ##  建立叢集
  3.   接下來,我們要透過Ruby腳本來建立叢集了。
  4.   

      

  5.   可以看到redis-trib.rb具有以下功能:
  6. create :建立叢集
  7. check :檢查叢集
  8. info :查看叢集資訊
  9. fix :修正叢集
  10. ##reshard :線上遷移slot
  11. rebalance :平衡叢集節點slot數量
  12. add-node :將新節點加入叢集
  13. del-node :從叢集中刪除節點#############set-timeout :設定叢集節點間心跳連接的逾時時間##### #######call :在叢集全部節點上執行指令############import :將外部redis資料匯入叢集###

redis-trib.rb mainly has two classes: ClusterNode and RedisTrib. ClusterNode saves the information of each node, RedisTrib is the implementation of each function of redis-trib.rb

 

Note: It prompts at least 3 master cluster nodes. It was said that 6 are created before, but in actual operation I only created 3 nodes, so it can be concluded that when we create a redis cluster, we need at least three master nodes, and it should be an odd number, so, no Be lazy and create three more.

Special note: The key here is the optional replicas parameter. --replicas 2 means to allocate 2 slaves to each master. replicas means how many slaves are needed. It can be successfully created without filling in this parameter, so there are three masters. We will introduce the replicas parameter later

 

 

First of all, --replicas 1 1 actually represents a ratio, which is the number of master nodes/ The proportion of slave nodes. So think about it, when creating a cluster, which nodes are the master nodes? Which nodes are slave nodes? The answer is that the order of IP:PORT in the command will be followed, first 3 master nodes, then 3 slave nodes.

Secondly, pay attention to the concept of slot in the picture. For Redis cluster, slot is a place to store data, it is a slot. For each Master, there will be a slot range, but the Slave does not. In the Redis cluster, the Master can still read and write, while the Slave can only read. The writing of data is actually distributed and stored in slots, which is different from the previous master-slave mode of 1.X (Master/Slave data storage in master-slave mode is completely consistent), because 3 The data storage of each Master is different. This will be verified in subsequent essays.

以上是redis集群搭建教學及遇到的問題處理的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
可以在Python數組中存儲哪些數據類型?可以在Python數組中存儲哪些數據類型?Apr 27, 2025 am 12:11 AM

pythonlistscanStoryDatatepe,ArrayModulearRaysStoreOneType,and numpyArraySareSareAraysareSareAraysareSareComputations.1)列出sareversArversAtileButlessMemory-Felide.2)arraymoduleareareMogeMogeNareSaremogeNormogeNoreSoustAta.3)

如果您嘗試將錯誤的數據類型的值存儲在Python數組中,該怎麼辦?如果您嘗試將錯誤的數據類型的值存儲在Python數組中,該怎麼辦?Apr 27, 2025 am 12:10 AM

WhenyouattempttostoreavalueofthewrongdatatypeinaPythonarray,you'llencounteraTypeError.Thisisduetothearraymodule'sstricttypeenforcement,whichrequiresallelementstobeofthesametypeasspecifiedbythetypecode.Forperformancereasons,arraysaremoreefficientthanl

Python標準庫的哪一部分是:列表或數組?Python標準庫的哪一部分是:列表或數組?Apr 27, 2025 am 12:03 AM

pythonlistsarepartofthestAndArdLibrary,herilearRaysarenot.listsarebuilt-In,多功能,和Rused ForStoringCollections,而EasaraySaraySaraySaraysaraySaraySaraysaraySaraysarrayModuleandleandleandlesscommonlyusedDduetolimitedFunctionalityFunctionalityFunctionality。

您應該檢查腳本是否使用錯誤的Python版本執行?您應該檢查腳本是否使用錯誤的Python版本執行?Apr 27, 2025 am 12:01 AM

ThescriptisrunningwiththewrongPythonversionduetoincorrectdefaultinterpretersettings.Tofixthis:1)CheckthedefaultPythonversionusingpython--versionorpython3--version.2)Usevirtualenvironmentsbycreatingonewithpython3.9-mvenvmyenv,activatingit,andverifying

在Python陣列上可以執行哪些常見操作?在Python陣列上可以執行哪些常見操作?Apr 26, 2025 am 12:22 AM

Pythonarrayssupportvariousoperations:1)Slicingextractssubsets,2)Appending/Extendingaddselements,3)Insertingplaceselementsatspecificpositions,4)Removingdeleteselements,5)Sorting/Reversingchangesorder,and6)Listcomprehensionscreatenewlistsbasedonexistin

在哪些類型的應用程序中,Numpy數組常用?在哪些類型的應用程序中,Numpy數組常用?Apr 26, 2025 am 12:13 AM

NumPyarraysareessentialforapplicationsrequiringefficientnumericalcomputationsanddatamanipulation.Theyarecrucialindatascience,machinelearning,physics,engineering,andfinanceduetotheirabilitytohandlelarge-scaledataefficiently.Forexample,infinancialanaly

您什麼時候選擇在Python中的列表上使用數組?您什麼時候選擇在Python中的列表上使用數組?Apr 26, 2025 am 12:12 AM

useanArray.ArarayoveralistinpythonwhendeAlingwithHomoGeneData,performance-Caliticalcode,orinterfacingwithccode.1)同質性data:arraysSaveMemorywithTypedElements.2)績效code-performance-calitialcode-calliginal-clitical-clitical-calligation-Critical-Code:Arraysofferferbetterperbetterperperformanceformanceformancefornallancefornalumericalical.3)

所有列表操作是否由數組支持,反之亦然?為什麼或為什麼不呢?所有列表操作是否由數組支持,反之亦然?為什麼或為什麼不呢?Apr 26, 2025 am 12:05 AM

不,notalllistoperationsareSupportedByArrays,andviceversa.1)arraysdonotsupportdynamicoperationslikeappendorinsertwithoutresizing,wheremactsperformance.2)listssdonotguaranteeconecontanttanttanttanttanttanttanttanttanttimecomplecomecomplecomecomecomecomecomecomplecomectacccesslectaccesslecrectaccesslerikearraysodo。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能