2019-07-05 redis 工具扩容、收缩节点

redis 工具扩容节点

1.在db01上创建新节点

mkdir -p /opt/redis_cluster/redis_{6390,6391}/{conf,logs,pid}

mkdir -p /data/redis_cluster/redis_{6390,6391}

cd /opt/redis_cluster/

cp redis_6380/conf/redis_6380.conf redis_6390/conf/redis_6390.conf

cp redis_6380/conf/redis_6380.conf redis_6391/conf/redis_6391.conf

sed -i 's#6380#6390#g' redis_6390/conf/redis_6390.conf

sed -i 's#6380#6391#g' redis_6391/conf/redis_6391.conf

2.在db01上启动新节点

sh /server/scripts/redis_shell.sh start 6390

sh /server/scripts/redis_shell.sh start 6391

3.使用工具发现节点并重新分配槽位

cd /opt/redis_cluster/redis/src/

./redis-trib.rb add-node 10.0.0.51:6390 10.0.0.51:6380

./redis-trib.rb add-node 10.0.0.51:6391 10.0.0.51:6380

./redis-trib.rb reshard 10.0.0.51:6380

4.扩容过程

#输入需要迁移多少个槽位
How many slots do you want to move (from 1 to 16384)? XXXX

#需要接收槽位的节点ID
What is the receiving node ID? XXXX

#需要迁移的节点ID(all全部)
Source node #1:all

#是否确认
Do you want to proceed with the proposed reshard plan (yes/no)? yes

#登陆查看
[root@db01 ]# sh /server/scripts/redis_shell.sh login 6390
10.0.0.51:6390> CLUSTER NODES

10.0.0.51:6390> CLUSTER INFO

#重新做主从关系(教学实例)
先做db03的6381复制db01的6390
再做db01的6391复制db01的6380

#确认和测试


redis 工具收缩节点

1.进入脚本目录

cd /opt/redis_cluster/redis/src/

./redis-trib.rb reshard 10.0.0.51:6391

2.收缩过程

#输入要迁移的槽数
How many slots do you want to move (from 1 to 16384)? XXXX

#需要接收槽位的节点ID
What is the receiving node ID? XXXX

#需要迁移的节点ID
Source node #1:XXXX
Source node #2:done

#是否确认
Do you want to proceed with the proposed reshard plan (yes/no)? yes

#登陆查看
[root@db01 ]# sh /server/scripts/redis_shell.sh login 6380
10.0.0.51:6380> CLUSTER NODES

10.0.0.51:6380> CLUSTER INFO

#输入源节点的ID
1.xxxxx 
2.done

#输入确认
yes

#工具删除节点
cd /opt/redis_cluster/redis/src/
./redis-trib.rb del-node 10.0.0.51:6390 ca07d35324306f7f035d598e76427a04523f08ec
./redis-trib.rb del-node 10.0.0.51:6391 cad275c00c314aad7e71e4ccd90b550a8ae1b515

3.数据导入导出工具

1.安装工具
cd /opt/redis_cluster/
git clone https://github.com/vipshop/redis-migrate-tool.git
cd redis-migrate-tool/
autoreconf -fvi
./configure
make && make install 


2.生成配置文件
cat > redis_6379_to_6380.conf  <

4.分析占用空间比较大的键

需求背景
redis的内存使用太大键值太多,不知道哪些键值占用的容量比较大,而且在线分析会影响性能.

安装工具
yum install python-pip gcc
pip install --upgrade pip
pip install rdbtools

使用方法
cd /data/redis_cluster/redis_6379/
rdb -c memory redis_6379.rdb -f 6379_memory.csv

分析rdb
awk -F ',' '{print $4,$2,$3,$1}' 6379_memory.csv |sort  > 6379.sort

你可能感兴趣的:(2019-07-05 redis 工具扩容、收缩节点)