redis集群(redis + cluster + sentinel)

说明:本次实验主从关系如下:

c1 master — c2 slave M/S 1

c2 master — c3 slave M/S 2

c3 master — c1 slave M/S 3

# 说明:框内内容是编译安装ruby工具,以便能成功执行redis-trib.rb创建集群,;yum方式安装ruby可能版本较低!

[root@c1 ~]# wget https://rubygems.org/downloads/redis-4.0.0.gem

[root@c1 ~]# tar -xf ruby-2.5.1.tar.gz -C /usr/local/

[root@c1 /usr/local/ruby-2.5.1]# ./configure -prefix=/usr/local/ruby-2.5.1

[root@c1 /usr/local/ruby-2.5.1]# make && make install

[root@c1 ~]# ln -sv /usr/local/ruby-2.5.1/bin/gem /usr/bin/gem

[root@c1 ~]# ln -sv /usr/local/ruby-2.5.1/bin/ruby /usr/bin/ruby

# 在配置文件/usr/local/ruby-2.5.1/ext/openssl/Makefile和/usr/local/ruby-2.5.1/ext/zlib/Makefile中的定义变量处加上如下红色行,若存在相应变量的定义请注释;

srcdir = .

top_srcdir = ../..

topdir = /usr/local/ruby-2.5.1/include/ruby-2.5.0

[root@c1 /usr/local/ruby-2.5.1/ext/zlib]# ruby extconf.rb

[root@c1 /usr/local/ruby-2.5.1/ext/zlib]# make && make install

[root@c1 /usr/local/ruby-2.5.1/ext/openssl]# ruby extconf.rb

[root@c1 /usr/local/ruby-2.5.1/ext/openssl]# make && make install

[root@c1 ~]# gem install -l redis-4.0.0.gem

# 创建集群,格式:主 主 主 从 从 从

[root@c1 ~]# /usr/local/redis/src/redis-trib.rb create –replicas 1 192.168.10.11:7001 192.168.10.12:7001 192.168.10.13:7001 192.168.10.12:7002 192.168.10.13:7002 192.168.10.11:7002

>>> Creating cluster

>>> Performing hash slots allocation on 6 nodes…

Using 3 masters:

192.168.10.11:7001

192.168.10.12:7001

192.168.10.13:7001

Adding replica 192.168.10.12:7002 to 192.168.10.11:7001

Adding replica 192.168.10.13:7002 to 192.168.10.12:7001

Adding replica 192.168.10.11:7002 to 192.168.10.13:7001

M: 440541e2a3235205bf190336a1f37f127d18bf60 192.168.10.11:7001

slots:0-5460 (5461 slots) master

M: c588a93825de6e0e6730a8bbb072684619201803 192.168.10.12:7001

slots:5461-10922 (5462 slots) master

M: 9ba21cfda0fed2d9013103e934f199a247c378ef 192.168.10.13:7001

slots:10923-16383 (5461 slots) master

S: f07abd56170635aaad5166bd38af9f7267834ca7 192.168.10.12:7002

replicates 440541e2a3235205bf190336a1f37f127d18bf60

S: 1aa03c91fc62ac72aeccf349d040f32ae190120b 192.168.10.13:7002

replicates c588a93825de6e0e6730a8bbb072684619201803

S: ff7e453f9ad5d2db2c7867893700fec033767bd9 192.168.10.11:7002

replicates 9ba21cfda0fed2d9013103e934f199a247c378ef

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.10.11:7001)

M: 440541e2a3235205bf190336a1f37f127d18bf60 192.168.10.11:7001

slots:0-5460 (5461 slots) master

1 additional replica(s)

S: 1aa03c91fc62ac72aeccf349d040f32ae190120b 192.168.10.13:7002

slots: (0 slots) slave

replicates c588a93825de6e0e6730a8bbb072684619201803

S: ff7e453f9ad5d2db2c7867893700fec033767bd9 192.168.10.11:7002

slots: (0 slots) slave

replicates 9ba21cfda0fed2d9013103e934f199a247c378ef

M: 9ba21cfda0fed2d9013103e934f199a247c378ef 192.168.10.13:7001

slots:10923-16383 (5461 slots) master

1 additional replica(s)

M: c588a93825de6e0e6730a8bbb072684619201803 192.168.10.12:7001

slots:5461-10922 (5462 slots) master

1 additional replica(s)

S: f07abd56170635aaad5166bd38af9f7267834ca7 192.168.10.12:7002

slots: (0 slots) slave

replicates 440541e2a3235205bf190336a1f37f127d18bf60

[OK] All nodes agree about slots configuration.

>>> Check for open slots…

>>> Check slots coverage…

[OK] All 16384 slots covered.

# 查看节点信息

[root@c1 ~]# /usr/local/redis/bin/redis-cli -h 192.168.10.13 -p 7001

192.168.10.13:7001> cluster nodes

ff7e453f9ad5d2db2c7867893700fec033767bd9 192.168.10.11:7002@17002 slave 9ba21cfda0fed2d9013103e934f199a247c378ef 0 1527578162996 6 connected

1aa03c91fc62ac72aeccf349d040f32ae190120b 192.168.10.13:7002@17002 slave c588a93825de6e0e6730a8bbb072684619201803 0 1527578161483 5 connected

440541e2a3235205bf190336a1f37f127d18bf60 192.168.10.11:7001@17001 master – 0 1527578162000 1 connected 0-5460

f07abd56170635aaad5166bd38af9f7267834ca7 192.168.10.12:7002@17002 slave 440541e2a3235205bf190336a1f37f127d18bf60 0 1527578161000 4 connected

c588a93825de6e0e6730a8bbb072684619201803 192.168.10.12:7001@17001 master – 0 1527578162491 2 connected 5461-10922

9ba21cfda0fed2d9013103e934f199a247c378ef 192.168.10.13:7001@17001 myself,master – 0 1527578162000 3 connected 10923-16383

原文链接:https://blog.csdn.net/w_wensan/article/details/88063654

原创文章,作者:优速盾-小U,如若转载,请注明出处:https://www.cdnb.net/bbs/archives/16930

(0)
上一篇 2022年11月16日 22:45
下一篇 2022年11月16日 22:45

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

优速盾注册领取大礼包www.cdnb.net
/sitemap.xml