1. 程式人生 > >redis-migrate-tool遷移工具

redis-migrate-tool遷移工具

Redis-Migrate-Tool 使用詳解

特點:

  • •快速。
  • •多執行緒。
  • •基於redis複製。
  • •實時遷移。
  • •遷移過程中,源叢集不影響對外提供服務。
  • •異構遷移。
  • •支援Twemproxy叢集,redis cluster叢集,rdb檔案 和 aof檔案。
  • •過濾功能。
  • •當目標叢集是Twemproxy,資料會跳過Twemproxy直接匯入到後端的redis。
  • •遷移狀態顯示。
  • •完善的資料抽樣校驗。

遷移工具的來源可以是:單獨的redis例項,twemproxy叢集,redis cluster,rdb檔案,aof檔案。 
遷移工具的目標可以是:單獨的redis例項,twemproxy叢集,redis cluster,rdb檔案。

#安裝依賴:
yum install autoconf automake libtool bzip2 

#linux機器上下載包
git clone https://github.com/vipshop/redis-migrate-tool

軟體編譯安裝:

$ cd redis-migrate-tool
$ autoreconf -fvi
$ ./configure
$ make
$ src/redis-migrate-tool -h

軟體執行:

src/redis-migrate-tool -c rmt.conf -o log -d

配置檔案示例:從redis cluster叢集遷移資料到twemproxy叢集

[source]
type: redis cluster servers: - 127.0.0.1:6379 [target] type: twemproxy hash: fnv1a_64 hash_tag: "{}" distribution: ketama servers: - 127.0.0.1:6380:1 server1 - 127.0.0.1:6381:1 server2 - 127.0.0.1:6382:1 server3 - 127.0.0.1:6383:1 server4 [common] listen: 0.0.0.0:34345 threads: 8 step: 1 mbuf_size: 512 source_safe
: true

配置檔案示例:從redis cluster叢集遷移資料到另外一個cluster叢集

[source]
type: redis cluster
servers:
- 127.0.0.1:8379

[target]
type: redis cluster
servers:
- 127.0.0.1:7379

[common]
listen: 0.0.0.0:8888

配置檔案示例:從rdb檔案恢復資料到redis cluster叢集[source]

type: rdb file
servers:
 - /data/redis/dump1.rdb
 - /data/redis/dump2.rdb
 - /data/redis/dump3.rdb

[target]
type: redis cluster
servers:
 - 127.0.0.1:7379

[common]
listen: 0.0.0.0:8888

狀態檢視:通過redis-cli連線redis-migrate-tool監控的埠,執行info命令

$redis-cli -h 127.0.0.1 -p 8888
127.0.0.1:8888> info
# Server
version:0.1.0
os:Linux 2.6.32-573.12.1.el6.x86_64 x86_64
multiplexing_api:epoll
gcc_version:4.4.7
process_id:9199
tcp_port:8888
uptime_in_seconds:1662
uptime_in_days:0
config_file:/ect/rmt.conf

# Clients
connected_clients:1
max_clients_limit:100
total_connections_received:3

# Memory
mem_allocator:jemalloc-4.0.4

# Group
source_nodes_count:32
target_nodes_count:48

# Stats
all_rdb_received:1
all_rdb_parsed:1
rdb_received_count:32
rdb_parsed_count:32
total_msgs_recv:7753587
total_msgs_sent:7753587
total_net_input_bytes:234636318
total_net_output_bytes:255384129
total_net_input_bytes_human:223.77M
total_net_output_bytes_human:243.55M
total_mbufs_inqueue:0
total_msgs_outqueue:0
127.0.0.1:8888>

資料校驗:

$src/redis-migrate-tool -c rmt.conf -o log -C redis_check
Check job is running...

Checked keys: 1000
Inconsistent value keys:0
Inconsistent expire keys : 0
Other check errorkeys: 0
Checked OK keys: 1000

All keys checked OK!
Check job finished, used 1.041s