暂无图片
暂无图片
暂无图片
暂无图片
暂无图片
REDIS集群说明.txt
9
2页
1次
2025-03-31
免费下载
按照此文档一步步做就可以实现集群
请使用 3.0 以上版本,低于 3.0 REDIS 没有集群功能
解压安装
tar -vxf redis-3.0.0-beta5.tar.gz
cd redis-3.0.0-beta5
编译
make
有时候会遇到#error "Newer version of jemalloc required",使用 make MALLOC=libc 即可
首先尝试单机 REDIS 的启动和停止
启动
cd /usr/local/redis-3.0.0-beta5
./src/redis-server &
关闭
./src/redis-cli shutdown
或指定端口关闭
./src/redis-cli -p 7000 shutdown
复制出 6 REDIS 实例(官方要求不得少于 6 个实例)
修改配置文件 redis.conf,找到 appendonly 这一项,默认是 NO,改成 yes,再追加另外几个项,变成
如下内容
appendonly yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
以此启动 6 redis,注意集群数目必须大于 6
./src/redis-server redis.conf &
启动集群
./src/redis-trib.rb create --replicas 1 192.168.1.75:7000 192.168.1.75:7001
192.168.1.75:7002 192.168.1.16:7000 192.168.1.16:7001 192.168.1.16:7002
--replicas 1 的意思是每个 MASTER 分配一个 SLAVE
此外,启动后 redis 会询问是否需要保存集群配置信息,敲 yes
然后系统会自动选择谁做主机谁备份
查看终端
./src/redis-cli -p 7000
查看集群信息
cluster info
cluster nodes
重新规划 slot hash
./src/redis-trib.rb reshard 192.168.1.75:7000
系统会询问:
How many slots do you want to move (from 1 to 16384)?
输入 1000,系统接着询问
What is the receiving node ID?
6bd328f46940b6b91f45e9a7606ac6f2a8c9840e(这是一个节点的 ID
然后系统问这是不是全部的接收节点,输入 all,系统开始迁移缓存数据
弄完后可以用这个命令查看结果
./src/redis-trib.rb check 192.168.1.75:7000
但是我切割的时候意外的出错了,
[ERR] Not all 16384 slots are covered by nodes.
*** Please fix your cluster problems before resharding
因此需要修复
./src/redis-trib.rb fix 192.168.1.75:7000
以下是修复提示信息
>>> Fixing slots coverage...
List of not covered slots: 5463
Slot 5463 has keys in 0 nodes:
The folowing uncovered slots have no keys across the cluster:
5463
Fix these slots by covering with a random node? (type 'yes' to accept): yes
如果无法修复,只要把 redis.conf 中定义的 cluster-config-file 所在的文件删除,重新启动
redis-server 及运行 redis-trib 即可
增加节点
./src/redis-trib.rb add-node 192.168.1.75:7003 192.168.1.75:7000
增加的节点变成了 MASTER
增加 SLAVE 节点,注意增加该节点时最好先检查下 cluster-config-file 指定的文件是否已经存在,如
本例是 nodes.conf,若存在,则先删掉
./src/redis-trib.rb add-node --slave --master-id
3771574aeba36ac672bdf9c7abb77db1613951e5 192.168.1.75:7004 192.168.1.75:7000
从集群中删除节点(注意这条命令同时也会关闭该节点)
./src/redis-trib.rb del-node 192.168.1.75:7000
'd855f5cefa031c3991960c97394b1dc7413744d6'
副本迁移
改变一个 SLAVE 机的 MASTER 对象(该命令未测试,可能要连上 redis-cli 然后执行)
CLUSTER REPLICATE <master-node-id>
启动 sentinel,提供主备自动切换
./src/redis-sentinel sentinel.conf &
参考以下内容
port 27000
#不要使用 17000,因为 REDIS 集群也需要占用大量端口,可能会占用掉 17000
dir /tmp
sentinel monitor mymaster 192.168.1.75 7000 2 #主服务器判断为失效至少需要 2
Sentinel 同意,采用流言协议
sentinel down-after-milliseconds mymaster 30000 #指定了 Sentinel 认为服务器已经断线所
需的毫秒数
sentinel parallel-syncs mymaster 1 #在执行故障转移时, 最多可以有多少个从服务器同时对新的
主服务器进行同步, 这个数字越小, 完成故障转移所需的时间就越长
sentinel failover-timeout mymaster 180000 #指定了 Sentinel 认为服务器已经断线所需的毫
秒数
of 2
免费下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。