RedisShake是一個開源的Redis遷移工具,可以用于在線遷移和離線遷移(通過備份文件導入)。當你需要遷移部署在其他云廠商上的 Redis集群數據時,如果無法進行在線遷移,你可以選擇離線遷移的方式。
在線遷移
在線遷移主要適用于自建Redis Cluster集群遷移到DCS Redis的場景,且兩端集群實例能夠網絡連通,或者有一臺中轉服務器能夠連通兩端集群實例。
在線遷移有多種模式,如果SYNC、PSYNC命令未被禁用,建議采用sync_reader模式,否則可使用scan_reader模式,具體見RedisShake官方社區。
1、在DCS控制臺創建Redis實例。
注意新創建的Redis實例容量不能小于源端Redis實例的實際使用容量。
2、準備一臺云服務器,并安裝RedisShake。
RedisShake需既能訪問源端緩存實例,也能訪問目標端DCS 緩存,需要綁定彈性公網IP
3、獲取源集群和目標集群的ip地址。
如果源實例或者目標實例是proxy模式架構,則獲取proxy ip即可。
4、編輯RedisShake配置文件。
編輯redis-shake工具配置文件shake.toml,補充遷移雙方信息,及遷移模式。
[sync_reader]
cluster = false # set to true if source is a redis cluster
address = "ip:port" # 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
sync_rdb = true # set to false if you don't want to sync rdb
sync_aof = true # set to false if you don't want to sync aof
[scan_reader]
cluster = false # set to true if source is a redis cluster
address = "ip:port" # 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
ksn = false # set to true to enabled Redis keyspace notifications (KSN) subscription
tls = false
dbs = [] # set you want to scan dbs such as [1,5,7], if you don't want to scan all
[redis_writer]
cluster = false # set to true if target is a redis cluster
address = "ip:port" # 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
5、在線遷移,同步數據。
使用如下命令同步源Redis集群和目標Redis集群數據:
./redis-shake shake.toml
執行日志中出現如下信息,代表全量數據同步完成,進入增量同步階段:
syncing aof
執行日志出現如下信息時,代表增量同步無新增內容,可手動停止同步:
read_count=[0], read_ops=[0.00], write_count=[0], write_ops=[0.00], src-x, syncing aof, diff=[0]
6、遷移后驗證。
數據同步結束后,可使用Redis-cli工具連接DCS 實例,通過dbsize查看key數量,確認數據是否完整導入。
如果數據不完整,可使用flushall或者flushdb命令清理實例中的緩存數據后重新同步。
7、清理RedisShake配置文件。
離線遷移(備份文件導入)
與在線遷移相比,離線遷移適宜于源實例與目標實例的網絡無法連通的場景。
1、在DCS控制臺創建緩存實例。
注意新創建的Redis實例容量不能小于源端Redis實例的實際使用容量。
2、準備一臺云服務器,并安裝RedisShake。
RedisShake既能訪問源端緩存實例,也能訪問目標端DCS 緩存,需要綁定彈性公網IP
3、導出RDB文件。
使用如下命令導出RDB文件:
./redis-cli -h {redis_address} -p {redis_port} -a {password} --rdb {output.rdb}
執行命令后回顯"Transfer finished with success.",表示文件導出成功。
4、將導出的RDB文件(含多個)上傳到云服務器上。
5、編輯RedisShake配置文件。
編輯redis-shake工具配置文件shake.toml,補充遷移雙方信息,及遷移模式。
[rdb_reader]
filepath = "/tmp/dump.rdb"
[redis_writer]
cluster = false # set to true if target is a redis cluster
address = "ip:port" # 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
6、在線遷移,同步數據。
使用如下命令同步源Redis集群和目標Redis集群數據:
./redis-shake shake.toml
執行日志中出現如下信息,代表同步完成:
all done
7、遷移后驗證。
數據同步結束后,可使用redis-cli工具連接DCS 實例,通過dbsize查看Key數量,確認數據是否完整導入。
如果數據不完整,可使用flushall或者flushdb命令清理實例中的緩存數據后重新同步。
8、清理RedisShake配置文件。