[root@localhost ~]# /data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL -p 46379 -h 192.168.222.131 CLUSTER NODES
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
a2b16bfa39fafe9b536ac6c952ae2dec58a8e35e 192.168.222.133:46379@56379 master - 017326987818247 connected 10923-16383
c6927c5de96959a24d04defe1227ca338089219e 192.168.222.131:46379@56379 myself,master - 017326987810001 connected 0-5460
964f27d3abd421ce99d6814cbc33f7efc3bd473d 192.168.222.132:46379@56379 master - 017326987795134 connected 5461-10922
4870524e9a47506996015387ea67e6491dd3adac 192.168.222.131:46380@56380 slave a2b16bfa39fafe9b536ac6c952ae2dec58a8e35e 017326987815227 connected
4891c05297daa8e310ac616d159b444d54ba7b51 192.168.222.132:46381@56381 slave a2b16bfa39fafe9b536ac6c952ae2dec58a8e35e 017326987805177 connected
0b88544c661dafef8f79c5204a5f6d7a8abde20b 192.168.222.133:46380@56380 slave c6927c5de96959a24d04defe1227ca338089219e 017326987808191 connected
bf5549f442b6c096efda3c97472813fdfd1338f3 192.168.222.132:46380@56380 slave c6927c5de96959a24d04defe1227ca338089219e 017326987800001 connected
b4e716e733cfbe3b61130981fe479f9b38ba2f1e 192.168.222.131:46381@56381 slave 964f27d3abd421ce99d6814cbc33f7efc3bd473d 017326987805174 connected
504cbbeb8a73512127a1566ac91f846145b11a58 192.168.222.133:46381@56381 slave 964f27d3abd421ce99d6814cbc33f7efc3bd473d 017326987810004 connected
数据写入测试
# cat write-data-redis.py from rediscluster import RedisCluster
# 启动节点列表
startup_nodes =[{"host":"192.168.222.131","port":"46379"}]# 创建集群连接
rc = RedisCluster(startup_nodes=startup_nodes, decode_responses=True, password='F3EE4Dk44ddDSLKL')# 写入数据for i inrange(100):# 例如,写入的数据
data_size_kb =1
data ='kjasjkldfjalsdflasdflasdfjllkasjdflasf'*(data_size_kb *1024*1024)
rc.set(f'key:{i}', data)print(f'Written key:{i} with {data_size_kb}KB of data')print("Data written.")# python3 write-data-redis.py
主机内存查看
[root@localhost ~]# free -h
total used free shared buff/cache available
Mem: 7.8G 2.2G 5.5G 11M 120M 5.4G
Swap: 3.6G 0B 3.6G
节点信息查询
# 连接集群
/data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL -c-p46379-h192.168.222.131
# 监控redis服务器的性能
/data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL -p46379-h192.168.222.131 --stat# 获取服务器的统计信息
/data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL -p46379-h192.168.222.131 INFO
# 检查集群状态
/data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL -p46379-h192.168.222.131 CLUSTER INFO
# 检查集群节点信息
/data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL -p46379-h192.168.222.131 CLUSTER NODES
# 添加主节点
/data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL --cluster add-node 192.168.222.134:46379 192.168.222.131:46379
# 查询主节点id[root@localhost ~]# /data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL -p 46379 -h 192.168.222.131 CLUSTER NODES |grep 134
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
7e4645f509d071be565d53f7167464456f869094 192.168.222.134:46379@56379 master - 017326991380000 connected
# 添加从节点
/data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL --cluster add-node 192.168.222.134:46380 192.168.222.131:46379 --cluster-slave --cluster-master-id 7e4645f509d071be565d53f7167464456f869094
/data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL --cluster add-node 192.168.222.134:46381 192.168.222.131:46379 --cluster-slave --cluster-master-id 7e4645f509d071be565d53f7167464456f869094
# 添加主节点
/data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL --cluster add-node 192.168.222.135:46379 192.168.222.131:46379
# 查询主节点id[root@localhost ~]# /data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL -p 46379 -h 192.168.222.131 CLUSTER NODES |grep 135
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
68520244e77a3a69122816496f5c9773b50e5277 192.168.222.135:46379@56379 master - 0173269923711011 connected
# 添加从节点
/data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL --cluster add-node 192.168.222.135:46380 192.168.222.131:46379 --cluster-slave --cluster-master-id 68520244e77a3a69122816496f5c9773b50e5277
/data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL --cluster add-node 192.168.222.135:46381 192.168.222.131:46379 --cluster-slave --cluster-master-id 68520244e77a3a69122816496f5c9773b50e5277
# 添加主节点
/data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL --cluster add-node 192.168.222.136:46379 192.168.222.131:46379
# 查询主节点id[root@localhost ~]# /data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL -p 46379 -h 192.168.222.131 CLUSTER NODES |grep 136
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
fa79672847de00a6590a0ebb2ee7d93b5ca11c82 192.168.222.136:46379@56379 master - 017326993059710 connected
# 添加从节点
/data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL --cluster add-node 192.168.222.136:46380 192.168.222.131:46379 --cluster-slave --cluster-master-id fa79672847de00a6590a0ebb2ee7d93b5ca11c82
/data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL --cluster add-node 192.168.222.136:46381 192.168.222.131:46379 --cluster-slave --cluster-master-id fa79672847de00a6590a0ebb2ee7d93b5ca11c82
[root@localhost ~]# /data/redis/redis-stack-server-7.2.0-v8/bin/redis-cli -a F3EE4Dk44ddDSLKL --cluster reshard 192.168.222.131:46379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node192.168.222.131:46379)
M: c6927c5de96959a24d04defe1227ca338089219e 192.168.222.131:46379
slots:[0-5460](5461 slots) master
2 additional replica(s)...........
[OK] All nodes agree about slots configuration.
>>> Check foropen slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 2730
What is the receiving node ID? 7e4645f509d071be565d53f7167464456f869094
Please enter all the sourcenode 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: c6927c5de96959a24d04defe1227ca338089219e
Source node#2: done...........
Moving slot 2729 from c6927c5de96959a24d04defe1227ca338089219e
Do you want to proceed with the proposed reshard plan (yes/no)? yes...........
Moving slot 2729 from 192.168.222.131:46379 to 192.168.222.134:46379: