Redis Cluster集群管理手册

文章目录

Redis Cluster集群管理

1. redis-trib.rb集群管理工具

在Redis4.x及之前版本,需要安装redis-trib模块管理集群,因为绝大部分集群功能需要依赖redis-trib模块实现。

1. 创建集群

若是Redis 5.x及以上版本,可采用redis-cli工具部署,因为Redis 5.x及以上版本彻底抛弃了ruby,将集群管理功能集成到了redis-cli工具中,

语法:redis-trib.rb create --replicas 1 redis_host1:redis_port1 redis_host2:redis_port2 redis_host3:redis_port3 ... redis_hostn:redis_portn

特别注意,–replicas选项值代表指定几个从库。

2. 查看集群信息

1. 通过redis-trib.rb检查集群配置

可以检查集群的配置是否正确,以及全部16384个槽是否已经全部指派给了主节点:

语法:redis-trib.rb check existing_host:existing_port

existing_host:existing_port可以为Redis Cluster集群中任意一个节点的地址,作为访问集群的入口。

# 示例1:检查Redis节点192.168.111.111:2011所在集群的配置
# redis-trib.rb check 192.168.111.111:2011

Performing Cluster Check (using node 192.168.111.111:2011)
M: 7b5f21f124373b7d99edafaab01b90afdcfe8592 192.168.111.111:2011
slots:0-2730 (2731 slots) master
1 additional replica(s)
M: 81757eeb491059021c8e2468f361245764800c05 192.168.111.112:2011
slots:2731-5460 (2730 slots) master
1 additional replica(s)
M: 1e94fb4e201b9e7c4eccc207a6f8bae883d1dff1 192.168.111.111:2012
slots:8192-10922 (2731 slots) master
1 additional replica(s)
M: cf118efd950061ae013c52539f66f7ff1779100f 192.168.111.112:2012
slots:10923-13652 (2730 slots) master
1 additional replica(s)
S: b9de42bb24a48cc6a8b6fc72f2c38f43057bf459 192.168.111.113:2014
slots: (0 slots) slave
replicates cf118efd950061ae013c52539f66f7ff1779100f
S: 79187b202bdb436e26d5a7b16e1e91bff0584dc1 192.168.111.111:2014
slots: (0 slots) slave
replicates 8bcaa25b6d0c61fedf1b181971f5eb7f4da7380d
S: 12874ba078047ad747e6123f68c32ddd94c752bc 192.168.111.112:2013
slots: (0 slots) slave
replicates 7b5f21f124373b7d99edafaab01b90afdcfe8592
S: 722ee8a5d3508df3eb6afeff60550de9b5b524be 192.168.111.113:2013
slots: (0 slots) slave
replicates 81757eeb491059021c8e2468f361245764800c05
M: 8bcaa25b6d0c61fedf1b181971f5eb7f4da7380d 192.168.111.113:2011
slots:5461-8191 (2731 slots) master
1 additional replica(s)
S: 7a5c454dfecc3ed53c6bd8cc29a01c3114ee0067 192.168.111.111:2013
slots: (0 slots) slave
replicates 15595bdf3cccc20eb25faf7993608b20967a8673
S: 2c24ba35f85e185b98c66ead9f3ce1a444839fb8 192.168.111.112:2014
slots: (0 slots) slave
replicates 1e94fb4e201b9e7c4eccc207a6f8bae883d1dff1
M: 15595bdf3cccc20eb25faf7993608b20967a8673 192.168.111.113:2012
slots:13653-16383 (2731 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.

注:如上提示均OK,则表示检查集群的配置正确,以及全部16384个槽已经全部
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
redis-cluster-tool 是一个非常便利的 Redis 集群管理工具。help        Usage: redis-cluster-tool [-?hVds] [-v verbosity level] [-o output file]                  [-c conf file] [-a addr] [-i interval]                  [-p pid file] [-C command] [-r redis role]                  [-t thread number] [-b buffer size]    Options:      -h, --help             : this help      -V, --version          : show version and exit      -d, --daemonize        : run as a daemon      -s, --simple           : show the output not in detail      -v, --verbosity=N      : set logging level (default: 5, min: 0, max: 11)      -o, --output=S         : set logging file (default: stderr)      -c, --conf-file=S      : set configuration file (default: conf/rct.yml)      -a, --addr=S           : set redis cluster address (default: 127.0.0.1:6379)      -i, --interval=N       : set interval in msec (default: 1000 msec)      -p, --pid-file=S       : set pid file (default: off)      -C, --command=S        : set command to execute (default: cluster_state)      -r, --role=S           : set the role of the nodes that command to execute on (default: all, you can input: all, master or slave)      -t, --thread=N         : set how many threads to run the job(default: 8)      -b, --buffer=S         : set buffer size to run the job (default: 1048576 byte, unit:G/M/K)        Commands:        cluster_state                 :Show the cluster state.        cluster_used_memory           :Show the cluster used memory.        cluster_keys_num              :Show the cluster holds keys num.        slots_state                   :Show the slots state.        node_slot_num                 :Show the node hold slots number.        new_nodes_name                :Show the new nodes name that not covered slots.        cluster_rebalance             :Show the cluster how to rebalance.        flushall                      :Flush all the cluster.        cluster_config_get            :Get config from every node in the cluster and check consistency.        cluster_config_set            :Set config to every node in the cluster.        cluster_config_rewrite        :Rewrite every node config to echo node for the cluster.        node_list                     :List the nodes            del_keys                      :Delete keys in the cluster. The keys must match a given glob-style pattern.(This command not block the redis)ExampleGet the cluster state:        $redis-cluster-tool -a 127.0.0.1:34501 -C cluster_state -r master    master[127.0.0.1:34504] cluster_state is ok     master[127.0.0.1:34501] cluster_state is ok     master[127.0.0.1:34502] cluster_state is ok     master[127.0.0.1:34503] cluster_state is ok     all nodes cluster_state is ok    Get the cluster used memory:    $redis-cluster-tool -a 127.0.0.1:34501 -C cluster_used_memory -r master    master[127.0.0.1:34504] used 195 M 25%    master[127.0.0.1:34501] used 195 M 25%    master[127.0.0.1:34502] used 195 M 25%    master[127.0.0.1:34503] used 195 M 25%    cluster used 780 MRebalance the cluster slots:    $redis-cluster-tool -a 127.0.0.1:34501 -C cluster_rebalance    --from e1a4ba9922555bfc961f987213e3d4e6659c9316 --to 785862477453bc6b91765ffba0b5bc803052d70a --slots 2048    --from 437c719f50dc9d0745032f3b280ce7ecc40792ac --to cb8299390ce53cefb2352db34976dd768708bf64 --slots 2048    --from a497fc619d4f6c93bd4afb85f3f8a148a3f35adb --to a0cf6c1f12d295cd80f5811afab713cdc858ea30 --slots 2048    --from 0bdef694d08cb3daab9aac518d3ad6f8035ec896 --to 471eaf98ff43ba9a0aadd9579f5af1609239c5b7 --slots 2048Then you can use "redis-trib.rb reshard --yes --from e1a4ba9922555bfc961f987213e3d4e6659c9316 --to 785862477453bc6b91765ffba0b5bc803052d70a --slots 2048 127.0.0.1:34501" to rebalance the cluster slots     Flushall the cluster:    $redis-cluster-tool -a 127.0.0.1:34501 -C flushall -s    Do you really want to execute the "flushall"?    please input "yes" or "no" :        yes    OKGet a config from every node in cluster:    $redis-cluster-tool -a 127.0.0.1:34501 -C "cluster_config_get maxmemory" -r master    master[127.0.0.1:34501] config maxmemory is 1048576000 (1000MB)    master[127.0.0.1:34502] config maxmemory is 1048576000 (1000MB)    master[127.0.0.1:34503] config maxmemory is 1048576000 (1000MB)    master[127.0.0.1:34504] config maxmemory is 1048576000 (1000MB)    All nodes config are Consistent    cluster total maxmemory: 4194304000 (4000MB)Set a config from every node in cluster:    $redis-cluster-tool -a 127.0.0.1:34501 -C "cluster_config_set maxmemory 10000000" -s    Do you really want to execute the "cluster_config_set"?    please input "yes" or "no" :    yes        OKDelete keys in the cluster:    $redis-cluster-tool -a 127.0.0.1:34501 -C "del_keys abc*"    Do you really want to execute the "del_keys"?    please input "yes" or "no" :    yes    delete keys job is running...    delete keys job finished, deleted: 999999 keys, used: 4 s 标签:redis

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zhi@Li

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值