Linux-7.7下基於最新版Redis-5.0.5集羣環境搭建與配置詳細教程

概述

一兩撥千斤,項目環境中某個環節爲了安全性的需要,因爲項目環境也是一個生態鏈嘛,所以就進行了所有的升級,其中涉及到Redis版本升級。

在上一篇文章中【CentOs7搭建基於Redis-4.0.2的集羣環境之圖文詳解】已經對Redis進行了一些基本的詳細的介紹,但是是基於Redis4.x的版本進行的,今年,Redis又進行了一次革命性版本變革,升級到了Redis-5.x版本,在本文章一些基本的概念就不再重複的闡述,本文主要結合官方文檔以更加主觀的方式來介紹Redis-5.x的一些更本性的變化,以及如何正確快捷的基於最新的Redis-5.x搭建一個Redis集羣環境。

 

官網文檔:https://redis.io/documentation

關於 Redis 集羣數據分片:

 

 

 

在官文中得出結論,當前Redis-5.x新版本構建集羣使用Redis的客戶端工具“ redis-cli ” 進行的,而Redis-4.x及Redis-3.x使用的 “ redis-trib ” 連接器進行構建的,語法如下:

redis-cli --cluster SUBCOMMAND [ARGUMENTS] [OPTIONS]

如果想構建一個基於Redis-5.x的集羣環境,請繼續往下看》》》

 

Linux-7.7下基於最新版Redis-5.0.5集羣環境搭建與配置

 

如果還是使用以前的方式的話,就不行了:

具體信息如下:

[root@localhost redis_cluster]# ./redis-trib.rb create --replicas 1 192.168.159.129:9001 192.168.159.129:9002 192.168.159.129:9003 192.168.159.129:9004 192.168.159.129:9005  192.168.159.129:9006
WARNING: redis-trib.rb is not longer available!
You should use redis-cli instead.

All commands and features belonging to redis-trib.rb have been moved
to redis-cli.
In order to use them you should call redis-cli with the --cluster
option followed by the subcommand name, arguments and options.

Use the following syntax:
redis-cli --cluster SUBCOMMAND [ARGUMENTS] [OPTIONS]

Example:
redis-cli --cluster create 192.168.159.129:9001 192.168.159.129:9002 192.168.159.129:9003 192.168.159.129:9004 192.168.159.129:9005 192.168.159.129:9006 --cluster-replicas 1

To get help about all subcommands, type:
redis-cli --cluster help

 

所以必須使用Redis的腳本工具 “ redis-cli ” 進行創建

輸入命令 “ ./redis-cli --cluster create 192.168.159.129:9001 192.168.159.129:9002 192.168.159.129:9003 192.168.159.129:9004 192.168.159.129:9005 192.168.159.129:9006 --cluster-replicas 1 ”

如果還不知道怎麼準備的,請參看【CentOs7搭建基於Redis-4.0.2的集羣環境之圖文詳解

創建內容如下:

[root@localhost redis_001]# ./redis-cli --cluster create 192.168.159.129:9001 192.168.159.129:9002 192.168.159.129:9003 192.168.159.129:9004 192.168.159.129:9005 192.168.159.129:9006 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.159.129:9005 to 192.168.159.129:9001
Adding replica 192.168.159.129:9006 to 192.168.159.129:9002
Adding replica 192.168.159.129:9004 to 192.168.159.129:9003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 6298907d9f4facfdc6b68e985013d80a5344a2da 192.168.159.129:9001
   slots:[0-5460] (5461 slots) master
M: 6d484bad6d77a8f7bf350a475471f11f79f0338a 192.168.159.129:9002
   slots:[5461-10922] (5462 slots) master
M: 88dff0c3f9705cb03797c1ebf933e1a184b5bb5d 192.168.159.129:9003
   slots:[10923-16383] (5461 slots) master
S: 0e5dbfa0b083c0246a28781cb8c891fe882014c3 192.168.159.129:9004
   replicates 6298907d9f4facfdc6b68e985013d80a5344a2da
S: b2e4faa325739badb7b272c15ead7b4321aa05d3 192.168.159.129:9005
   replicates 6d484bad6d77a8f7bf350a475471f11f79f0338a
S: d2c554a34412e6767f1d512c8db03fdd81067f4e 192.168.159.129:9006
   replicates 88dff0c3f9705cb03797c1ebf933e1a184b5bb5d
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
....
>>> Performing Cluster Check (using node 192.168.159.129:9001)
M: 6298907d9f4facfdc6b68e985013d80a5344a2da 192.168.159.129:9001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: b2e4faa325739badb7b272c15ead7b4321aa05d3 192.168.159.129:9005
   slots: (0 slots) slave
   replicates 6d484bad6d77a8f7bf350a475471f11f79f0338a
M: 6d484bad6d77a8f7bf350a475471f11f79f0338a 192.168.159.129:9002
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 0e5dbfa0b083c0246a28781cb8c891fe882014c3 192.168.159.129:9004
   slots: (0 slots) slave
   replicates 6298907d9f4facfdc6b68e985013d80a5344a2da
S: d2c554a34412e6767f1d512c8db03fdd81067f4e 192.168.159.129:9006
   slots: (0 slots) slave
   replicates 88dff0c3f9705cb03797c1ebf933e1a184b5bb5d
M: 88dff0c3f9705cb03797c1ebf933e1a184b5bb5d 192.168.159.129:9003
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

hash-slots的分配如下:

【圖1】

 

【圖2】

 

 

 


 好了,關於 Linux-7.7下基於最新版Redis-5.0.5集羣環境搭建與配置詳細教程 就寫到這兒了,如果還有什麼疑問或遇到什麼問題歡迎掃碼提問,也可以給我留言哦,我會一一詳細的解答的。 
歇後語:“ 共同學習,共同進步 ”,也希望大家多多關注CSND的IT社區。


作       者: 華    仔
聯繫作者: [email protected]
來        源: CSDN (Chinese Software Developer Network)
原        文: https://blog.csdn.net/Hello_World_QWP/article/details/102820018
版權聲明: 本文爲博主原創文章,請在轉載時務必註明博文出處!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章