华企号 软件设计 redis集群构建技术方法

redis集群构建技术方法

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”

 

作者: 华企网通李铁牛程序员

我是程序员李铁牛,热爱互联网软件开发和设计,专注于大数据、数据分析、数据库、php、java、python、scala、k8s、docker等知识总结。15889726201 我的座右铭:"业精于勤荒于嬉,行成于思毁于随"
上一篇
下一篇

发表回复

联系我们

联系我们

028-84868647

在线咨询: QQ交谈

邮箱: tech@68v8.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部