redis 叢集構建

babyyellow發表於2022-11-24



redis叢集: 





[root@yt2-db-test-vm16-124-10 data_6379]# redis-cli   --cluster  create  --cluster-replicas 1 10.16.124.10:6379 10.16.124.11:6378 10.16.124.11:6379 10.16.124.12:6378 10.16.124.12:6379 10.16.124.10:6378 

>>> 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.16.124.11:6379 to 10.16.124.10:6379

Adding replica 10.16.124.12:6379 to 10.16.124.11:6378

Adding replica 10.16.124.10:6378 to 10.16.124.12:6378

M: a373bfeafe4484fed9d88e06d4c34f9a8bcc7047 10.16.124.10:6379

   slots:[0-5460] (5461 slots) master

M: 62da0a5ad744251d6b2d2ce13fdc1ff611d30ddb 10.16.124.11:6378

   slots:[5461-10922] (5462 slots) master

S: 3a6960c7f781bdd342fcb90fb9fd65499e7bee57 10.16.124.11:6379

   replicates a373bfeafe4484fed9d88e06d4c34f9a8bcc7047

M: 366c2088f00aaff161a1abf5a831160ef26b8646 10.16.124.12:6378

   slots:[10923-16383] (5461 slots) master

S: 94f7df592c031a56dd0370dc04f0f9c564cbd423 10.16.124.12:6379

   replicates 62da0a5ad744251d6b2d2ce13fdc1ff611d30ddb

S: 31e19cc8bb5c0c8dfb8e78c735daa634e33644ad 10.16.124.10:6378

   replicates 366c2088f00aaff161a1abf5a831160ef26b8646

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.16.124.10:6379)

M: a373bfeafe4484fed9d88e06d4c34f9a8bcc7047 10.16.124.10:6379

   slots:[0-5460] (5461 slots) master

   1 additional replica(s)

M: 366c2088f00aaff161a1abf5a831160ef26b8646 10.16.124.12:6378

   slots:[10923-16383] (5461 slots) master

   1 additional replica(s)

S: 31e19cc8bb5c0c8dfb8e78c735daa634e33644ad 10.16.124.10:6378

   slots: (0 slots) slave

   replicates 366c2088f00aaff161a1abf5a831160ef26b8646

S: 3a6960c7f781bdd342fcb90fb9fd65499e7bee57 10.16.124.11:6379

   slots: (0 slots) slave

   replicates a373bfeafe4484fed9d88e06d4c34f9a8bcc7047

S: 94f7df592c031a56dd0370dc04f0f9c564cbd423 10.16.124.12:6379

   slots: (0 slots) slave

   replicates 62da0a5ad744251d6b2d2ce13fdc1ff611d30ddb

M: 62da0a5ad744251d6b2d2ce13fdc1ff611d30ddb 10.16.124.11:6378

   slots:[5461-10922] (5462 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.




127.0.0.1:6379> CLUSTER nodes

366c2088f00aaff161a1abf5a831160ef26b8646 10.16.124.12:6378@16378 master - 0 1669263296463 4 connected 10923-16383

31e19cc8bb5c0c8dfb8e78c735daa634e33644ad 10.16.124.10:6378@16378 slave 366c2088f00aaff161a1abf5a831160ef26b8646 0 1669263295000 4 connected

a373bfeafe4484fed9d88e06d4c34f9a8bcc7047 10.16.124.10:6379@16379 myself,master - 0 1669263295000 1 connected 0-5460

3a6960c7f781bdd342fcb90fb9fd65499e7bee57 10.16.124.11:6379@16379 slave a373bfeafe4484fed9d88e06d4c34f9a8bcc7047 0 1669263293453 1 connected

94f7df592c031a56dd0370dc04f0f9c564cbd423 10.16.124.12:6379@16379 slave 62da0a5ad744251d6b2d2ce13fdc1ff611d30ddb 0 1669263295460 2 connected

62da0a5ad744251d6b2d2ce13fdc1ff611d30ddb 10.16.124.11:6378@16378 master - 0 1669263294000 2 connected 5461-10922

127.0.0.1:6379> 


127.0.0.1:6379> 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:160

cluster_stats_messages_pong_sent:172

cluster_stats_messages_sent:332

cluster_stats_messages_ping_received:167

cluster_stats_messages_pong_received:160

cluster_stats_messages_meet_received:5

cluster_stats_messages_received:332


基本錯誤處理: 


127.0.0.1:6379> get mykey

(error) MOVED 14687 10.16.124.12:6378


這是因為 我們登入的本機不是啟用了叢集模式 


[root@yt2-db-test-vm16-124-10 data_6379]# redis-cli -c

127.0.0.1:6379> get mykey 

-> Redirected to slot [14687] located at 10.16.124.12:6378

"redis over"

 





來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/133735/viewspace-2924917/,如需轉載,請註明出處,否則將追究法律責任。

相關文章