redis-cluster集群搭建
young / / / 阅读量

前言

下图中描述的是六个redis实例构成的集群
集群内部划分为16384个数据分槽,分布在三个主redis中。
从redis中没有分槽,不会参与集群投票,也不会帮忙加快读取数据,仅仅作为主机的备份。
三个主节点中平均分布着16384数据分槽的三分之一,每个节点中不会存有有重复数据,仅仅有自己的从机帮忙冗余。


redis 官方提供了一个 redis-trib.rb (src目录下) 工具用于搭建集群。很明显是 ruby 写的,所以需要 ruby 环境。
redis安装链接地址

redis节点安装及配置

安装 ruby

yum -y install ruby ruby-devel rubygems rpm-build

用 gem 安装 redis 接口

[root@localhost /]# gem install redis
Fetching: redis-3.3.3.gem (100{5749fe182deba6f703e69800a8cc3afb9894ad400f350437bd2be724fa41f418})
Successfully installed redis-3.3.3
Parsing documentation for redis-3.3.3
Installing ri documentation for redis-3.3.3

我gem install redis时报错

redis requires Ruby version >= 2.2.2

解决办法:http://yangxx.net/?p=1533
gem installe安装时还可能会有一些问题如下:

问题1:
执行命令:./redis-trib.rb
/usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- redis (LoadError)
from /usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from ./redis-trib.rb:25:in `<main>'
解决方法:下载安装rubygem 进入解压包中./configure make && make install
此时就可以运行gem intall redis 命令,来安装ruby执行redis的相关依赖。
问题2:
gem install redis 命令出现的问题
ERROR: Loading command: install (LoadError)
cannot load such file -- openssl
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass手动安装opensll,此问题解决。

问题3:
接着执行命令:gem install redis
ERROR: Loading command: install (LoadError)
cannot load such file -- zlib
手动安装zlib包解决(这个可能是系统太纯净,没有些包的问题)。安装过程不多说,手动下载安装包安装。

问题4:
接着执行命令:gem install redis
ERROR: While executing gem ... (Gem::Exception)
Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
解决方法:
gem sources -a https://gems.ruby-china.org/ 把https地址改成 gem sources -a http://gems.ruby-china.org/
执行成功,查看gem source -l 镜像地址修改成功。

再次执行:gem install redis成功。

配置文件修改>

#绑定主机IP,默认值为127.0.0.1
bind 0.0.0.0
#要是配置里没有指定bind和密码,开启该参数后,redis只能本地进行访问,要是开启了密码和bind,可以开启.否则最好设置为no。
protected-mode yes
#端口号
port 6380
#和内核参数/proc/sys/net/core/somaxconn值一样,redis默认511,而内核默认值128,高并发场景将其增大,内核参数也增大
tcp-backlog 511
#客户端闲置多少秒后,断开连接为0,则服务端不会主动断开连接
timeout 0
#是否在后台执行
daemonize yes
supervised no
#redis进程文件
pidfile /web/soft/redis-6380/redis-6380.pid
#日志的级别,包括:debug,verbose,notice(默认适合生成环境),warn(只有非常重要的信息)
loglevel notice
#指定日志文件
logfile "/web/soft/redis-6380/redis-6380.log"
#数据库的数量,默认使用的数据库是DB 0,可以通过”SELECT “命令选择一个db
databases 16
 
# -------------------- SLOW LOG --------------------
#slog log是用来记录慢查询,执行时间比slowlog-log-slower-than大的请求记录到slowlog里面,1000000=1秒
slowlog-log-slower-than 1000000
 
#慢查询日志长度。当一个新的命令被写进日志的时候,最老的那个记录会被删掉。这个长度没有限制。只要有足够的内存就行。你可以通过 SLOWLOG RESET 来释放内存。
slowlog-max-len 128
 
# -------------------- rdb Persistence --------------------
#当有一条Keys数据被改变是,900秒刷新到disk一次
save 900 1
#当有10条Keys数据被改变时,300秒刷新到disk一次
save 300 10
#当有1w条keys数据被改变时,60秒刷新到disk一次
save 60 10000
#当RDB持久化出现错误后,是否依然进行继续进行工作
stop-writes-on-bgsave-error yes
#使用压缩rdb文件,压缩需要一些cpu的消耗,不压缩需要更多的磁盘空间
rdbcompression yes
##是否校验rdb文件,校验会有大概10%的性能损耗
#rdbchecksum yes
##rdb文件的名称
dbfilename dump.rdb
##数据目录,数据库的写入会在这个目录。rdb、aof文件也会写在这个目录
dir /web/soft/redis-6380/
# -------------------- AOF Persistence --------------------
#Append Only File是另一种持久化方式,可以提供更好的持久化特性.Redis会把每次写入的数据在接收后都写入 appendonly.aof 文件,每次启动时Redis都会先把这个文件的数据读入内存里,先忽略RDB文件
appendonly yes
#aof文件名
appendfilename "appendonly6380.aof"
#aof持久化策略,no表示不执行fsync,由操作系统保证数据同步到磁盘,速度最快.
#always表示每次写入都执行fsync,以保证数据同步到磁盘
#everysec表示每秒执行一次fsync,可能会导致丢失这1s数据
appendfsync everysec
#设置为yes表示rewrite期间对新写操作不fsync,暂时存在内存中,等rewrite完成后再写入,默认为no最安全,建议yes.Linux的默认fsync策略是30秒.可能丢失30秒数据.
no-appendfsync-on-rewrite no
#aof自动重写配置,前AOF文件大小是上次AOF文件大小的二倍(设置为100)时,自动启动新的日志重写过程
auto-aof-rewrite-percentage 100
#设置允许重写的最小aof文件大小,避免了达到约定百分比但尺寸仍然很小的情况还要重写
auto-aof-rewrite-min-size 64mb
#aof文件可能在尾部是不完整的,如果选择的是yes,当截断的aof文件被导入的时候,会自动发布一个log给客户端然后load
aof-load-truncated yes
# 如果达到最大时间限制(毫秒),redis会记个log,然后返回error。当一个脚本超过了最大时限。只有SCRIPT KILL和SHUTDOWN NOSAVE可以用。第一个可以杀没有调write命令的东西。要是已经调用了write,只能用第二个命令杀。
lua-time-limit 5000
 
# -------------------- REDIS CLUSTER --------------------
##集群开关,默认是不开启集群模式。
cluster-enabled yes
 
#集群配置文件的名称,每个节点都有一个集群相关的配置文件,持久化保存集群的信息。这个文件并不需要手动配置,这个配置文件有Redis生成并更新,每个Redis集群节点需要一个单独的配置文件,请确保与实例运行的系统中配置文件名称不冲突
cluster-config-file /web/soft/redis-6380/nodes-6380.conf
 
#节点互连超时的阀值。集群节点超时毫秒数
cluster-node-timeout 5000
 
#在进行故障转移的时候,全部slave都会请求申请为master,但是有些slave可能与master断开连接一段时间了,导致数据过于陈旧,这样的slave不应该被提升为master。
##如果节点超时时间为三十秒, 并且slave-validity-factor为10,假设默认的repl-ping-slave-period是10秒,即如果超过310秒slave将不会尝试进行故障转移 
cluster-slave-validity-factor 10
 
#当某个主节点的从节点挂掉裸奔后,会从其他富余的主节点分配一个从节点过来,确保每个主节点都有至少一个从节点
#分配后仍然剩余migration barrier个从节点的主节点才会触发节点分配,默认是1,生产环境建议维持默认值,这样才能最大可能的确保集群稳定
cluster-migration-barrier 1

依次启动redis节点

redis-server  /root/redis-6001/redis.conf  #redis节点配置文件

防火墙端口放通

确保开放端口,每个redis实例都需要2个TCP端口,其一为服务于客户端的port,通常为6379;另外一个为“Redis Cluster bus”端口,此值为客户端port + 10000,假如客户端port为6379,那么bus端口即为16379,此端口我们无法通过配置来设定。(因为server的最大端口号为65535,所以客户端port不要设置的太大),如果开了防火墙,需要设置iptables开放上面所有端口。Server2步骤和Server1一样

创建集群

运行 redis-trib.rb 查看 集群创建帮助

#其中 –replicas 1 意思为为每个 master 分配 1 个 slave
protected-mode  no  这是3.2.0以后redis.conf中新增的配置项,默认值为yes,限制从其它机器登录Redis server, 而只能从127.0.0.1登录。为保证redis-trib.rb工具的正常运行,最好设置为no,

[root@gitserver redis-4.0.2]# ./src/redis-trib.rb create --replicas 1 192.168.121.200:6001 192.168.121.200:6002 192.168.121.200:6003 192.168.121.201:6001 192.168.121.201:6002 192.168.121.201:6003

注意:当集群或各个redis实例非正常关闭(如使用kill命令),重新启动集群,就需要使用如下命令启动各个节点(在nodes-7000.conf所在目录下执行):
#../bin/redis-server redis.conf –cluster-config-file nodes-6001.conf

测试集群

get 和 set数据
在192.168.121.200上终端输入:
#./ redis-cli  -c  -p  6001
进入命令窗口,直接 set  hello   helloworld,直接根据hash匹配切换到相应的slot节点上。然后找到这个节点所对应的从节点,在从节点上执行redis-cli   -c  -p  7004进入命令行后,输入get  hello出现如下界面:

#在 192.168.121.200:6001 机器上设置一个键值对 testKey--testValue ,因为绑定了 IP ,所以 h 参数不能省略
[root@localhost redis-4.0.2]# redis-cli -h 192.168.121.200 -c -p 6001
192.168.121.200:6001> set hello helloworld
OK
192.168.121.200:6001> get hello
"helloworld"

#在 192.168.121.200:6003 上获取 hello 的值,发现自动定向到 192.168.121.200:6001,说明成功
root@localhost redis-4.0.2]# redis-cli -h 192.168.121.200 -c -p 6003
192.168.121.200:6003> get hello
-> Redirected to slot [866] located at 192.168.121.200:6001
"helloworld"

#在 192.168.121.201:6003 上获取 testKey 的值,发现自动定向到 192.168.121.200:6001,说明成功
[root@localhost redis-4.0.2]# redis-cli -h 192.168.121.201 -c -p 6003
192.168.121.201:6003> get hello
-> Redirected to slot [866] located at 192.168.121.200:6001
"helloworld"

[root@localhost redis-4.0.2]# ./src/redis-trib.rb check 192.168.121.200:6001          //检查集群状态(ip和端口可以是任何一个节点)

redis集群由16383个slot组成,通过分片分布到多个节点上,读写都发生在master节点。假设先把Server2服务Down掉(Server2有1个Master, 2个Slave) ,  查看一下发生了什么事,Server1的3个节点全部都是Master,其他几个Server2的不见了,测试一下依然没有问题,集群依然能继续工作。

原因:redis集群通过选举方式进行容错,保证一台Server挂了还能跑,这个选举是全部集群超过半数以上的Master发现其他Master挂了后,会将其对应的Slave节点升级成Master。

疑问:要是挂的是Server1怎么办?cluster is down!!没办法,超过半数的Master挂了那救不了了,整个集群就无法工作了。 要是有三台Server,每台两个Master,切记对应的主从节点不要放在一台Server,互相交叉配置主从,挂哪台也没事。可以通过执行redis-cli  -p  7001 cluster  nodes命令进行查看,下图中的7000的机子已经挂了,然后对应的7005从slave升为了master。

至此,Redis 集群搭建完成。

集群操作

检查状态

[root@localhost redis-4.0.2]# ./src/redis-trib.rb check 192.168.121.200:6001
>>> Performing Cluster Check (using node 192.168.121.200:6001)
M: 817e5b3bf56e9d59dbcc0c77f5703e5290926f74 192.168.121.200:6001
 slots:0-5460 (5461 slots) master
 1 additional replica(s)
S: f76148b832b137ebc3919f4f8774dacb85f942eb 192.168.121.200:6003
 slots: (0 slots) slave
 replicates b430ffee12cca7034aa2db73a8f971614e1256b5
M: ed7ad1169882c32812c6618a683b50ca17acfb4d 192.168.121.200:6002
 slots:10923-16383 (5461 slots) master
 1 additional replica(s)
M: b430ffee12cca7034aa2db73a8f971614e1256b5 192.168.121.201:6001
 slots:5461-10922 (5462 slots) master
 1 additional replica(s)
S: 98ec01eb644d86aa5ab8ac68c84070d6421eb85e 192.168.121.201:6002
 slots: (0 slots) slave
 replicates 817e5b3bf56e9d59dbcc0c77f5703e5290926f74
S: ed58954926b02a37ba340f4de9eec8f3782e481c 192.168.121.201:6003
 slots: (0 slots) slave
 replicates ed7ad1169882c32812c6618a683b50ca17acfb4d
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

查看节点信息

[root@localhost redis-4.0.2]# redis-cli -h 192.168.121.200 -c -p 6001
192.168.121.200:6001> 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:2357
cluster_stats_messages_pong_sent:2361
cluster_stats_messages_sent:4718
cluster_stats_messages_ping_received:2356
cluster_stats_messages_pong_received:2357
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:4718

cluster 扩容

新增节点

业务规模变大后,集群扩容是早晚的事情,下面演示如何再添加2个节点,先把6001复制二份,变成7006,7007,然后进入7006/7007目录redis的src子目录下
1 rm nodes.conf dump.rdb appendonly.aof
由于6001我们刚才启动过,里面有已经有一些数据了,所以要把数据文件,日志文件,以及cluster的nodes.conf文件删除,变成一个空的redis独立节点,否则无法加入cluster。
然后修改redis-cluster.conf

port 6001
cluster-enabled yes
cluster-config-file "nodes.conf"
cluster-node-timeout 10000
appendonly yes

要修改的地方有二处,1是第一行的端口,改成与7006/7007匹配的端口,2是最后2行,这是7000运行后,自动添加的,把最后二行删除。
做完这些后,启动7006,7007这二个redis节点,此时这2个新节点与cluster没有任何关系,可以用下面的命令将7006做为master添加到cluster中。

./redis-trib.rb add-node 192.168.121.200:7006 192.168.121.200:6001

注:第1个参数为新节点的”IP:端口”,第2个参数为集群中的任一有效的节点。
顺利的话,输出如下:

>>> Adding node 127.0.0.1:7006 to cluster 127.0.0.1:6001
>>> Performing Cluster Check (using node 127.0.0.1:6001)
M: 0b7e0d5337e87ac7b59bba4c1248e5c9e8d1905e 192.168.121.200:6001
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: e0e8dfddd4e9d855090d6efd18e55ea9c0e1f7aa 192.168.121.200:6002
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: be7e9fd3b7d096b037306bc14e1017150fa59d7a 192.168.121.200:6003
   slots: (0 slots) slave
   replicates e0e8dfddd4e9d855090d6efd18e55ea9c0e1f7aa
M: ec964a7c7cd53b986f54318a190c1426fc53a5fa 192.168.121.201:6001
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 88e16f91609c03277f2ee6ce5285932f58c221c1 192.168.121.201:6002
   slots: (0 slots) slave
   replicates ec964a7c7cd53b986f54318a190c1426fc53a5fa
S: 38910c5baafea02c5303505acfd9bd331c608cfc 192.168.121.201:6003
   slots: (0 slots) slave
   replicates 0b7e0d5337e87ac7b59bba4c1248e5c9e8d1905e
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 127.0.0.1:7006 to make it join the cluster.
[OK] New node added correctly.

可以再用check确认下状态:

 ./redis-trib.rb check 127.0.0.1:7000
>>> Performing Cluster Check (using node 127.0.0.1:7000)
M: 0b7e0d5337e87ac7b59bba4c1248e5c9e8d1905e 127.0.0.1:7000
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: e0e8dfddd4e9d855090d6efd18e55ea9c0e1f7aa 127.0.0.1:7001
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: be7e9fd3b7d096b037306bc14e1017150fa59d7a 127.0.0.1:7004
   slots: (0 slots) slave
   replicates e0e8dfddd4e9d855090d6efd18e55ea9c0e1f7aa
M: 226d1af3c95bf0798ea9fed86373b89347f889da 127.0.0.1:7006
   slots: (0 slots) master
   0 additional replica(s)
M: ec964a7c7cd53b986f54318a190c1426fc53a5fa 127.0.0.1:7002
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 88e16f91609c03277f2ee6ce5285932f58c221c1 127.0.0.1:7005
   slots: (0 slots) slave
   replicates ec964a7c7cd53b986f54318a190c1426fc53a5fa
S: 38910c5baafea02c5303505acfd9bd331c608cfc 127.0.0.1:7003
   slots: (0 slots) slave
   replicates 0b7e0d5337e87ac7b59bba4c1248e5c9e8d1905e
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

12-14行说明7006已经是cluster的新master了,继续,用下面的命令把7007当成slave加入:

./redis-trib.rb add-node --slave --master-id 226d1af3c95bf0798ea9fed86373b89347f889da 127.0.0.1:7007 127.0.0.1:7000

这里多出了二个参数:–slave 表示准备将新节点当成slave加入,–master-id xxxxx 则是指定要当谁的slave,后面的xxx部分,即为前面check的输出结果中,7006的ID,完事之后,可以再次确认状态:

src ./redis-trib.rb check 127.0.0.1:7000
>>> Performing Cluster Check (using node 127.0.0.1:7000)
M: 0b7e0d5337e87ac7b59bba4c1248e5c9e8d1905e 127.0.0.1:7000
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: 792bcccf35845c4922dd33d7f9827420ebb89bc9 127.0.0.1:7007
   slots: (0 slots) slave
   replicates 226d1af3c95bf0798ea9fed86373b89347f889da
M: e0e8dfddd4e9d855090d6efd18e55ea9c0e1f7aa 127.0.0.1:7001
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: be7e9fd3b7d096b037306bc14e1017150fa59d7a 127.0.0.1:7004
   slots: (0 slots) slave
   replicates e0e8dfddd4e9d855090d6efd18e55ea9c0e1f7aa
M: 226d1af3c95bf0798ea9fed86373b89347f889da 127.0.0.1:7006
   slots: (0 slots) master
   1 additional replica(s)
M: ec964a7c7cd53b986f54318a190c1426fc53a5fa 127.0.0.1:7002
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 88e16f91609c03277f2ee6ce5285932f58c221c1 127.0.0.1:7005
   slots: (0 slots) slave
   replicates ec964a7c7cd53b986f54318a190c1426fc53a5fa
S: 38910c5baafea02c5303505acfd9bd331c608cfc 127.0.0.1:7003
   slots: (0 slots) slave
   replicates 0b7e0d5337e87ac7b59bba4c1248e5c9e8d1905e
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

观察6-8行、15-17行,说明7007已经是7006的slave。

reshard 重新划分slot

增加新的节点之后,问题就来了,16384个slot已经被其它3组节点分完了,新节点没有slot,没办法存放缓存,所以需要将slot重新分布。

./redis-trib.rb info 127.0.0.1:7000
127.0.0.1:7000 (0b7e0d53...) -> 4 keys | 5461 slots | 1 slaves.
127.0.0.1:7001 (e0e8dfdd...) -> 4 keys | 5462 slots | 1 slaves.
127.0.0.1:7006 (226d1af3...) -> 0 keys | 0 slots | 1 slaves. #7006上完全没有slot
127.0.0.1:7002 (ec964a7c...) -> 9 keys | 5461 slots | 1 slaves.
[OK] 17 keys in 4 masters.
0.00 keys per slot on average.

用下面的命令可以重新分配slot

./redis-trib.rb reshard 127.0.0.1:7000
reshard后面的IP:port,只要是在cluster中的有效节点即可。
./redis-trib.rb reshard 127.0.0.1:7000
>>> Performing Cluster Check (using node 127.0.0.1:7000)
M: 0b7e0d5337e87ac7b59bba4c1248e5c9e8d1905e 127.0.0.1:7000
   slots:1792-4095 (2304 slots) master
   0 additional replica(s)
   ...
[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)? 1000 #这里输入要移动多少slot
What is the receiving node ID? 0b7e0d5337e87ac7b59bba4c1248e5c9e8d1905e #这里输入目标节点的id
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 #将所有node都当成源节点
    ...
    Moving slot 4309 from ec964a7c7cd53b986f54318a190c1426fc53a5fa
    Moving slot 4310 from ec964a7c7cd53b986f54318a190c1426fc53a5fa
    Moving slot 4311 from ec964a7c7cd53b986f54318a190c1426fc53a5fa
    Moving slot 4312 from ec964a7c7cd53b986f54318a190c1426fc53a5fa
    Moving slot 4313 from ec964a7c7cd53b986f54318a190c1426fc53a5fa
Do you want to proceed with the proposed reshard plan (yes/no)? yes #确认执行

注:第一个交互询问,填写多少slot移动时,要好好想想,如果填成16384,则将所有slot都移动到一个固定节点上,会导致更加不均衡!建议每次移动500~1000,这样对线上的影响比较小。
另外在填写source node时,除了all之外,还可以直接填写源节点的id,即:

[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 300
What is the receiving node ID? 0b7e0d5337e87ac7b59bba4c1248e5c9e8d1905e
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:226d1af3c95bf0798ea9fed86373b89347f889da #这里填写源节点的id
Source node #2:done #这里输入done表示,不再继续添加源节点了

reshard可以多次操作,直到达到期望的分布为止(注:个人觉得redis的reshard这里有点麻烦,要移动多少slot需要人工计算,如果能提供一个参数之类,让16384个slot自动平均分配就好了),调整完成后,可以再看看分布情况:

./redis-trib.rb info 127.0.0.1:7000
127.0.0.1:7000 (0b7e0d53...) -> 4 keys | 4072 slots | 0 slaves.
127.0.0.1:7001 (e0e8dfdd...) -> 5 keys | 4099 slots | 0 slaves.
127.0.0.1:7006 (226d1af3...) -> 5 keys | 4132 slots | 4 slaves.
127.0.0.1:7002 (ec964a7c...) -> 3 keys | 4081 slots | 0 slaves.
[OK] 17 keys in 4 masters.
0.00 keys per slot on average.

删除节点del-node

既然有扩容,就会有反向需求,某些节点不再需要时,可以用del-node删除,比如刚才我一阵乱倒腾后,发现7006已经有4个slave了,而其它master一个slave都没有,这明显不合理。
删除节点命令:

./redis-trib.rb del-node 127.0.0.1:7006 88e16f91609c03277f2ee6ce5285932f58c221c1

del-node后面的ip:port只要是cluster中有效节点即可,最后一个参数为目标节点的id,注意:只有slave节点和空的master节点可以删除,如果master非空,先用reshard把上面的slot移动到其它node后再删除,如果有一组master-slave节点,将master上所有slot移到其它节点,然后将master删除,剩下的slave会另寻他主,变成其它master的slave。
另外:删除节点的含义,不仅仅是从cluster中将这个节点移除,还会直接将目标节点的redis服务停止。

集群相关命令

从 slaves 读数据

默认不能从 slaves 读取数据,但建立连接后,执行一次命令 READONLY,即可从 slaves读取数据。如果想再次恢复不能从 slaves 读取数据,可以执行命令 READWRITE。
redis不能来做数据库持久化网站数据,只是拿来做cache,官网说的很清楚,Redis Cluster is not able to guarantee strong consistency

支付宝捐赠
请使用支付宝扫一扫进行捐赠
微信捐赠
请使用微信扫一扫进行赞赏
有 0 篇文章