zhmg23

我们是如此的不同
资深运维工程师互荐群: 102123162

Redis集群迁移节点

1、当前集群现状说明

192.168.85.156 7001

192.168.85.156 7002 从

192.168.85.156 7003 从

192.168.85.157 7004

192.168.85.157 7005

192.168.85.157 7006 从

计划把7005主节点,迁移到新的一台机器192.168.85.158上去


2、安装新节点,并加入集群

tar zxvf redis-3.2.5.tar.gz

cd redis-3.2.5

make

mak install

cd utils/

./install_server.sh

 

#  ./install_server.sh

Welcome to the redis service installer

This script will help you easily set up a running redis server

 

Please select the redis port for this instance: [6379] 7005

Please select the redis config file name [/etc/redis/7005.conf] 回车默认

Selected default - /etc/redis/7001.conf

Please select the redis log file name [/var/log/redis_7005.log] 回车默认

Selected default - /var/log/redis_7005.log

Please select the data directory for this instance [/var/lib/redis/7005] /data/redis3

Please select the redis executable path [/usr/local/bin/redis-server] /usr/local/bin/redis-server

Selected config:

Port           : 7005

Config file    : /etc/redis/7005.conf

Log file       : /var/log/redis_7005.log

Data dir       : /data/redis3

Executable     : /usr/local/bin/redis-server

Cli Executable : /usr/local/bin/redis-cli

Is this ok? Then press ENTER to go on or Ctrl-C to abort.

Copied /tmp/7001.conf => /etc/init.d/redis_7005

Installing service...

Successfully added to chkconfig!

Successfully added to runlevels 345!

Starting Redis server...

Installation successful!

修改配置文件/etc/redis/7005.conf

sed -i '$ a\cluster-enabled yes' /etc/redis/7005.conf

sed -i '$ a\cluster-config-file \/data\/redis3\/nodes-7005.conf' /etc/redis/7005.conf

sed -i '$ a\cluster-node-timeout 15000' /etc/redis/7005.conf

sed -i 's/bind 127.0.0.1/ bind 0.0.0.0/g' /etc/redis/7005.conf

重启

service redis_7005 restart

3、将新节点加入集群

redis-trib.rb add-node 192.168.85.158:7005 192.168.85.157:7005 

add-node是加入集群节点,192.168.85.158:7005为要加入的节点,192.168.85.157:7005 表示加入的集群的一个节点,用来辨识是哪个集群

Redis集群迁移节点 - zhm - 合肥运维


4、迁移节点solt

# redis-trib.rb check 192.168.85.157:7005

>>> Performing Cluster Check (using node 192.168.85.157:7005)

M: 8c4b95726f481c7c953da110771b1832daa1815f 192.168.85.157:7005

   slots:6484-16383 (9900 slots) master

   1 additional replica(s)

M: 1f48df22516542856bbdc874b3ddf613d7645a1d 192.168.85.158:7005

   slots: (0 slots) master

   0 additional replica(s)

S: e1094c6a1143b7ca407e0bf3e33650bad61fc089 192.168.85.157:7006

   slots: (0 slots) slave

   replicates 8c4b95726f481c7c953da110771b1832daa1815f

M: ec2cc9445ebe752434dc4922a2a6f14cead16bce 192.168.85.157:7004

   slots:0-5459 (5460 slots) master

   1 additional replica(s)

M: 3859d8f88f59fbefbb9627c252caeecd9a638bbc 192.168.85.156:7001

   slots:5460-6483 (1024 slots) master

   1 additional replica(s)

S: 922f2ab7ed7e9bd9c5c8c2b41423c327c101b57e 192.168.85.156:7002

   slots: (0 slots) slave

   replicates 3859d8f88f59fbefbb9627c252caeecd9a638bbc

S: 5a573047d926dc8b7f3665c2a3e3aec2a1e87fe1 192.168.85.156:7003

   slots: (0 slots) slave

   replicates ec2cc9445ebe752434dc4922a2a6f14cead16bce

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

Redis集群迁移节点 - zhm - 合肥运维

如上图,我们现在要从192.168.85.157:7005上迁移9900个solt到192。168.85.158:7005上去,命令如下

# redis-trib.rb reshard --from 8c4b95726f481c7c953da110771b1832daa1815f --to 1f48df22516542856bbdc874b3ddf613d7645a1d --slots 9900 --yes 192.168.85.156:7001

Redis集群迁移节点 - zhm - 合肥运维


完成之后,在次查看集群状态

Redis集群迁移节点 - zhm - 合肥运维

由上图,可见,192.168.85.157上的7005节点的solt已全部迁移到192.168.85.158上。


 5、删除空节点

删除192.168.85.157:7005空节点

redis-trib.rb del-node '192.168.85.157:7005' 8c4b95726f481c7c953da110771b1832daa1815f


 在次查看集群状态

# redis-trib.rb check 192.168.85.158:7005

Redis集群迁移节点 - zhm - 合肥运维


至此, Redis集群迁移节点迁移过程完成。


6、redis-trib.rb命令相关功能参数

create:创建集群

check:检查集群

info:查看集群信息

fix:修复集群

reshard:在线迁移slot

rebalance:平衡集群节点slot数量

add-node:将新节点加入集群

del-node:从集群中删除节点

set-timeout:设置集群节点间心跳连接的超时时间

call:在集群全部节点上执行命令

import:将外部redis数据导入集群

评论