Redis遷移工具redis-migrate-tool的使用
背景 : 公司由于以前沒有同意規劃 , 導致出現好幾個redis實例 , 現在需要整合到一起 , 查到還有redis-migrate-tool工具 , 所以把使用情況寫一下 , 以備后用參考
一、下載編譯
# 從git庫直接拉取
git clone https://github.com/vipshop/redis-migrate-tool.git
# CentOS安裝必要的包(其他Linux版本請自己查詢安裝方法)
yum -y install automake libtool autoconf bzip2
# 編譯并安裝
cd redis-migrate-tool
autoreconf -fvi
./configure
make
#能出現幫助 , 說明編輯安裝成功
src/redis-migrate-tool -h
二、寫配置文件
配置文件樣例 :
[source] type: redis cluster servers: - 172.25.2.118:6380 - 172.25.2.118:6381 redis_auth: {redis密碼} [target] type: single servers: - 172.25.2.118:6379 redis_auth: {redis密碼} [common] listen: 0.0.0.0:8888 threads: 8 step: 1 mbuf_size: 512 source_safe: true
source和target詳解 (待遷移 和 遷入數據源) :
;Redis RDB備份模式 [source] type: rdb file servers: - /data/redis/dump1.rdb - /data/redis/dump2.rdb ;Redis AOF備份模式 [source] type: aof file servers: - /data/redis/dump1.aof - /data/redis/dump2.aof ;Redis 單機實例 [source] type: single servers: - 172.25.2.118:6379 ; redis密碼 redis_auth: 111 ;Redis Cluster集群模式 [target] type: redis cluster servers: - 127.0.0.1:6379 - 127.0.0.1:6380 ; redis密碼 redis_auth: 111 ;Redis Twemproxy集群模式 [target] type: twemproxy ;hash模式包括 : one_at_a_time md5 crc16 crc32 crc32a fnv1_64 fnv1a_64 fnv1_32 fnv1a_32 hsieh murmur jenkins hash: fnv1a_64 ; {} or $$ hash_tag: "{}" ;distribution包括 : ketama , modula ,random distribution: ketama servers: - 127.0.0.1:6380:1 server1 - 127.0.0.1:6381:1 server2
common詳解
common
listen: 監聽的地址和端口(name:port或ip:port)。默認是127.0.0.1:8888
max_clients:該監聽端口客戶端最大數量。默認是100
threads: redis-migrate-tool能夠使用的最大的線程數量。默認是cpu核數。
step: 解析請求的級別。配的越大,遷移越快,消耗內存越多。默認是1
mbuf_size: Mbuf的大小。默認是512
noreply: boolean。決定是否要檢測目標redis的回復。默認是false。
source_safe: boolean。是否保護源redis的內存安全。如果設置為true,那么該工具保證一臺機器上同一時刻只有一個redis在生成rdb文件。除此之外,設置‘source_safe:true’時,所使用的線程可能會比你設置的要少。默認是true
dir: 工作目錄,用于存儲文件(例如rdb文件)。默認是當前目錄。
filter: 過濾key,如果不匹配表達式,則不遷移。表達式Glob-style(通配符)。默認是空。
filter支持通配符表達式:
h?llo 匹配 hello, hallo 和 hxllo
h*llo 匹配 hllo 和 heeeello
h[ae]llo 匹配 hello 和 hallo, 不匹配 hillo
h[^e]llo 匹配 hallo, hbllo, … 不匹配 hello
h[a-b]llo 匹配 hallo 和 hbllo
三、開始遷移
注意 : 建議配置文件直接使用根目錄下的 rmt.conf , 并且執行也是在根目錄下執行 , 比如 :
# 開始運行 ./src/redis-migrate-tool -c rmt.conf -o log -d
自寫其他配置文件 , 使用-c加載 , 有時候會出現無法加載的情況 , 不知道是不是bug
四、查看遷移情況
軟件的原理是自己創建一個redis從庫, 然后作為從庫進行主從遷移 ,
所以根據此原理 , 可用redis-cli進入臨時庫 , 進行數據查詢
# 使用redis-cli進入臨時庫進行查看 redis-cli -h 127.0.0.1 -p 8888 127.0.0.1:8888> info
info命令響應介紹:
Server:
Clients:
version: redis-migrate-tool版本號
os:操作系統名稱
multiplexing_api: 多路復用API
gcc_version: gcc版本
process_id: redis-migrate-tool的進程id
tcp_port: redis-migrate-tool監聽的tcp端口
uptime_in_seconds: redis-migrate-tool運行的時長。單位秒。
uptime_in_days: redis-migrate-tool運行的時長。單位天。
config_file: redis-migrate-tool配置文件的名稱
connected_clients: 當前連接的客戶端數量
max_clients_limit: 允許同時連接的最大客戶端數量
total_connections_received: 迄今為止接收的連接數量的總數
Group:
source_nodes_count: 源redis的節點數量
target_nodes_count: 目標redis的節點數量
Stats:
all_rdb_received: 是否所有源節點的rdb都已接收完畢。
all_rdb_parsed: 是否所有的源節點rdb文件都已經解析完畢。
all_aof_loaded: 是否所有的源節點aof文件都已經加載完畢。
rdb_received_count: 已經接收源redis節點rdb文件的個數。
rdb_parsed_count: 已經完成解析rdb的個數。
aof_loaded_count: 已經加載完aof的個數。
total_msgs_recv: 從源redis接收到的消息總數。
total_msgs_sent: 發送給目標redis,并已經收到相應的的消息總數。
total_net_input_bytes: 從源redis接收到的數據總大小
total_net_output_bytes: 發送給目標redis的數據總大小
total_net_input_bytes_human: 和total_net_input_bytes相同,轉化成可讀的格式
total_net_output_bytes_human: 和total_net_output_bytes相同,轉化為可讀的格式
total_mbufs_inqueue: 來自源redis的mbufs的緩存數據(不包括rdb數據)
total_msgs_outqueue: 待發送給目標redis和已經發送等待響應的消息總數
五、遷移異常處理及驗證
停止遷移 : 直接把臨時庫停止即可
$redis-cli -h 127.0.0.1 -p 8888 127.0.0.1:8888> shutdown OK
shutdown參數 : [second | asap]
- seconds: 在redis-migrate-tool退出之前,它把緩沖區的數據發送給目標redis最多用的時長(秒)。默認是10s
- asap: 不關心緩沖區的數據,直接退出。
該命令會干下面幾件事:
- 停止從源redis復制數據
- 試圖發送redis-migrate-tool緩沖區中的數據給目標集群
- 停止redis-migrate-tool并退出
驗證 :
# 驗證傳輸情況 src/redis-migrate-tool -c rmt.conf -o log -C redis_check
浙公網安備 33010602011771號