目錄
專案GitHub網址: https://github.com/tair-opensource/RedisShake
使用這個版本: https://github.com/tair-opensource/RedisShake/releases/tag/v4.0.2
Redis Cluster主機IP表
主機名稱 | 主機IP | 角色 | 主機IP | 角色 | 跟隨 |
redis91 | 192.168.1.91:6379 | master | 192.168.1.91:6380 | slave | 192.168.1.92:6380 |
redis92 | 192.168.1.92:6379 | master | 192.168.1.92:6380 | slave | 192.168.1.93:6380 |
redis93 | 192.168.1.93:6379 | master | 192.168.1.93:6380 | slave | 192.168.1.91:6380 |
redis94 | 192.168.1.94:6379 | master | 192.168.1.94:6380 | slave | 192.168.1.98:6380 |
redis98 | 192.168.1.98:6379 | master | 192.168.1.98:6380 | slave | 192.168.1.94:6380 |
Golang安裝
[root@redis91 ~]# sudo tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz
[root@redis91 ~]# sudo vim /etc/profile
# 加到最後面
export PATH=$PATH:/usr/local/go/bin
[root@redis91 ~]# source /etc/profile
[root@redis91 ~]# go version
go version go1.21.5 linux/amd64
Redis-Shake設定
創建工作目錄,解壓redis-shake包
# 創建工作目錄
[root@redis91 ~]# mkdir redis-shake
[root@redis91 ~]# sudo tar -C ./redis-shake -xzvf redis-shake-linux-amd64.tar.gz
./redis-shake
./shake.toml
[root@redis91 ~]# cd redis-shake
[root@redis91 redis-shake]# ls -l
總計 11212
-rwxr-xr-x 1 1001 127 11473016 10月 11 19:52 redis-shake
-rw-r--r-- 1 1001 127 2927 10月 11 19:52 shake.toml
創建dumprdbfile目錄,解壓要恢復數據的dump.rdb包,總共五個dump-master1.rdb、dump-master2.rdb、dump-master3.rdb、dump-master4.rdb、dump-master5.rdb
[root@redis91 redis-shake]# mkdir dumprdbfile
[root@redis91 redis-shake]# ll
總計 11212
drwxr-xr-x 2 root root 6 12月 17 19:55 dumprdbfile
-rwxr-xr-x 1 1001 127 11473016 10月 11 19:52 redis-shake
-rw-r--r-- 1 1001 127 2927 10月 11 19:52 shake.toml
[root@redis91 redis-shake]# cd dumprdbfile/
[root@redis91 dumprdbfile]# ls -l
總計 1256064
-rw-r--r-- 1 root root 255824392 12月 17 19:56 redis-master1_dump_rdb.tar.gz
-rw-r--r-- 1 root root 253817683 12月 17 19:56 redis-master2_dump_rdb.tar.gz
-rw-r--r-- 1 root root 254657334 12月 17 19:56 redis-master3_dump_rdb.tar.gz
-rw-r--r-- 1 root root 254929776 12月 17 19:56 redis-master4_dump_rdb.tar.gz
-rw-r--r-- 1 root root 266967631 12月 17 19:56 redis-master5_dump_rdb.tar.gz
[root@redis91 dumprdbfile]# tar -xzvf redis-master1_dump_rdb.tar.gz -O dump.rdb > dump-master1.rdb
[root@redis91 dumprdbfile]# tar -xzvf redis-master2_dump_rdb.tar.gz -O dump.rdb > dump-master2.rdb
[root@redis91 dumprdbfile]# tar -xzvf redis-master3_dump_rdb.tar.gz -O dump.rdb > dump-master3.rdb
[root@redis91 dumprdbfile]# tar -xzvf redis-master4_dump_rdb.tar.gz -O dump.rdb > dump-master4.rdb
[root@redis91 dumprdbfile]# tar -xzvf redis-master5_dump_rdb.tar.gz -O dump.rdb > dump-master5.rdb
[root@redis91 dumprdbfile]# ls -l
總計 3014796
-rw-r--r-- 1 root root 343630318 12月 17 20:03 dump-master1.rdb
-rw-r--r-- 1 root root 348759548 12月 17 20:04 dump-master2.rdb
-rw-r--r-- 1 root root 349938872 12月 17 20:04 dump-master3.rdb
-rw-r--r-- 1 root root 402484559 12月 17 20:04 dump-master4.rdb
-rw-r--r-- 1 root root 356118026 12月 17 20:04 dump-master5.rdb
-rw-r--r-- 1 root root 255824392 12月 17 19:56 redis-master1_dump_rdb.tar.gz
-rw-r--r-- 1 root root 253817683 12月 17 19:56 redis-master2_dump_rdb.tar.gz
-rw-r--r-- 1 root root 254657334 12月 17 19:56 redis-master3_dump_rdb.tar.gz
-rw-r--r-- 1 root root 254929776 12月 17 19:56 redis-master4_dump_rdb.tar.gz
-rw-r--r-- 1 root root 266967631 12月 17 19:56 redis-master5_dump_rdb.tar.gz
編輯redis-shake設定檔
[root@redis91 redis-shake]# vim shake.toml
# 填寫要恢復數據的rdb檔案位置
[rdb_reader]
filepath = "/root/redis-shake/dumprdbfile/dump-master1.rdb"
# 填寫cluster其中一台master的ip,連接redis有帳號密碼,也要填上
[redis_writer]
cluster = true # set to true if target is a redis cluster
address = "192.168.1.91:6379" # when cluster is true, set address to one of the cluster node
username = "帳號" # keep empty if not using ACL
password = "密碼" # keep empty if no authentication is required
tls = false
Redis-Shake開始恢復數據
恢復dump-master1,rdb數據
開始恢復dump-master1.rdb數據至cluster
[root@redis91 redis-shake]# ./redis-shake shake.toml
Usage: redis-shake [config file]
Example:
redis-shake sync.toml # load config from sync.toml
redis-shake # load config from environment variables
[root@redis91 redis-shake]# ./redis-shake shake.toml
2023-12-17 20:16:47 INF load config from file: shake.toml
2023-12-17 20:16:47 INF log_level: [info], log_file: [/root/redis-shake/data/shake.log]
2023-12-17 20:16:47 INF changed work dir to [/root/redis-shake/data]
2023-12-17 20:16:47 INF GOMAXPROCS defaults to the value of runtime.NumCPU [8]
2023-12-17 20:16:47 INF not set pprof port
2023-12-17 20:16:47 INF no function script
2023-12-17 20:16:47 INF create RdbReader: /root/redis-shake/dumprdbfile/dump-master1.rdb
2023-12-17 20:16:47 INF redisClusterWriter load cluster nodes. line=2c05c930c506e54ebea35f8f0b731754cd44082a 192.168.1.91:6379@16379 myself,master - 0 1702815406000 1 connected 0-3276
2023-12-17 20:16:47 INF redisClusterWriter load cluster nodes. line=c40f72b0ee3ac4be0b9ddaea4d16079f723e13bf 192.168.1.98:6379@16379 master - 0 1702815406361 5 connected 13107-16383
2023-12-17 20:16:47 INF redisClusterWriter load cluster nodes. line=71d88e302c0a7ec240cbbb6f8380786d01da984c 192.168.1.92:6379@16379 master - 0 1702815405000 2 connected 3277-6553
2023-12-17 20:16:47 INF redisClusterWriter load cluster nodes. line=caa1fb6b5fbc4e133b5ef472e2def11e836481f7 192.168.1.93:6379@16379 master - 0 1702815403000 3 connected 6554-9829
2023-12-17 20:16:47 INF redisClusterWriter load cluster nodes. line=eaeb50d0d31025f1589b7c8cdc12867f7a474c24 192.168.1.94:6379@16379 master - 0 1702815405357 4 connected 9830-13106
2023-12-17 20:16:47 INF redisClusterWriter connected to redis cluster successful. addresses=[192.168.1.91:6379 192.168.1.98:6379 192.168.1.92:6379 192.168.1.93:6379 192.168.1.94:6379]
2023-12-17 20:16:47 INF create RedisClusterWriter: 192.168.1.91:6379
2023-12-17 20:16:47 INF not set status port
2023-12-17 20:16:47 INF start syncing...
2023-12-17 20:16:47 INF [rdb_reader] start read
2023-12-17 20:16:52 INF read_count=[298147], read_ops=[62121.63], write_count=[298146], write_ops=[62121.63], [rdb_reader] rdb file synced: 51.78%
2023-12-17 20:16:54 INF [rdb_reader] rdb file parse done
2023-12-17 20:16:54 INF all done
檢查一下,恢復數據後,數據分布和集群slot狀況
[root@redis91 redis-shake]# redis-cli --user 帳號 --pass 密碼 --cluster check 192.168.1.91:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.1.91:6379 (2c05c930...) -> 327164 keys | 3277 slots | 1 slaves.
192.168.1.98:6379 (c40f72b0...) -> 0 keys | 3277 slots | 1 slaves.
192.168.1.92:6379 (71d88e30...) -> 108611 keys | 3277 slots | 1 slaves.
192.168.1.93:6379 (caa1fb6b...) -> 0 keys | 3276 slots | 1 slaves.
192.168.1.94:6379 (eaeb50d0...) -> 0 keys | 3277 slots | 1 slaves.
[OK] 435775 keys in 5 masters.
26.60 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.1.91:6379)
M: 2c05c930c506e54ebea35f8f0b731754cd44082a 192.168.1.91:6379
slots:[0-3276] (3277 slots) master
1 additional replica(s)
S: 1709189e2036c2e0c4168189be9074d66bce2991 192.168.1.92:6380
slots: (0 slots) slave
replicates 2c05c930c506e54ebea35f8f0b731754cd44082a
M: c40f72b0ee3ac4be0b9ddaea4d16079f723e13bf 192.168.1.98:6379
slots:[13107-16383] (3277 slots) master
1 additional replica(s)
M: 71d88e302c0a7ec240cbbb6f8380786d01da984c 192.168.1.92:6379
slots:[3277-6553] (3277 slots) master
1 additional replica(s)
M: caa1fb6b5fbc4e133b5ef472e2def11e836481f7 192.168.1.93:6379
slots:[6554-9829] (3276 slots) master
1 additional replica(s)
S: 500ed38b799c6d5ad13483f8e0fee45fc9142d69 192.168.1.94:6380
slots: (0 slots) slave
replicates c40f72b0ee3ac4be0b9ddaea4d16079f723e13bf
S: 533669750790e904050e917657beae942185a407 192.168.1.91:6380
slots: (0 slots) slave
replicates caa1fb6b5fbc4e133b5ef472e2def11e836481f7
S: b0bff6695a1318da9a01af2550c85de1e8e81a83 192.168.1.93:6380
slots: (0 slots) slave
replicates 71d88e302c0a7ec240cbbb6f8380786d01da984c
M: eaeb50d0d31025f1589b7c8cdc12867f7a474c24 192.168.1.94:6379
slots:[9830-13106] (3277 slots) master
1 additional replica(s)
S: 2b487243e0c78adb93ac73017d04a6ad39b51c36 192.168.1.98:6380
slots: (0 slots) slave
replicates eaeb50d0d31025f1589b7c8cdc12867f7a474c24
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
恢復dump-master2,rdb數據
# 修改要恢復數據的rdb檔案位置
[root@redis91 redis-shake]# vim shake.toml
[rdb_reader]
filepath = "/root/redis-shake/dumprdbfile/dump-master2.rdb"
開始恢復dump-master2.rdb數據至cluster
[root@redis91 redis-shake]# ./redis-shake shake.toml
2023-12-17 20:18:45 INF load config from file: shake.toml
2023-12-17 20:18:45 INF log_level: [info], log_file: [/root/redis-shake/data/shake.log]
2023-12-17 20:18:45 INF changed work dir to [/root/redis-shake/data]
2023-12-17 20:18:45 INF GOMAXPROCS defaults to the value of runtime.NumCPU [8]
2023-12-17 20:18:45 INF not set pprof port
2023-12-17 20:18:45 INF no function script
2023-12-17 20:18:45 INF create RdbReader: /root/redis-shake/dumprdbfile/dump-master2.rdb
2023-12-17 20:18:45 INF redisClusterWriter load cluster nodes. line=2c05c930c506e54ebea35f8f0b731754cd44082a 192.168.1.91:6379@16379 myself,master - 0 1702815523000 1 connected 0-3276
2023-12-17 20:18:45 INF redisClusterWriter load cluster nodes. line=c40f72b0ee3ac4be0b9ddaea4d16079f723e13bf 192.168.1.98:6379@16379 master - 0 1702815524860 5 connected 13107-16383
2023-12-17 20:18:45 INF redisClusterWriter load cluster nodes. line=71d88e302c0a7ec240cbbb6f8380786d01da984c 192.168.1.92:6379@16379 master - 0 1702815521000 2 connected 3277-6553
2023-12-17 20:18:45 INF redisClusterWriter load cluster nodes. line=caa1fb6b5fbc4e133b5ef472e2def11e836481f7 192.168.1.93:6379@16379 master - 0 1702815523000 3 connected 6554-9829
2023-12-17 20:18:45 INF redisClusterWriter load cluster nodes. line=eaeb50d0d31025f1589b7c8cdc12867f7a474c24 192.168.1.94:6379@16379 master - 0 1702815522000 4 connected 9830-13106
2023-12-17 20:18:45 INF redisClusterWriter connected to redis cluster successful. addresses=[192.168.1.91:6379 192.168.1.98:6379 192.168.1.92:6379 192.168.1.93:6379 192.168.1.94:6379]
2023-12-17 20:18:45 INF create RedisClusterWriter: 192.168.1.91:6379
2023-12-17 20:18:45 INF not set status port
2023-12-17 20:18:45 INF start syncing...
2023-12-17 20:18:45 INF [rdb_reader] start read
2023-12-17 20:18:50 INF read_count=[301839], read_ops=[62949.67], write_count=[301838], write_ops=[62949.67], [rdb_reader] rdb file synced: 69.52%
2023-12-17 20:18:52 INF [rdb_reader] rdb file parse done
2023-12-17 20:18:52 INF all done
檢查一下,恢復數據後,數據分布和集群slot狀況
[root@redis91 redis-shake]# redis-cli --user 帳號 --pass 密碼 --cluster check 192.168.1.91:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.1.91:6379 (2c05c930...) -> 327164 keys | 3277 slots | 1 slaves.
192.168.1.98:6379 (c40f72b0...) -> 0 keys | 3277 slots | 1 slaves.
192.168.1.92:6379 (71d88e30...) -> 326861 keys | 3277 slots | 1 slaves.
192.168.1.93:6379 (caa1fb6b...) -> 218263 keys | 3276 slots | 1 slaves.
192.168.1.94:6379 (eaeb50d0...) -> 0 keys | 3277 slots | 1 slaves.
[OK] 872288 keys in 5 masters.
53.24 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.1.91:6379)
M: 2c05c930c506e54ebea35f8f0b731754cd44082a 192.168.1.91:6379
slots:[0-3276] (3277 slots) master
1 additional replica(s)
S: 1709189e2036c2e0c4168189be9074d66bce2991 192.168.1.92:6380
slots: (0 slots) slave
replicates 2c05c930c506e54ebea35f8f0b731754cd44082a
M: c40f72b0ee3ac4be0b9ddaea4d16079f723e13bf 192.168.1.98:6379
slots:[13107-16383] (3277 slots) master
1 additional replica(s)
M: 71d88e302c0a7ec240cbbb6f8380786d01da984c 192.168.1.92:6379
slots:[3277-6553] (3277 slots) master
1 additional replica(s)
M: caa1fb6b5fbc4e133b5ef472e2def11e836481f7 192.168.1.93:6379
slots:[6554-9829] (3276 slots) master
1 additional replica(s)
S: 500ed38b799c6d5ad13483f8e0fee45fc9142d69 192.168.1.94:6380
slots: (0 slots) slave
replicates c40f72b0ee3ac4be0b9ddaea4d16079f723e13bf
S: 533669750790e904050e917657beae942185a407 192.168.1.91:6380
slots: (0 slots) slave
replicates caa1fb6b5fbc4e133b5ef472e2def11e836481f7
S: b0bff6695a1318da9a01af2550c85de1e8e81a83 192.168.1.93:6380
slots: (0 slots) slave
replicates 71d88e302c0a7ec240cbbb6f8380786d01da984c
M: eaeb50d0d31025f1589b7c8cdc12867f7a474c24 192.168.1.94:6379
slots:[9830-13106] (3277 slots) master
1 additional replica(s)
S: 2b487243e0c78adb93ac73017d04a6ad39b51c36 192.168.1.98:6380
slots: (0 slots) slave
replicates eaeb50d0d31025f1589b7c8cdc12867f7a474c24
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
恢復dump-master3,rdb數據
# 修改要恢復數據的rdb檔案位置
[root@redis91 redis-shake]# vim shake.toml
[rdb_reader]
filepath = "/root/redis-shake/dumprdbfile/dump-master3.rdb"
開始恢復dump-master3.rdb數據至cluster
[root@redis91 redis-shake]# ./redis-shake shake.toml
2023-12-17 20:20:39 INF load config from file: shake.toml
2023-12-17 20:20:39 INF log_level: [info], log_file: [/root/redis-shake/data/shake.log]
2023-12-17 20:20:39 INF changed work dir to [/root/redis-shake/data]
2023-12-17 20:20:39 INF GOMAXPROCS defaults to the value of runtime.NumCPU [8]
2023-12-17 20:20:39 INF not set pprof port
2023-12-17 20:20:39 INF no function script
2023-12-17 20:20:39 INF create RdbReader: /root/redis-shake/dumprdbfile/dump-master3.rdb
2023-12-17 20:20:39 INF redisClusterWriter load cluster nodes. line=2c05c930c506e54ebea35f8f0b731754cd44082a 192.168.1.91:6379@16379 myself,master - 0 1702815636000 1 connected 0-3276
2023-12-17 20:20:39 INF redisClusterWriter load cluster nodes. line=c40f72b0ee3ac4be0b9ddaea4d16079f723e13bf 192.168.1.98:6379@16379 master - 0 1702815635243 5 connected 13107-16383
2023-12-17 20:20:39 INF redisClusterWriter load cluster nodes. line=71d88e302c0a7ec240cbbb6f8380786d01da984c 192.168.1.92:6379@16379 master - 0 1702815636000 2 connected 3277-6553
2023-12-17 20:20:39 INF redisClusterWriter load cluster nodes. line=caa1fb6b5fbc4e133b5ef472e2def11e836481f7 192.168.1.93:6379@16379 master - 0 1702815638000 3 connected 6554-9829
2023-12-17 20:20:39 INF redisClusterWriter load cluster nodes. line=eaeb50d0d31025f1589b7c8cdc12867f7a474c24 192.168.1.94:6379@16379 master - 0 1702815639056 4 connected 9830-13106
2023-12-17 20:20:39 INF redisClusterWriter connected to redis cluster successful. addresses=[192.168.1.91:6379 192.168.1.98:6379 192.168.1.92:6379 192.168.1.93:6379 192.168.1.94:6379]
2023-12-17 20:20:39 INF create RedisClusterWriter: 192.168.1.91:6379
2023-12-17 20:20:39 INF not set status port
2023-12-17 20:20:39 INF start syncing...
2023-12-17 20:20:39 INF [rdb_reader] start read
2023-12-17 20:20:44 INF read_count=[335689], read_ops=[82529.84], write_count=[335689], write_ops=[82529.84], [rdb_reader] rdb file synced: 57.47%
2023-12-17 20:20:45 INF [rdb_reader] rdb file parse done
2023-12-17 20:20:45 INF all done
檢查一下,恢復數據後,數據分布和集群slot狀況
[root@redis91 redis-shake]# redis-cli --user 帳號 --pass 密碼 --cluster check 192.168.1.91:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.1.91:6379 (2c05c930...) -> 327164 keys | 3277 slots | 1 slaves.
192.168.1.98:6379 (c40f72b0...) -> 0 keys | 3277 slots | 1 slaves.
192.168.1.92:6379 (71d88e30...) -> 326860 keys | 3277 slots | 1 slaves.
192.168.1.93:6379 (caa1fb6b...) -> 327959 keys | 3276 slots | 1 slaves.
192.168.1.94:6379 (eaeb50d0...) -> 327538 keys | 3277 slots | 1 slaves.
[OK] 1309521 keys in 5 masters.
79.93 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.1.91:6379)
M: 2c05c930c506e54ebea35f8f0b731754cd44082a 192.168.1.91:6379
slots:[0-3276] (3277 slots) master
1 additional replica(s)
S: 1709189e2036c2e0c4168189be9074d66bce2991 192.168.1.92:6380
slots: (0 slots) slave
replicates 2c05c930c506e54ebea35f8f0b731754cd44082a
M: c40f72b0ee3ac4be0b9ddaea4d16079f723e13bf 192.168.1.98:6379
slots:[13107-16383] (3277 slots) master
1 additional replica(s)
M: 71d88e302c0a7ec240cbbb6f8380786d01da984c 192.168.1.92:6379
slots:[3277-6553] (3277 slots) master
1 additional replica(s)
M: caa1fb6b5fbc4e133b5ef472e2def11e836481f7 192.168.1.93:6379
slots:[6554-9829] (3276 slots) master
1 additional replica(s)
S: 500ed38b799c6d5ad13483f8e0fee45fc9142d69 192.168.1.94:6380
slots: (0 slots) slave
replicates c40f72b0ee3ac4be0b9ddaea4d16079f723e13bf
S: 533669750790e904050e917657beae942185a407 192.168.1.91:6380
slots: (0 slots) slave
replicates caa1fb6b5fbc4e133b5ef472e2def11e836481f7
S: b0bff6695a1318da9a01af2550c85de1e8e81a83 192.168.1.93:6380
slots: (0 slots) slave
replicates 71d88e302c0a7ec240cbbb6f8380786d01da984c
M: eaeb50d0d31025f1589b7c8cdc12867f7a474c24 192.168.1.94:6379
slots:[9830-13106] (3277 slots) master
1 additional replica(s)
S: 2b487243e0c78adb93ac73017d04a6ad39b51c36 192.168.1.98:6380
slots: (0 slots) slave
replicates eaeb50d0d31025f1589b7c8cdc12867f7a474c24
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
恢復dump-master4,rdb數據
# 修改要恢復數據的rdb檔案位置
[root@redis91 redis-shake]# vim shake.toml
[rdb_reader]
filepath = "/root/redis-shake/dumprdbfile/dump-master4.rdb"
開始恢復dump-master4.rdb數據至cluster
[root@redis91 redis-shake]# ./redis-shake shake.toml
2023-12-17 20:21:39 INF load config from file: shake.toml
2023-12-17 20:21:39 INF log_level: [info], log_file: [/root/redis-shake/data/shake.log]
2023-12-17 20:21:39 INF changed work dir to [/root/redis-shake/data]
2023-12-17 20:21:39 INF GOMAXPROCS defaults to the value of runtime.NumCPU [8]
2023-12-17 20:21:39 INF not set pprof port
2023-12-17 20:21:39 INF no function script
2023-12-17 20:21:39 INF create RdbReader: /root/redis-shake/dumprdbfile/dump-master4.rdb
2023-12-17 20:21:39 INF redisClusterWriter load cluster nodes. line=2c05c930c506e54ebea35f8f0b731754cd44082a 192.168.1.91:6379@16379 myself,master - 0 1702815696000 1 connected 0-3276
2023-12-17 20:21:39 INF redisClusterWriter load cluster nodes. line=c40f72b0ee3ac4be0b9ddaea4d16079f723e13bf 192.168.1.98:6379@16379 master - 0 1702815695487 5 connected 13107-16383
2023-12-17 20:21:39 INF redisClusterWriter load cluster nodes. line=71d88e302c0a7ec240cbbb6f8380786d01da984c 192.168.1.92:6379@16379 master - 0 1702815699501 2 connected 3277-6553
2023-12-17 20:21:39 INF redisClusterWriter load cluster nodes. line=caa1fb6b5fbc4e133b5ef472e2def11e836481f7 192.168.1.93:6379@16379 master - 0 1702815695000 3 connected 6554-9829
2023-12-17 20:21:39 INF redisClusterWriter load cluster nodes. line=eaeb50d0d31025f1589b7c8cdc12867f7a474c24 192.168.1.94:6379@16379 master - 0 1702815697000 4 connected 9830-13106
2023-12-17 20:21:39 INF redisClusterWriter connected to redis cluster successful. addresses=[192.168.1.91:6379 192.168.1.98:6379 192.168.1.92:6379 192.168.1.93:6379 192.168.1.94:6379]
2023-12-17 20:21:39 INF create RedisClusterWriter: 192.168.1.91:6379
2023-12-17 20:21:39 INF not set status port
2023-12-17 20:21:39 INF start syncing...
2023-12-17 20:21:39 INF [rdb_reader] start read
2023-12-17 20:21:44 INF read_count=[219205], read_ops=[48733.57], write_count=[219204], write_ops=[48733.57], [rdb_reader] rdb file synced: 53.23%
2023-12-17 20:21:48 INF [rdb_reader] rdb file parse done
2023-12-17 20:21:48 INF all done
檢查一下,恢復數據後,數據分布和集群slot狀況
[root@redis91 redis-shake]# redis-cli --user 帳號 --pass 密碼 --cluster check 192.168.1.91:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.1.91:6379 (2c05c930...) -> 437387 keys | 3277 slots | 1 slaves.
192.168.1.98:6379 (c40f72b0...) -> 149 keys | 3277 slots | 1 slaves.
192.168.1.92:6379 (71d88e30...) -> 437074 keys | 3277 slots | 1 slaves.
192.168.1.93:6379 (caa1fb6b...) -> 437832 keys | 3276 slots | 1 slaves.
192.168.1.94:6379 (eaeb50d0...) -> 437593 keys | 3277 slots | 1 slaves.
[OK] 1750035 keys in 5 masters.
106.81 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.1.91:6379)
M: 2c05c930c506e54ebea35f8f0b731754cd44082a 192.168.1.91:6379
slots:[0-3276] (3277 slots) master
1 additional replica(s)
S: 1709189e2036c2e0c4168189be9074d66bce2991 192.168.1.92:6380
slots: (0 slots) slave
replicates 2c05c930c506e54ebea35f8f0b731754cd44082a
M: c40f72b0ee3ac4be0b9ddaea4d16079f723e13bf 192.168.1.98:6379
slots:[13107-16383] (3277 slots) master
1 additional replica(s)
M: 71d88e302c0a7ec240cbbb6f8380786d01da984c 192.168.1.92:6379
slots:[3277-6553] (3277 slots) master
1 additional replica(s)
M: caa1fb6b5fbc4e133b5ef472e2def11e836481f7 192.168.1.93:6379
slots:[6554-9829] (3276 slots) master
1 additional replica(s)
S: 500ed38b799c6d5ad13483f8e0fee45fc9142d69 192.168.1.94:6380
slots: (0 slots) slave
replicates c40f72b0ee3ac4be0b9ddaea4d16079f723e13bf
S: 533669750790e904050e917657beae942185a407 192.168.1.91:6380
slots: (0 slots) slave
replicates caa1fb6b5fbc4e133b5ef472e2def11e836481f7
S: b0bff6695a1318da9a01af2550c85de1e8e81a83 192.168.1.93:6380
slots: (0 slots) slave
replicates 71d88e302c0a7ec240cbbb6f8380786d01da984c
M: eaeb50d0d31025f1589b7c8cdc12867f7a474c24 192.168.1.94:6379
slots:[9830-13106] (3277 slots) master
1 additional replica(s)
S: 2b487243e0c78adb93ac73017d04a6ad39b51c36 192.168.1.98:6380
slots: (0 slots) slave
replicates eaeb50d0d31025f1589b7c8cdc12867f7a474c24
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
恢復dump-master5,rdb數據
# 修改要恢復數據的rdb檔案位置
[root@redis91 redis-shake]# vim shake.toml
[rdb_reader]
filepath = "/root/redis-shake/dumprdbfile/dump-master5.rdb"
開始恢復dump-master5.rdb數據至cluster
[root@redis91 redis-shake]# ./redis-shake shake.toml
2023-12-17 20:23:23 INF load config from file: shake.toml
2023-12-17 20:23:23 INF log_level: [info], log_file: [/root/redis-shake/data/shake.log]
2023-12-17 20:23:23 INF changed work dir to [/root/redis-shake/data]
2023-12-17 20:23:23 INF GOMAXPROCS defaults to the value of runtime.NumCPU [8]
2023-12-17 20:23:23 INF not set pprof port
2023-12-17 20:23:23 INF no function script
2023-12-17 20:23:23 INF create RdbReader: /root/redis-shake/dumprdbfile/dump-master5.rdb
2023-12-17 20:23:23 INF redisClusterWriter load cluster nodes. line=2c05c930c506e54ebea35f8f0b731754cd44082a 192.168.1.91:6379@16379 myself,master - 0 1702815801000 1 connected 0-3276
2023-12-17 20:23:23 INF redisClusterWriter load cluster nodes. line=c40f72b0ee3ac4be0b9ddaea4d16079f723e13bf 192.168.1.98:6379@16379 master - 0 1702815800000 5 connected 13107-16383
2023-12-17 20:23:23 INF redisClusterWriter load cluster nodes. line=71d88e302c0a7ec240cbbb6f8380786d01da984c 192.168.1.92:6379@16379 master - 0 1702815799000 2 connected 3277-6553
2023-12-17 20:23:23 INF redisClusterWriter load cluster nodes. line=caa1fb6b5fbc4e133b5ef472e2def11e836481f7 192.168.1.93:6379@16379 master - 0 1702815801921 3 connected 6554-9829
2023-12-17 20:23:23 INF redisClusterWriter load cluster nodes. line=eaeb50d0d31025f1589b7c8cdc12867f7a474c24 192.168.1.94:6379@16379 master - 0 1702815800000 4 connected 9830-13106
2023-12-17 20:23:23 INF redisClusterWriter connected to redis cluster successful. addresses=[192.168.1.91:6379 192.168.1.98:6379 192.168.1.92:6379 192.168.1.93:6379 192.168.1.94:6379]
2023-12-17 20:23:23 INF create RedisClusterWriter: 192.168.1.91:6379
2023-12-17 20:23:23 INF not set status port
2023-12-17 20:23:23 INF start syncing...
2023-12-17 20:23:23 INF [rdb_reader] start read
2023-12-17 20:23:28 INF read_count=[318286], read_ops=[61021.11], write_count=[318285], write_ops=[61021.11], [rdb_reader] rdb file synced: 59.98%
2023-12-17 20:23:30 INF [rdb_reader] rdb file parse done
2023-12-17 20:23:30 INF all done
檢查一下,恢復數據後,數據分布和集群slot狀況
[root@redis91 redis-shake]# redis-cli --user 帳號 --pass 密碼 --cluster check 192.168.1.91:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.1.91:6379 (2c05c930...) -> 436710 keys | 3277 slots | 1 slaves.
192.168.1.98:6379 (c40f72b0...) -> 437406 keys | 3277 slots | 1 slaves.
192.168.1.92:6379 (71d88e30...) -> 436424 keys | 3277 slots | 1 slaves.
192.168.1.93:6379 (caa1fb6b...) -> 437055 keys | 3276 slots | 1 slaves.
192.168.1.94:6379 (eaeb50d0...) -> 436830 keys | 3277 slots | 1 slaves.
[OK] 2184425 keys in 5 masters.
133.33 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.1.91:6379)
M: 2c05c930c506e54ebea35f8f0b731754cd44082a 192.168.1.91:6379
slots:[0-3276] (3277 slots) master
1 additional replica(s)
S: 1709189e2036c2e0c4168189be9074d66bce2991 192.168.1.92:6380
slots: (0 slots) slave
replicates 2c05c930c506e54ebea35f8f0b731754cd44082a
M: c40f72b0ee3ac4be0b9ddaea4d16079f723e13bf 192.168.1.98:6379
slots:[13107-16383] (3277 slots) master
1 additional replica(s)
M: 71d88e302c0a7ec240cbbb6f8380786d01da984c 192.168.1.92:6379
slots:[3277-6553] (3277 slots) master
1 additional replica(s)
M: caa1fb6b5fbc4e133b5ef472e2def11e836481f7 192.168.1.93:6379
slots:[6554-9829] (3276 slots) master
1 additional replica(s)
S: 500ed38b799c6d5ad13483f8e0fee45fc9142d69 192.168.1.94:6380
slots: (0 slots) slave
replicates c40f72b0ee3ac4be0b9ddaea4d16079f723e13bf
S: 533669750790e904050e917657beae942185a407 192.168.1.91:6380
slots: (0 slots) slave
replicates caa1fb6b5fbc4e133b5ef472e2def11e836481f7
S: b0bff6695a1318da9a01af2550c85de1e8e81a83 192.168.1.93:6380
slots: (0 slots) slave
replicates 71d88e302c0a7ec240cbbb6f8380786d01da984c
M: eaeb50d0d31025f1589b7c8cdc12867f7a474c24 192.168.1.94:6379
slots:[9830-13106] (3277 slots) master
1 additional replica(s)
S: 2b487243e0c78adb93ac73017d04a6ad39b51c36 192.168.1.98:6380
slots: (0 slots) slave
replicates eaeb50d0d31025f1589b7c8cdc12867f7a474c24
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
分析數據
以下是將RBD檔案複製到REDIS目錄,一台一台REDIS服務重啟,慢慢導入RBD數據的效果
看起來效果是一樣,但是使用Redis-Shake,有幾個好處:
- Redis服務不用重啟,線上恢復數據
- Redis slot不會有異常分配狀況,還要使用–cluster fix的狀況發生
- 恢復數據非常快,一個dump恢復大約5秒完成
測試數據,是否正確
來查查看數據,是不是跟之前使用重啟Redis服務恢復數據時,得到的一樣
以下是使用重啟Redis服務恢復數據時,查到的key和value
[root@redis01 redis]# redis-cli --user 帳號 --pass 密碼 -c
# 查看key type,此key剛好就在redis01主機上,所以執行直接顯示type
127.0.0.1:6379> type spring:session:index:org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME:362C74F290B63E5F751DCF1E49EC34BEAF6822F0
set
# 查看key type,此key在redis02主機上,會Redirected到此key所在slot主機上,再顯示type
127.0.0.1:6379> type DRM01001000347201
-> Redirected to slot [5914] located at 192.168.1.12:6379
hash
# 查看key type,此key在redis03主機上,會Redirected到此key所在slot主機上,再顯示type
192.168.1.12:6379> type spring:session:index:org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME:EBB87CF1F764E6BACCC709323FE1457065B0CC8E
-> Redirected to slot [10759] located at 192.168.1.13:6379
set
192.168.1.13:6379> SMEMBERS spring:session:index:org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME:EBB87CF1F764E6BACCC709323FE1457065B0CC8E
1) "\xac\xed\x00\x05t\x00$aef3b17d-ed6f-4c4e-9cc3-ef69eda6f33c"
# 查看key type,此key在redis04主機上,會Redirected到此key所在slot主機上,再顯示type
192.168.1.13:6379> type TON01001010231201
-> Redirected to slot [12921] located at 192.168.1.14:6379
hash
192.168.1.14:6379> hgetall TON01001010231201
1) "path"
2) "/reader/book_content_unpack/teb/2022/10/17/TON01001010231201/TON01001010231201"
3) "iv"
4) "06ac4696c8a4bb94ecb7e82b38a1dc3f"
5) "key"
6) "36971e857d647324cb59e1cdf58d7071"
# 查看key type,此key在redis05主機上,會Redirected到此key所在slot主機上,再顯示type
192.168.1.14:6379> type spring:session:index:org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME:25E30A2AB63FE661B9AE7803EAD9A9AC234097FC
-> Redirected to slot [16326] located at 192.168.1.18:6379
set
192.168.1.18:6379> SMEMBERS spring:session:index:org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME:25E30A2AB63FE661B9AE7803EAD9A9AC234097FC
1) "\xac\xed\x00\x05t\x00$f0d82ce3-28e3-493c-b992-439565cf987e"
# 查看key type,此key在redis02主機上,會Redirected到此key所在slot主機上,再顯示type
192.168.1.18:6379> type BOOK_CASE_LIST_U_39048951
-> Redirected to slot [5895] located at 192.168.1.12:6379
hash
192.168.1.12:6379> hgetall BOOK_CASE_LIST_U_39048951
1) "0_5"
2) "{\"result\":\"00\",\"syncTime\":\"20231202164546\",\"ebooks\":[{\"deliverId\":\"SON03001000560201\",\"contentId\":\"SON03001000560\",\"title\":\"\xe6\x8a\x95\xe8\xb3\x875\xe5\xb9\xb4\xef\xbc\x8c\xe6\x9c\xac\xe9\x87\x91\xe5\xbe\x9e4\xe8\x90\xac\xe5\x88\xb01\xe5\x84\x84\xe7\x9a\x84\xe5\xa5\xb3\xe4\xba\xba\xef\xbc\x9a\xe5\xbe\x9e\xe7\x9c\x81\xe9\x8c\xa2\xe3\x80\x81\xe5\xae\x9a\xe5\xad\x98\xe5\x88\xb0\xe8\x82\xa1\xe7\xa5\xa8\xef\xbc\x8c\xe5\xb0\x88\xe5\xb1\xac\xe5\xb0\x8f\xe8\xb3\x87\xe5\xa5\xb3\xe7\x9a\x84\xe8\xb3\xaa\xe6\x84\x9f\xe7\x90\x86\xe8\xb2\xa1\xe6\x8f\x90\xe6\xa1\x88\",\"publisher\":\"\xe5\xb4\xa7\xe7\x87\x81\xe6\x96\x87\xe5\x8c\x96\",\"author\":\"\xe6\xb7\x98\xe6\xb7\x98\",\"bodyTypeCode\":\"201\",\"ebookType\":\"\xe6\x9b\xb8\xe7\xb1\x8d\",\"categories\":[\"\xe9\x87\x91\xe8\x9e\x8d\xe7\x90\x86\xe8\xb2\xa1\"],
注意:可以看到,數據都正確,此方法恢復數據,可行
[root@redis91 redis]# redis-cli --user 帳號 --pass 密碼 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# 查看key type,此key剛好就在redis01主機上,所以執行直接顯示type
127.0.0.1:6379> type spring:session:index:org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME:362C74F290B63E5F751DCF1E49EC34BEAF6822F0
set
# 查看key type,此key在redis92主機上,會Redirected到此key所在slot主機上,再顯示type
127.0.0.1:6379> type DRM01001000347201
-> Redirected to slot [5914] located at 192.168.1.92:6379
hash
# 查看key type,此key在redis94主機上,會Redirected到此key所在slot主機上,再顯示type
192.168.1.92:6379> type spring:session:index:org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME:EBB87CF1F764E6BACCC709323FE1457065B0CC8E
-> Redirected to slot [10759] located at 192.168.1.94:6379
set
192.168.1.94:6379> SMEMBERS spring:session:index:org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME:EBB87CF1F764E6BACCC709323FE1457065B0CC8E
1) "\xac\xed\x00\x05t\x00$aef3b17d-ed6f-4c4e-9cc3-ef69eda6f33c"
# 查看key type,此key剛好就在redis94主機上,所以執行直接顯示type
192.168.1.94:6379> type TON01001010231201
hash
192.168.1.94:6379> hgetall TON01001010231201
1) "path"
2) "/reader/book_content_unpack/teb/2022/10/17/TON01001010231201/TON01001010231201"
3) "key"
4) "36971e857d647324cb59e1cdf58d7071"
5) "iv"
6) "06ac4696c8a4bb94ecb7e82b38a1dc3f"
# 查看key type,此key在redis98主機上,會Redirected到此key所在slot主機上,再顯示type
192.168.1.94:6379> type spring:session:index:org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME:25E30A2AB63FE661B9AE7803EAD9A9AC234097FC
-> Redirected to slot [16326] located at 192.168.1.98:6379
set
192.168.1.98:6379> SMEMBERS spring:session:index:org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME:25E30A2AB63FE661B9AE7803EAD9A9AC234097FC
1) "\xac\xed\x00\x05t\x00$f0d82ce3-28e3-493c-b992-439565cf987e"
# 查看key type,此key在redis92主機上,會Redirected到此key所在slot主機上,再顯示type
192.168.1.98:6379> type BOOK_CASE_LIST_U_39048951
-> Redirected to slot [5895] located at 192.168.1.92:6379
hash
192.168.1.92:6379> hgetall BOOK_CASE_LIST_U_39048951
1) "0_5"
2) "{\"result\":\"00\",\"syncTime\":\"20231202164546\",\"ebooks\":[{\"deliverId\":\"SON03001000560201\",\"contentId\":\"SON03001000560\",\"title\":\"\xe6\x8a\x95\xe8\xb3\x875\xe5\xb9\xb4\xef\xbc\x8c\xe6\x9c\xac\xe9\x87\x91\xe5\xbe\x9e4\xe8\x90\xac\xe5\x88\xb01\xe5\x84\x84\xe7\x9a\x84\xe5\xa5\xb3\xe4\xba\xba\xef\xbc\x9a\xe5\xbe\x9e\xe7\x9c\x81\xe9\x8c\xa2\xe3\x80\x81\xe5\xae\x9a\xe5\xad\x98\xe5\x88\xb0\xe8\x82\xa1\xe7\xa5\xa8\xef\xbc\x8c\xe5\xb0\x88\xe5\xb1\xac\xe5\xb0\x8f\xe8\xb3\x87\xe5\xa5\xb3\xe7\x9a\x84\xe8\xb3\xaa\xe6\x84\x9f\xe7\x90\x86\xe8\xb2\xa1\xe6\x8f\x90\xe6\xa1\x88\",\"publisher\":\"\xe5\xb4\xa7\xe7\x87\x81\xe6\x96\x87\xe5\x8c\x96\",\"author\":\"\xe6\xb7\x98\xe6\xb7\x98\",\"bodyTypeCode\":\"201\",\"ebookType\":\"\xe6\x9b\xb8\xe7\xb1\x8d\",\"categories\":[\"\xe9\x87\x91