初始化集群
任意一台输入以下命令,将IP替换为实际IP:
docker compose down && rm -r data && docker compose up -d
docker exec -it redis-6379 redis-cli --cluster create \
124.223.188.153:6379 \
124.223.101.46:6379 \
124.222.201.247:6379 \
--cluster-replicas 0 -a Ux#Redis@Passwd
验证集群
docker exec -it redis-6379 redis-cli -a Ux#Redis@Passwd -c cluster nodes
docker exec -it redis-6379 redis-cli -a Ux#Redis@Passwd -c cluster info
数据迁移
下载工具
wget https://github.com/alibaba/RedisShake/releases/download/v3.0.0/redis-shake-v3.0.0-linux-amd64.tar.gz
tar -zxvf redis-shake-v3.0.0-linux-amd64.tar.gz
cd redis-shake-v3.0.0-linux-amd64
编写配置文件 redis-shake.toml
[sync_reader]
cluster = false
address = "DB:16379"
password = "123456"
tls = false
sync_rdb = true
sync_aof = true
[redis_writer]
cluster = true
address = "DB-Node-1:6379" # 只写一个节点
password = "Ux#Redis@Passwd"
tls = false
off_reply = false
[filter]
allow_keys = []
allow_key_prefix = []
allow_key_suffix = []
allow_key_regex = []
block_keys = []
block_key_prefix = []
block_key_suffix = []
block_key_regex = []
allow_db = []
block_db = []
allow_command = []
block_command = []
allow_command_group = []
block_command_group = []
function = ""
[advanced]
dir = "data"
ncpu = 0
pprof_port = 0
status_port = 0
log_file = "shake.log"
log_level = "info"
log_interval = 5
log_rotation = true
log_max_size = 512
log_max_age = 7
log_max_backups = 3
log_compress = true
rdb_restore_command_behavior = "panic"
pipeline_count_limit = 1024
target_redis_client_max_querybuf_len = 1073741824
target_redis_proto_max_bulk_len = 512000000
empty_db_before_sync = false
执行迁移
./redis-shake redis-shake.toml
验证数据是否迁移成功
docker exec -it redis-6379 redis-cli -c -h DB-Node-1 -a Ux#Redis@Passwd -p 6379 keys '*'
docker run -it --rm redis:latest
redis-cli -c -h 10.0.12.16 -p 6379 -a ‘Ux#Redis@Passwd’