最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Redis集群擴(kuò)容的實(shí)現(xiàn)示例

 更新時(shí)間:2025年02月27日 11:32:58   作者:元?dú)鉂M滿的熱碼式  
本文介紹了在虛擬機(jī)上新建Redis集群,并將新增節(jié)點(diǎn)加入現(xiàn)有集群,通過配置文件和`redis-cli`命令,成功實(shí)現(xiàn)了Redis集群的擴(kuò)容,感興趣的可以了解一下

在虛擬機(jī)上新建兩個(gè)6387,6388服務(wù)配置文件,新建之后啟動(dòng)

[root@redis-cluster1 cluster]# cat redisCluster6387.conf 
bind 0.0.0.0
daemonize yes
protected-mode no
logfile "/myredis/cluster/cluster6387.log"
pidfile /myredis/cluster6387.pid
dir /myredis/cluster
dbfilename dump6387.rdb
appendonly yes
appendfilename "appendonly6387.aof"
requirepass 111111
masterauth 111111
port 6387
cluster-enabled yes
cluster-config-file nodes-6387.conf
cluster-node-timeout 5000

[root@redis-cluster1 cluster]# cat redisCluster6388.conf 
bind 0.0.0.0
daemonize yes
protected-mode no
logfile "/myredis/cluster/cluster6388.log"
pidfile /myredis/cluster6388.pid
dir /myredis/cluster
dbfilename dump6388.rdb
appendonly yes
appendfilename "appendonly6388.aof"
requirepass 111111
masterauth 111111
port 6388
cluster-enabled yes
cluster-config-file nodes-6388.conf
cluster-node-timeout 5000

啟動(dòng)87,88兩個(gè)服務(wù),此時(shí)他們都是master,沒有加入集群

[root@redis-cluster1 cluster]# redis-server redisCluster6387.conf 
[root@redis-cluster1 cluster]# redis-server redisCluster6388.conf 
[root@redis-cluster1 cluster]# ps -ef | grep redis
root        2038       1  0 15:31 ?        00:00:31 redis-server 0.0.0.0:6386 [cluster]
root        2221       1  0 15:47 ?        00:00:24 redis-server 0.0.0.0:6385 [cluster]
root        2327    1753  0 16:01 pts/0    00:00:00 redis-cli -a 111111 -p 6385
root        2472       1  0 16:44 ?        00:00:00 redis-server 0.0.0.0:6387 [cluster]
root        2479       1  0 16:44 ?        00:00:00 redis-server 0.0.0.0:6388 [cluster]
root        2486    1954  0 16:44 pts/1    00:00:00 grep --color=auto redis
[root@redis-cluster1 cluster]# redis-cli -a 111111 -p 6387
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6387> 
127.0.0.1:6387> 
127.0.0.1:6387> cluster nodes
494e60980fac86000312e544f71c0e835bc1445b :6387@16387 myself,master - 0 0 0 connected
127.0.0.1:6387> 

將新增的6387節(jié)點(diǎn)作為master加入原集群

將新增的6387作為master節(jié)點(diǎn)加入原有集群
redis-cli -a 密碼 --cluster add-node,自己實(shí)際IP地址:6387 自己實(shí)際IP地址:6381
6387 就是將要作為master新增節(jié)點(diǎn)
6381 就是原來集群節(jié)點(diǎn)里面的領(lǐng)路人,相當(dāng)于6387拜拜6381的碼頭從而找到組織加入集群redis-cli -a 111111 --cluster add-node 192.168.111.174:6387 192.168.111.175:6381

[root@redis-cluster1 cluster]# redis-cli -a 111111  --cluster add-node 192.168.58.212:6387 192.168.58.129:6381
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 192.168.58.212:6387 to cluster 192.168.58.129:6381
>>> Performing Cluster Check (using node 192.168.58.129:6381)
M: ba40235fdad71fb36c3bf165ea51055825d453c2 192.168.58.129:6381
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: fedf4b13be2122f44dde749a08c4b943582b3566 192.168.58.129:6382
   slots: (0 slots) slave
   replicates be191621d4aa881d864a113c385d58b751753392
S: 91cf395e8f04a5df1aeec4602dd38b3e4a708d55 192.168.58.130:6384
   slots: (0 slots) slave
   replicates ba40235fdad71fb36c3bf165ea51055825d453c2
M: 0a820807a70885c1d87d141824d3869dcf2418ee 192.168.58.130:6383
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: be191621d4aa881d864a113c385d58b751753392 192.168.58.212:6385
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 30e5bdec200a671e4de666551d4489f0035235ba 192.168.58.212:6386
   slots: (0 slots) slave
   replicates 0a820807a70885c1d87d141824d3869dcf2418ee
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Getting functions from cluster
>>> Send FUNCTION LIST to 192.168.58.212:6387 to verify there is no functions in it
>>> Send FUNCTION RESTORE to 192.168.58.212:6387
>>> Send CLUSTER MEET to node 192.168.58.212:6387 to make it join the cluster.
[OK] New node added correctly.

第一次檢查集群狀態(tài):

6387還沒有被分配槽位

[root@redis-cluster1 cluster]# redis-cli -a 111111 --cluster check 192.168.58.129:6381
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.58.129:6381 (ba40235f...) -> 0 keys | 5461 slots | 1 slaves.
192.168.58.130:6383 (0a820807...) -> 0 keys | 5462 slots | 1 slaves.
192.168.58.212:6385 (be191621...) -> 0 keys | 5461 slots | 1 slaves.
192.168.58.212:6387 (494e6098...) -> 0 keys | 0 slots | 0 slaves.
[OK] 0 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.58.129:6381)
M: ba40235fdad71fb36c3bf165ea51055825d453c2 192.168.58.129:6381
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: fedf4b13be2122f44dde749a08c4b943582b3566 192.168.58.129:6382
   slots: (0 slots) slave
   replicates be191621d4aa881d864a113c385d58b751753392
S: 91cf395e8f04a5df1aeec4602dd38b3e4a708d55 192.168.58.130:6384
   slots: (0 slots) slave
   replicates ba40235fdad71fb36c3bf165ea51055825d453c2
M: 0a820807a70885c1d87d141824d3869dcf2418ee 192.168.58.130:6383
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: be191621d4aa881d864a113c385d58b751753392 192.168.58.212:6385
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 30e5bdec200a671e4de666551d4489f0035235ba 192.168.58.212:6386
   slots: (0 slots) slave
   replicates 0a820807a70885c1d87d141824d3869dcf2418ee
M: 494e60980fac86000312e544f71c0e835bc1445b 192.168.58.212:6387
   slots: (0 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

重新分配槽號(hào)

16384處于4,因?yàn)楝F(xiàn)在有四個(gè)主機(jī);

填寫6387的id號(hào);

[root@redis-cluster1 cluster]# redis-cli -a 111111 --cluster reshard 192.168.58.129:6381
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 192.168.58.129:6381)
M: ba40235fdad71fb36c3bf165ea51055825d453c2 192.168.58.129:6381
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: fedf4b13be2122f44dde749a08c4b943582b3566 192.168.58.129:6382
   slots: (0 slots) slave
   replicates be191621d4aa881d864a113c385d58b751753392
S: 91cf395e8f04a5df1aeec4602dd38b3e4a708d55 192.168.58.130:6384
   slots: (0 slots) slave
   replicates ba40235fdad71fb36c3bf165ea51055825d453c2
M: 0a820807a70885c1d87d141824d3869dcf2418ee 192.168.58.130:6383
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: be191621d4aa881d864a113c385d58b751753392 192.168.58.212:6385
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 30e5bdec200a671e4de666551d4489f0035235ba 192.168.58.212:6386
   slots: (0 slots) slave
   replicates 0a820807a70885c1d87d141824d3869dcf2418ee
M: 494e60980fac86000312e544f71c0e835bc1445b 192.168.58.212:6387
   slots: (0 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID? 494e60980fac86000312e544f71c0e835bc1445b
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
Source node #1: all

Ready to move 4096 slots.
  Source nodes:
    M: ba40235fdad71fb36c3bf165ea51055825d453c2 192.168.58.129:6381
       slots:[0-5460] (5461 slots) master
       1 additional replica(s)
    M: 0a820807a70885c1d87d141824d3869dcf2418ee 192.168.58.130:6383
       slots:[5461-10922] (5462 slots) master
       1 additional replica(s)
    M: be191621d4aa881d864a113c385d58b751753392 192.168.58.212:6385
       slots:[10923-16383] (5461 slots) master
       1 additional replica(s)
  Destination node:
    M: 494e60980fac86000312e544f71c0e835bc1445b 192.168.58.212:6387
       slots: (0 slots) master
  Resharding plan:

再次查看集群狀態(tài)

四個(gè)主節(jié)點(diǎn)均已被分配槽位;

當(dāng)前狀態(tài)為三主三從,一主零從

[root@redis-cluster1 cluster]# redis-cli -a 111111 --cluster check 192.168.58.129:6381
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.58.129:6381 (ba40235f...) -> 0 keys | 4096 slots | 1 slaves.
192.168.58.130:6383 (0a820807...) -> 0 keys | 4096 slots | 1 slaves.
192.168.58.212:6385 (be191621...) -> 0 keys | 4096 slots | 1 slaves.
192.168.58.212:6387 (494e6098...) -> 0 keys | 4096 slots | 0 slaves.
[OK] 0 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.58.129:6381)
M: ba40235fdad71fb36c3bf165ea51055825d453c2 192.168.58.129:6381
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
S: fedf4b13be2122f44dde749a08c4b943582b3566 192.168.58.129:6382
   slots: (0 slots) slave
   replicates be191621d4aa881d864a113c385d58b751753392
S: 91cf395e8f04a5df1aeec4602dd38b3e4a708d55 192.168.58.130:6384
   slots: (0 slots) slave
   replicates ba40235fdad71fb36c3bf165ea51055825d453c2
M: 0a820807a70885c1d87d141824d3869dcf2418ee 192.168.58.130:6383
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
M: be191621d4aa881d864a113c385d58b751753392 192.168.58.212:6385
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 30e5bdec200a671e4de666551d4489f0035235ba 192.168.58.212:6386
   slots: (0 slots) slave
   replicates 0a820807a70885c1d87d141824d3869dcf2418ee
M: 494e60980fac86000312e544f71c0e835bc1445b 192.168.58.212:6387
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

 為主節(jié)點(diǎn)87分配從節(jié)點(diǎn)88

[root@redis-cluster1 cluster]# redis-cli  -a 111111 --cluster add-node 192.168.58.212:6388 192.168.58.212:6387 --cluster-slave --cluster-master-id 494e60980fac86000312e544f71c0e835bc1445b 

--cluster-master-id 494e60980fac86000312e544f71c0e835bc1445b :主節(jié)點(diǎn)id號(hào)

再次查看當(dāng)前的集群狀態(tài):

127.0.0.1:6385> cluster nodes
0a820807a70885c1d87d141824d3869dcf2418ee 192.168.58.130:6383@16383 master - 0 1733303488000 3 connected 6827-10922
91cf395e8f04a5df1aeec4602dd38b3e4a708d55 192.168.58.130:6384@16384 slave ba40235fdad71fb36c3bf165ea51055825d453c2 0 1733303487073 1 connected
be191621d4aa881d864a113c385d58b751753392 192.168.58.212:6385@16385 myself,master - 0 0 8 connected 12288-16383
30e5bdec200a671e4de666551d4489f0035235ba 192.168.58.212:6386@16386 slave 0a820807a70885c1d87d141824d3869dcf2418ee 0 1733303488559 3 connected
ba40235fdad71fb36c3bf165ea51055825d453c2 192.168.58.129:6381@16381 master - 0 1733303488000 1 connected 1365-5460
c26c4f5ec9882083544326df9249fa48e35c6a2a 192.168.58.212:6388@16388 slave 494e60980fac86000312e544f71c0e835bc1445b 0 1733303488345 9 connected
494e60980fac86000312e544f71c0e835bc1445b 192.168.58.212:6387@16387 master - 0 1733303488675 9 connected 0-1364 5461-6826 10923-12287
fedf4b13be2122f44dde749a08c4b943582b3566 192.168.58.129:6382@16382 slave be191621d4aa881d864a113c385d58b751753392 0 1733303488106 8 connected
127.0.0.1:6385> 

四主四從,集群擴(kuò)容完成!

[root@redis-cluster1 cluster]# redis-cli -a 111111 --cluster check 192.168.58.129:6381
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.58.129:6381 (ba40235f...) -> 0 keys | 4096 slots | 1 slaves.
192.168.58.212:6387 (494e6098...) -> 0 keys | 4096 slots | 1 slaves.
192.168.58.130:6383 (0a820807...) -> 0 keys | 4096 slots | 1 slaves.
192.168.58.212:6385 (be191621...) -> 0 keys | 4096 slots | 1 slaves.
[OK] 0 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.58.129:6381)
M: ba40235fdad71fb36c3bf165ea51055825d453c2 192.168.58.129:6381
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
S: 30e5bdec200a671e4de666551d4489f0035235ba 192.168.58.212:6386
   slots: (0 slots) slave
   replicates 0a820807a70885c1d87d141824d3869dcf2418ee
M: 494e60980fac86000312e544f71c0e835bc1445b 192.168.58.212:6387
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
   1 additional replica(s)
S: fedf4b13be2122f44dde749a08c4b943582b3566 192.168.58.129:6382
   slots: (0 slots) slave
   replicates be191621d4aa881d864a113c385d58b751753392
M: 0a820807a70885c1d87d141824d3869dcf2418ee 192.168.58.130:6383
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: 91cf395e8f04a5df1aeec4602dd38b3e4a708d55 192.168.58.130:6384
   slots: (0 slots) slave
   replicates ba40235fdad71fb36c3bf165ea51055825d453c2
M: be191621d4aa881d864a113c385d58b751753392 192.168.58.212:6385
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: c26c4f5ec9882083544326df9249fa48e35c6a2a 192.168.58.212:6388
   slots: (0 slots) slave
   replicates 494e60980fac86000312e544f71c0e835bc1445b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

到此這篇關(guān)于Redis集群擴(kuò)容的實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)Redis集群擴(kuò)容內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Redission實(shí)現(xiàn)分布式鎖lock()和tryLock()方法的區(qū)別小結(jié)

    Redission實(shí)現(xiàn)分布式鎖lock()和tryLock()方法的區(qū)別小結(jié)

    Redisson是一種基于Redis的分布式鎖框架,提供了lock()和tryLock()兩種獲取鎖的方法,本文主要介紹了Redission實(shí)現(xiàn)分布式鎖lock()和tryLock()方法的區(qū)別小結(jié),具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-07-07
  • Redis使用ZSET實(shí)現(xiàn)消息隊(duì)列的項(xiàng)目實(shí)踐

    Redis使用ZSET實(shí)現(xiàn)消息隊(duì)列的項(xiàng)目實(shí)踐

    本文主要介紹了Redis使用ZSET實(shí)現(xiàn)消息隊(duì)列的項(xiàng)目實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07
  • redis如何實(shí)現(xiàn)保存對(duì)象

    redis如何實(shí)現(xiàn)保存對(duì)象

    這篇文章主要介紹了redis如何實(shí)現(xiàn)保存對(duì)象,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • redis的bigkey掃描腳本深入介紹

    redis的bigkey掃描腳本深入介紹

    這篇文章主要給大家介紹了關(guān)于redis的bigkey掃描腳本的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07
  • Redis 底層運(yùn)行機(jī)制與原理流程分析

    Redis 底層運(yùn)行機(jī)制與原理流程分析

    Redis是一個(gè)基于內(nèi)存的鍵值存儲(chǔ)系統(tǒng),采用單線程事件驅(qū)動(dòng)架構(gòu)和epoll/kqueue實(shí)現(xiàn)I/O多路復(fù)用,本文給大家介紹Redis 底層運(yùn)行機(jī)制與原理流程分析,感興趣的朋友一起看看吧
    2025-11-11
  • Redis持久化策略解讀以及如何選擇

    Redis持久化策略解讀以及如何選擇

    這篇文章主要介紹了Redis持久化策略解讀以及如何選擇問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-06-06
  • Redis集群部署的過程詳解

    Redis集群部署的過程詳解

    Redis集群是Redis官方推出的分布式解決方案,它允許將數(shù)據(jù)分布在多個(gè)Redis節(jié)點(diǎn)中,從而提高Redis的性能和可擴(kuò)展性,本文給大家介紹了Redis集群部署的過程步驟,需要的朋友可以參考下
    2024-06-06
  • 詳解Redis分布式鎖的原理與實(shí)現(xiàn)

    詳解Redis分布式鎖的原理與實(shí)現(xiàn)

    在單體應(yīng)用中,如果我們對(duì)共享數(shù)據(jù)不進(jìn)行加鎖操作,會(huì)出現(xiàn)數(shù)據(jù)一致性問題,我們的解決辦法通常是加鎖。下面我們一起聊聊使用redis來實(shí)現(xiàn)分布式鎖
    2022-06-06
  • Redis高并發(fā)緩存設(shè)計(jì)問題與性能優(yōu)化

    Redis高并發(fā)緩存設(shè)計(jì)問題與性能優(yōu)化

    本文詳細(xì)介紹了Redis緩存設(shè)計(jì)中常見的問題及解決方案,包括緩存穿透、緩存失效(擊穿)、緩存雪崩、熱點(diǎn)緩存key重建優(yōu)化、緩存與數(shù)據(jù)庫雙寫不一致以及開發(fā)規(guī)范與性能優(yōu)化,感興趣的可以了解一下
    2024-11-11
  • redis中如何做到內(nèi)存優(yōu)化

    redis中如何做到內(nèi)存優(yōu)化

    為了提高數(shù)據(jù)處理效率和降低存儲(chǔ)成本,優(yōu)化數(shù)據(jù)結(jié)構(gòu)和采用高效的存儲(chǔ)策略至關(guān)重要,使用最小存儲(chǔ)形式、整數(shù)編碼、Redis的HyperLogLog等方法可以有效減少內(nèi)存占用,Redis6引入的對(duì)象壓縮、設(shè)置合理的過期時(shí)間、數(shù)據(jù)分片
    2024-09-09

最新評(píng)論

临泽县| 揭阳市| 涞水县| 通化县| 收藏| 屏南县| 怀柔区| 黄石市| 旬阳县| 中牟县| 泗水县| 永修县| 隆尧县| 疏附县| 印江| 旬阳县| 兴山县| 太仓市| 大竹县| 新民市| 湖北省| 四会市| 巨鹿县| 龙口市| 桓仁| 政和县| 青州市| 娄烦县| 蚌埠市| 津市市| 广元市| 屏边| 锡林郭勒盟| 微山县| 彝良县| 射洪县| 天津市| 宽城| 龙江县| 淮安市| 南京市|