redis5安装redis-cluster
young / / / 阅读量

redis5.0新特性

Redis 5主要专注于几个重要功能。相比之下Redis 4非常非常专注于操作类型,Redis 5的变化大多是面向用户的。即在现有的基础上增加新的数据类型和操作类型。以下是此版本的主要功能:

1. 新的Stream数据类型。[1]
2. 新的Redis模块API:Timers and Cluster API。
3. RDB现在存储LFU和LRU信息。
4. 集群管理器从Ruby(redis-trib.rb)移植到C代码。可以在redis-cli中。查看redis-cli —cluster help了解更多信息。
5. 新sorted set命令:ZPOPMIN / MAX和阻塞变量。
6. 主动碎片整理V2。
7. 增强HyperLogLog实现。
8. 更好的内存统计报告。
9. 许多带有子命令的命令现在都有一个HELP子命令。
10. 客户经常连接和断开连接时性能更好。
11. 错误修复和改进。
12. Jemalloc升级到5.1版

*Redis 4.0大多是5.0的严格子集,应用程序从4.0升级到5.0通常不会碰见问题

redis 5.0集群工具

集群管理工具redis-trib.rb已经被废弃,所以不用安装ruby啥的了,redis-cli现在实现了集群管理工具。 我们仍然在维护旧的redis-trib,但是新的修复只会在redis-cli中实现。有关更多信息,请参阅redis-cli —cluster help

redis5安装cluster集群

redis节点安装

(略)

配置文件修改

(略)

依次启动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一样

创建集群

/usr/local/redis/bin/redis-cli  --cluster-replicas 1 --cluster create  172.16.44.18:6380 172.16.44.18:6381 172.16.44.19:6380 172.16.44.19:6381 172.16.44.19:6382 172.16.44.19:6383 172.16.44.18:6382 172.16.44.18:6383 

输出:

>>> Performing hash slots allocation on 8 nodes...
Master[0] -> Slots 0 - 4095
Master[1] -> Slots 4096 - 8191
Master[2] -> Slots 8192 - 12287
Master[3] -> Slots 12288 - 16383
Adding replica 172.16.44.19:6382 to 172.16.44.18:6380
Adding replica 172.16.44.18:6382 to 172.16.44.19:6380
Adding replica 172.16.44.19:6383 to 172.16.44.18:6381
Adding replica 172.16.44.18:6383 to 172.16.44.19:6381
M: b5d8175b8bc702b5082da06f11777ab171998657 172.16.44.18:6380
   slots:[0-4095] (4096 slots) master
M: 82eac59d74b69fe078976e02821794b043c779bd 172.16.44.18:6381
   slots:[8192-12287] (4096 slots) master
M: f3ae988d5fb6aa69b7753b5156ca4a6e793b0ee3 172.16.44.19:6380
   slots:[4096-8191] (4096 slots) master
M: 5aa4c15b5ecb4354becad6259a2dc235628a98df 172.16.44.19:6381
   slots:[12288-16383] (4096 slots) master
S: f0ed6d25f308799fc13a8fc986cd535828b03ea9 172.16.44.19:6382
   replicates b5d8175b8bc702b5082da06f11777ab171998657
S: 5323ec967d30ea48d264bf92ef3ca29df8dc68a4 172.16.44.19:6383
   replicates 82eac59d74b69fe078976e02821794b043c779bd
S: 7cd98a62121a47cef5556abc18173262bc51c511 172.16.44.18:6382
   replicates f3ae988d5fb6aa69b7753b5156ca4a6e793b0ee3
S: 3e5397e22bf12ea2fd0f4d3fb4f29ad95149ac2d 172.16.44.18:6383
   replicates 5aa4c15b5ecb4354becad6259a2dc235628a98df
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 172.16.44.18:6380)
M: b5d8175b8bc702b5082da06f11777ab171998657 172.16.44.18:6380
   slots:[0-4095] (4096 slots) master
   1 additional replica(s)
S: 3e5397e22bf12ea2fd0f4d3fb4f29ad95149ac2d 172.16.44.18:6383
   slots: (0 slots) slave
   replicates 5aa4c15b5ecb4354becad6259a2dc235628a98df
M: 82eac59d74b69fe078976e02821794b043c779bd 172.16.44.18:6381
   slots:[8192-12287] (4096 slots) master
   1 additional replica(s)
S: 7cd98a62121a47cef5556abc18173262bc51c511 172.16.44.18:6382
   slots: (0 slots) slave
   replicates f3ae988d5fb6aa69b7753b5156ca4a6e793b0ee3
M: f3ae988d5fb6aa69b7753b5156ca4a6e793b0ee3 172.16.44.19:6380
   slots:[4096-8191] (4096 slots) master
   1 additional replica(s)
S: f0ed6d25f308799fc13a8fc986cd535828b03ea9 172.16.44.19:6382
   slots: (0 slots) slave
   replicates b5d8175b8bc702b5082da06f11777ab171998657
M: 5aa4c15b5ecb4354becad6259a2dc235628a98df 172.16.44.19:6381
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 5323ec967d30ea48d264bf92ef3ca29df8dc68a4 172.16.44.19:6383
   slots: (0 slots) slave
   replicates 82eac59d74b69fe078976e02821794b043c779bd
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

相关操作

检查集群

./redis-cli --cluster check 192.168.121.200:6001

输出:

172.16.44.18:6380 (b5d8175b...) -> 0 keys | 4096 slots | 1 slaves.
172.16.44.18:6381 (82eac59d...) -> 0 keys | 4096 slots | 1 slaves.
172.16.44.19:6380 (f3ae988d...) -> 0 keys | 4096 slots | 1 slaves.
172.16.44.19:6381 (5aa4c15b...) -> 0 keys | 4096 slots | 1 slaves.
[OK] 0 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 172.16.44.18:6380)
M: b5d8175b8bc702b5082da06f11777ab171998657 172.16.44.18:6380
   slots:[0-4095] (4096 slots) master
   1 additional replica(s)
S: 3e5397e22bf12ea2fd0f4d3fb4f29ad95149ac2d 172.16.44.18:6383
   slots: (0 slots) slave
   replicates 5aa4c15b5ecb4354becad6259a2dc235628a98df
M: 82eac59d74b69fe078976e02821794b043c779bd 172.16.44.18:6381
   slots:[8192-12287] (4096 slots) master
   1 additional replica(s)
S: 7cd98a62121a47cef5556abc18173262bc51c511 172.16.44.18:6382
   slots: (0 slots) slave
   replicates f3ae988d5fb6aa69b7753b5156ca4a6e793b0ee3
M: f3ae988d5fb6aa69b7753b5156ca4a6e793b0ee3 172.16.44.19:6380
   slots:[4096-8191] (4096 slots) master
   1 additional replica(s)
S: f0ed6d25f308799fc13a8fc986cd535828b03ea9 172.16.44.19:6382
   slots: (0 slots) slave
   replicates b5d8175b8bc702b5082da06f11777ab171998657
M: 5aa4c15b5ecb4354becad6259a2dc235628a98df 172.16.44.19:6381
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 5323ec967d30ea48d264bf92ef3ca29df8dc68a4 172.16.44.19:6383
   slots: (0 slots) slave
   replicates 82eac59d74b69fe078976e02821794b043c779bd
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

查看集群key、slot、slave分布信息

redis-cli --cluster info 172.16.44.18:6380

输出:

172.16.44.18:6380 (b5d8175b...) -> 0 keys | 4096 slots | 1 slaves.
172.16.44.18:6381 (82eac59d...) -> 0 keys | 4096 slots | 1 slaves.
172.16.44.19:6380 (f3ae988d...) -> 0 keys | 4096 slots | 1 slaves.
172.16.44.19:6381 (5aa4c15b...) -> 0 keys | 4096 slots | 1 slaves.
[OK] 0 keys in 4 masters.
0.00 keys per slot on average.

在线迁移槽

./redis-cli --cluster reshard 192.168.121.200:6001

选择一个目标节点的id
源选择all

平衡各节点槽数量

./redis-cli --cluster rebalance --cluster-threshold 1 192.168.121.200:6001

删除集群节点

./redis-cli --cluster del-node 192.168.121.200:6001 b97cde23f3c1a1b13e42728562180355b985831a

这里必须是没有槽的节点,所以必须先移除槽,否则报错
被删除的node重启后,依然记得集群中的其它节点,这是需要执行cluster forget nodeid来忘记其它节点

添加集群节点

./redis-cli --cluster add-node 192.168.121.200:6004 192.168.121.200:6005

将集群外部redis实例中的数据导入到集群中去

redis-cli -h 192.168.1.172 -p 6379 --cluster import 192.168.1.172:6379 --cluster-from 192.168.121.200:6006 --cluster-copy --cluster-replace

Cluster-from后面跟外部redis的ip和port
如果只使用cluster-copy,则要导入集群中的key不能在,否则如下:
如果集群中已有同样的key,如果需要替换,可以cluster-copy和cluster-replace联用,这样集群中的key就会被替换为外部的

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