Redis集群中新增节点(master、slave)(实验)
新增master节点的配置文件:
# vim /usr/local/redis-3.0.6-6379/redis.conf
daemonize yes //开启后台运行
pidfile /var/run/redis_6379.pid //pid文件
port 6379 //端口
bind 192.168.2.100 //默认127.0.0.1,需要改为其他节点可访问的地址
logfile "/usr/local/redis-3.0.6-6379/redis_6379.log" //log文件路径
dir /usr/local/redis-3.0.6-6379/ //RDB文件路径
appendonly yes //开启AOF持久化
cluster-enabled yes //开启集群
cluster-config-file nodes-6379.conf //集群配置文件
cluster-node-timeout 15000 //请求超时,默认15秒
启动新增master节点:
# redis-server redis.conf
安装ruby环境:(redis-trib.rb命令,需要在ruby环境中执行)
# yum -y install ruby ruby-devel rubygems rpm-build
# gem install redis
Successfully installed redis-3.2.1
Parsing documentation for redis-3.2.1
1 gem installed
可能会遇到的报错:
ERROR: Could not find a valid gem 'redis' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - no such name (https://rubygems.org/latest_specs.4.8.gz)
手动下载:https://rubygems.global.ssl.fastly.net/gems/redis-3.2.1.gem
执行:# gem install -l ./redis-3.2.1.gem
把master节点加入集群中:
# redis-trib.rb add-node 192.168.2.202:6379 192.168.2.100:6379
//第一个ip:port 新节点
第二个ip:port 集群中的任意节点
查看集群所有节点信息:(可以看到,新增节点已加入集群,但是没有分配hash slot)
# redis-trib.rb check 192.168.2.202:6379
>>> Performing Cluster Check (using node 192.168.2.202:6379)
M: 8326ff0be199fa0d4db74f0ebcc58f27e65991b4 192.168.2.202:6379
slots: (0 slots) master
0 additional replica(s)
... ...
给新增master节点分配slot:
# redis-trib.rb reshard 192.168.2.202:6379
>>> Performing Cluster Check (using node 192.168.2.202:6379)
M: 8326ff0be199fa0d4db74f0ebcc58f27e65991b4 192.168.2.202:6379
slots: (0 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
//想要移动多少个hash slot?(分配给新节点)
What is the receiving node ID? 8326ff0be199fa0d4db74f0ebcc58f27e65991b4
//接受的节点ID是什么?(新加节点的ID)
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
//如果从所有节点移动,输入all
Type 'done' once you entered all the source nodes IDs.
//输入指定节点ID,done结尾
Source node #1:all
... ...
Do you want to proceed with the proposed reshard plan (yes/no)? yes
//是否满意hash slot移动计划?
查看集群节点的信息:(确认新增节点hash slot分配正确)
# redis-trib.rb check 192.168.2.202:6379
>>> Performing Cluster Check (using node 192.168.2.202:6379)
M: 8326ff0be199fa0d4db74f0ebcc58f27e65991b4 192.168.2.202:6379
slots:0-332,5461-5794,10923-11255 (1000 slots) master
0 additional replica(s)
... ...
启动slave节点:(配置和上面一样)
# redis-server /usr/local/redis-3.0.6-6380/redis.conf
将slave节点加入集群:
# redis-trib.rb add-node --slave 192.168.2.202:6380 192.168.2.100:6379
//加入--slave参数,表示加入的是slave
第一个IP是新增的slave
第二个IP是节点中的任意节点
查看集群信息:(可以看到新加slave属于192.168.2.202:6379的从节点)
# redis-trib.rb check 192.168.2.100:6379
>>> Performing Cluster Check (using node 192.168.2.100:6379)
M: 8326ff0be199fa0d4db74f0ebcc58f27e65991b4 192.168.2.202:6379
slots:0-332,5461-5794,10923-11255 (1000 slots) master
1 additional replica(s)
S: e4dc23dc67418bf66c6c63655110612cb9516aff 192.168.2.202:6380
slots: (0 slots) slave
replicates 8326ff0be199fa0d4db74f0ebcc58f27e65991b4
... ...
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341