您好,登錄后才能下訂單哦!
這篇文章主要介紹“Redis cluster集群需要至少多少個(gè)redis節(jié)點(diǎn)”,在日常操作中,相信很多人在Redis cluster集群需要至少多少個(gè)redis節(jié)點(diǎn)問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”Redis cluster集群需要至少多少個(gè)redis節(jié)點(diǎn)”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
##配置redis集群需要至少6個(gè)redis節(jié)點(diǎn)
集群至少3主3從才可以搭建,防止錯(cuò)亂我們?cè)趓edis 下建立一個(gè)文件夾cluster,里面復(fù)制6份配置文件,改名為redis1-redis6.conf
把每個(gè)配置文件都修改以下共同點(diǎn):
bind 10.233.19.36 (根據(jù)實(shí)際情況配置)
port 7001 (7001-7006)
daemonize yes(以守護(hù)進(jìn)程運(yùn)行)
pidfile /var/run/redis.pid (守護(hù)進(jìn)程生成的文件,以實(shí)際情況配置)
appendonly yes (開(kāi)啟AOF日志記錄Redis操作的持久化)
appendfilename "appendonly-7001.aof" (AOF文件名,配置端口為文件名便于查看)
cluster-enabled yes (開(kāi)啟集群)
cluster-config-file nodes-7001.conf (節(jié)點(diǎn)信息,已節(jié)點(diǎn)命名便于查看)
cluster-node-timeout 15000 (節(jié)點(diǎn)響應(yīng)超時(shí)時(shí)間)
以上為共同點(diǎn)每個(gè)節(jié)點(diǎn)不論主從都需要配置。
此外還需要注意,不要再為各個(gè)節(jié)點(diǎn)主動(dòng)配置主從關(guān)系,否則啟動(dòng)時(shí)會(huì)報(bào)錯(cuò)。
因?yàn)橹鲝年P(guān)系要給redis集群自己調(diào)節(jié)。
##啟動(dòng)redis集群
上面的配置完成之后,分別啟動(dòng)6個(gè)redis實(shí)例。配置正確的情況下,都可以啟動(dòng)成功。然后運(yùn)行如下命令創(chuàng)建集群:
注意,這里使用的是ip:port
replicas
1 表示我們希望為集群中的每個(gè)主節(jié)點(diǎn)創(chuàng)建一個(gè)從節(jié)點(diǎn)
因?yàn)榕渲梦募性O(shè)置了密碼所以創(chuàng)建集群也需要加密碼參數(shù) -a
[ERR] Node 10.233.19.36:6380 NOAUTH Authentication required.
[redis@weblogic-test bin]$ ./redis-cli --cluster create 10.233.19.36:6380 10.233.19.36:6381 10.233.19.36:6382 10.233.19.36:6383 10.233.19.36:6384 10.233.19.36:6385 --cluster-replicas 1 -a beijing
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 10.233.19.36:6383 to 10.233.19.36:6380
Adding replica 10.233.19.36:6384 to 10.233.19.36:6381
Adding replica 10.233.19.36:6385 to 10.233.19.36:6382
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 369151e4f1bed1e3fcaf474025853bc72056542e 10.233.19.36:6380
slots:[0-5460] (5461 slots) master
M: 1f9314f13a22c2c68c609e98247bfe6d0714c75b 10.233.19.36:6381
slots:[5461-10922] (5462 slots) master
M: 41840a493fceef875b1a521d951090f9c99c7040 10.233.19.36:6382
slots:[10923-16383] (5461 slots) master
S: 438c5ecaf7501da25bfc0d2055445c036907ba61 10.233.19.36:6383
replicates 1f9314f13a22c2c68c609e98247bfe6d0714c75b
S: 9598769e90155aeb130a33980ac1a1c27b1609cc 10.233.19.36:6384
replicates 41840a493fceef875b1a521d951090f9c99c7040
S: b0d325e936ee5055648561302560d055d0bdb365 10.233.19.36:6385
replicates 369151e4f1bed1e3fcaf474025853bc72056542e
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 10.233.19.36:6380)
M: 369151e4f1bed1e3fcaf474025853bc72056542e 10.233.19.36:6380
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: 1f9314f13a22c2c68c609e98247bfe6d0714c75b 10.233.19.36:6381
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 9598769e90155aeb130a33980ac1a1c27b1609cc 10.233.19.36:6384
slots: (0 slots) slave
replicates 41840a493fceef875b1a521d951090f9c99c7040
M: 41840a493fceef875b1a521d951090f9c99c7040 10.233.19.36:6382
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: b0d325e936ee5055648561302560d055d0bdb365 10.233.19.36:6385
slots: (0 slots) slave
replicates 369151e4f1bed1e3fcaf474025853bc72056542e
S: 438c5ecaf7501da25bfc0d2055445c036907ba61 10.233.19.36:6383
slots: (0 slots) slave
replicates 1f9314f13a22c2c68c609e98247bfe6d0714c75b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
執(zhí)行成功之后,連接一臺(tái)redis,執(zhí)行 cluster info 會(huì)看到類(lèi)似如下信息:
127.0.0.1:6380> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:190
cluster_stats_messages_pong_sent:181
cluster_stats_messages_sent:371
cluster_stats_messages_ping_received:176
cluster_stats_messages_pong_received:190
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:371
我們可以看到cluster_state:ok,cluster_slots_ok:16384,cluster_size:3。
到此,關(guān)于“Redis cluster集群需要至少多少個(gè)redis節(jié)點(diǎn)”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。