同理 , 使用cluster nodes查看节点信息
ef24f98f9d811539ed3aa7ebd58b42c02ae11c1a 162.14.74.11:7005@17005 slave d77367d7830b4503980a14e379cb06a271906787 0 1663166631000 1 connected 5a92ba294e35f1d61e8091216c59c2fa44adfb9d 162.14.74.11:7002@17002 master - 0 1663166631175 2 connected 5461-10922 d77367d7830b4503980a14e379cb06a271906787 10.0.0.5:7001@17001 myself,master - 0 1663166628000 1 connected 0-5460 448b264edf1f697128395d8b6a656129024e2b55 162.14.74.11:7006@17006 slave 5a92ba294e35f1d61e8091216c59c2fa44adfb9d 0 1663166630173 2 connected d5004e076572b8fab64c8cc4473c298396b78823 162.14.74.11:7007@17007 master - 0 1663166632178 0 connected 841ea8438a496f02c3866fa71fc9d4271b94e946 162.14.74.11:7004@17004 slave 851c1b20f0616b60f172837e7e4bce792397d8ac 0 1663166631000 3 connected 851c1b20f0616b60f172837e7e4bce792397d8ac 162.14.74.11:7003@17003 master - 0 1663166630000 3 connected 10923-16383
可以看到 , 节点已经加入成功了 , 但是发现不像其他节点有一个connected 0-5460 。这是因为还没有分配hash操作 , 节点上没有数据 。
2.4.1、Redis数据迁移+重新分配hash槽
添加完主节点需要对主节点进行hash槽分配 , 这样该主节才可以存储数据 。
Redis数据迁移原理
文章插图
- 1、向节点B发送状态变更命令 , 将B的对应slot状态置为importing 。
- 2、向节点A发送状态变更命令 , 将A对应的slot状态置为migrating 。
- 3、向A发送migrate命令 , 告知A将要迁移的slot对应的key迁移到B 。
- 4、当所有key迁移完成后 , cluster setslot重新设置槽位 。
# 指定rehash重新分槽的命令 redis-cli --cluster reshard 162.14.74.11:7007 -a abcAbc123. # 输入hash槽数量 , 表示要分配hash槽给目标节点 How many slots do you want to move (from 1 to 16384)? 输入3000 # 输入接收槽的结点id 也就是7007节点的id 可以在前面的cluster nodes中获取 d5004e076572b8fab64c8cc4473c298396b78823 What is the receiving node ID? d5004e076572b8fab64c8cc4473c298396b78823 # 输入源结点id,这里输入all表示从其他所有节点中都分一点槽出来 Please enter all the source node IDs. Type 'all' to use all the nodes as source nodes for the hash slots. Type 'done' once you entered all the source nodes IDs. Source node #1: all # 输入yes开始移动槽到目标结点id Do you want to proceed with the proposed reshard plan (yes/no)? yes # 这些就是迁移日志 还有很多 只复制了两行 Moving slot 195 from 162.14.74.11:7001 to 162.14.74.11:7007: Moving slot 196 from 162.14.74.11:7001 to 162.14.74.11:7007: 使用cluster nodes查看
162.14.74.11:7001> cluster nodes ef24f98f9d811539ed3aa7ebd58b42c02ae11c1a 162.14.74.11:7005@17005 slave d77367d7830b4503980a14e379cb06a271906787 0 1663167613059 7 connected 5a92ba294e35f1d61e8091216c59c2fa44adfb9d 162.14.74.11:7002@17002 master - 0 1663167610000 2 connected 7687-10922 # 7001有两端槽 因为之前迁移错误 迁移到7001去了 d77367d7830b4503980a14e379cb06a271906787 10.0.0.5:7001@17001 myself,master - 0 1663167612000 7 connected 1550-6961 10923-12421 448b264edf1f697128395d8b6a656129024e2b55 162.14.74.11:7006@17006 slave 5a92ba294e35f1d61e8091216c59c2fa44adfb9d 0 1663167611053 2 connected # 这里7007有i狼三段槽 , 从7001-7003都迁移了部分过来 d5004e076572b8fab64c8cc4473c298396b78823 162.14.74.11:7007@17007 master - 0 1663167611000 8 connected 0-1549 6962-7686 12422-13146 841ea8438a496f02c3866fa71fc9d4271b94e946 162.14.74.11:7004@17004 slave 851c1b20f0616b60f172837e7e4bce792397d8ac 0 1663167612055 3 connected 851c1b20f0616b60f172837e7e4bce792397d8ac 162.14.74.11:7003@17003 master - 0 1663167608044 3 connected 13147-163832.4.2、Redis添加从节点添加7008从结点 , 将7008作为7007的从结点
放行防火墙和云服务器安全组
firewall-cmd --zone=public --add-port=7008/tcp --permanent firewall-cmd --zone=public --add-port=17008/tcp --permanent systemctl restart firewalld.service安全组略 , 需要修改腾讯云上的端口规则 。
添加从节点
# redis-cli --cluster add-node 新节点的ip和端口 旧节点ip和端口 --cluster-slave --cluster-master-id 主节点id -a 密码 redis-cli --cluster add-node 162.14.74.11:7008 162.14.74.11:7007 --cluster-slave --cluster-master-id d5004e076572b8fab64c8cc4473c298396b78823 -a abcAbc123.执行结果
root@redis1:/data# redis-cli --cluster add-node 162.14.74.11:7008 162.14.74.11:7007 --cluster-slave --cluster-master-id d5004e076572b8fab64c8cc4473c298396b78823 -a abcAbc123. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. >>> Adding node 162.14.74.11:7008 to cluster 162.14.74.11:7007 >>> Performing Cluster Check (using node 162.14.74.11:7007) M: d5004e076572b8fab64c8cc4473c298396b78823 162.14.74.11:7007 slots:[0-1549],[6962-7686],[12422-13146] (3000 slots) master S: ef24f98f9d811539ed3aa7ebd58b42c02ae11c1a 162.14.74.11:7005 slots: (0 slots) slave replicates d77367d7830b4503980a14e379cb06a271906787 S: 841ea8438a496f02c3866fa71fc9d4271b94e946 162.14.74.11:7004 slots: (0 slots) slave replicates 851c1b20f0616b60f172837e7e4bce792397d8ac M: 5a92ba294e35f1d61e8091216c59c2fa44adfb9d 162.14.74.11:7002 slots:[7687-10922] (3236 slots) master 1 additional replica(s) M: 851c1b20f0616b60f172837e7e4bce792397d8ac 162.14.74.11:7003 slots:[13147-16383] (3237 slots) master 1 additional replica(s) S: 448b264edf1f697128395d8b6a656129024e2b55 162.14.74.11:7006 slots: (0 slots) slave replicates 5a92ba294e35f1d61e8091216c59c2fa44adfb9d M: d77367d7830b4503980a14e379cb06a271906787 162.14.74.11:7001 slots:[1550-6961],[10923-12421] (6911 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. >>> Send CLUSTER MEET to node 162.14.74.11:7008 to make it join the cluster. Waiting for the cluster to join >>> Configure node as replica of 162.14.74.11:7007. [OK] New node added correctly.
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Redis 的大 Key 对持久化有什么影响?
- 手机防窥膜的原理是什么?真的会影响视力吗?
- 碘酒消毒的原理是什么?
- 三大指纹识别原理 指纹识别技术
- 玄空风水原理和方法 大玄空风水
- 图解涡轮增压器工作原理 涡轮增压器工作原理
- 跳绳减肥原理是什么
- 瘦身舞蹈瘦腿的原理是什么?
- 详解反渗透膜(RO 反渗透膜原理工作原理)
- 精索静脉曲张手术原理
