Fastdfs數據遷移方案

  • 2021 年 2 月 25 日
  • 筆記

1.     方案背景描述

環境遷移,需要遷移舊環境的fastdfs集群的數據到新環境,由於之前數據遷移僅僅是針對mysql和mongodb,對fastdfs數據的遷移了解甚少,本文檔主要是針對fastdfs數據遷移和恢復的幾種方式以及具體操作流程做詳細闡述。

2.     方案實現的目標

實現fastdfs集群數據完整遷移,保證在新環境正常使用,以及保證fastdfs集群高可用。

3.     方案說明

Fstdfs整體架構

        

 

 

 

Fastdfs數據遷移

         數據遷移是指舊的fastdfs可以繼續正常運行的情況下,將舊環境的fastdfs的數據恢復到新的環境fastdfs服務中。

 

同IP數據遷移

1) 首先關閉fdfs_storage和fdfs_tracker服務。

2) 拷貝fdfs_storage目錄中的所有數據到新目錄。

3) 修改storage配置文件中的store_path和base_path到新位置。

4) 修改mod_fastdfs.conf配置文件中的store_path和base_path到新位置。

5) 根據情況,選擇是否修改client配置文件。

6) 重啟fdfs_tracker和fdfs_storage服務

 

不同IP數據遷移

不同IP之間遷移採用FastDFS的擴容機制。

1) 在新伺服器安裝FastDFS。

2) 將新FastDFS的storage服務實例關聯到以前的tracker服務。

3) 拷貝以前的storage服務配置為新服務實例的配置文件。

4) 啟動storage服務。

FastDFS會自動同步以前伺服器上的數據

5) 停止storage服務,將storage配置文件中的tracker地址修改為新的tracer 地址,同時修改storage 中/data/fast_data/data/.data_init_flag文件,sync_src_server=空即可。

6) 啟動新的tracker服務和storage服務。

 

Fastdfs數據恢復

 

數據恢復是指舊的FastDFS服務已經不能運行,需要將已有的FastDFS數據恢復到新的FastDFS服務中。

 

1) 如果FastDFS服務使用了V4的ServerID特性,修改storage_ids.conf文件,調整對應關係即可。

 

2) 如果採用IP地址進行標識,則需要修改tracker 和storage下data目錄中的數據文件中的ip地址。

tracker server 需要修改 :

tracker/data/storage_groups_new.dat

tracker/data/storage_servers_new.dat

tracker/data/storage_sync_timestamp.dat

 

storage server 需要修改:

storage/data/.data_init_flag

storage/data/sync/${ip_addr}_${port}.mark

 

4.     數據同步以及驗證

本次遷移考慮到我們舊環境依舊可以使用並且是不同網段之間的fastdfs集群,所以採用的是FastDFS的擴容機制來遷移fastdfs的數據。

查看數據同步的進度:

           在舊環境storage服務base_path 目錄下有一個 data/sync目錄,裡面的文件如下:

              10.10.101.135_23000.mark  這個是 new_storage 的同步數據的情況

               binlog.000  舊tracker的binlog

               binlog.index  記錄著當前正在使用哪個 binlog 文件

          查看 10.10.101.135_23000.mark 的文件內容就可看到 數據同步的情況,從 scan_row_count 和 sync_row_count 的數量對比可以知道同步的進度,當兩者一致的時候同步完成。

                  

              binlog_index=0

              binlog_offset=1689076    binlog.xxx的偏移量,可以從這個偏移量獲取下一行記錄

              need_sync_old=1   本storage是否是對側storage(110.119.19.21)的源結點,同時是否需要從起點同步所有的記錄

              sync_old_done=1              是否同步完成過

              until_timestamp=1614235090        上次同步時間結點

              scan_row_count=29122                binlog總記錄數

              sync_row_count=29122                  同步的binlog行數

5.     fastdfs文件上傳下載以及基礎操作命令

文件上傳測試

1)  修改Tracker伺服器客戶端配置文件

cp   /etc/fdfs/client.conf.sample   /etc/fdfs/client.conf

vim   /etc/fdfs/client.conf

修改以下配置,其它保持默認

base_path=/data/fastdfs/tracker

tracker_server= 10.10.8.85:22122  # tracker伺服器IP和埠

tracker_server= 10.10.8.86:22122  #tracker伺服器IP和埠

2) 執行文件上傳命令

#/root/test.png 是需要上傳文件路徑

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /root/test.png

返迴文件ID號:group1/M00/00/00/wKgAfFzMX_2AB9V9AADa-k_GxyQ840.jpg

(能返回以上文件ID,說明文件已經上傳成功)

 

 

基礎操作命令:

查看集群資訊:

/usr/bin/fdfs_monitor   /usr/local/storage.conf    Storage節點都啟動之後,可以在任一 Storage 節點上使用如下命令查看集群資訊。

 

上傳命令:

fdfs_upload_file  /etc/fdfs/client.conf  [文件名稱](需全路徑)

/usr/local/bin/fdfs_upload_file   [文件名稱](需全路徑)

 

下載命令:

fdfs_download_file  /etc/fdfs/client.conf   [filename]

filename:為保存到fdfs的文件;上傳的時候返回的路徑是什麼,這邊filename就寫什麼;默認下載到當前執行命令的目錄

 

刪除命令:

fdfs_delete_file  /etc/fdfs/client.conf  [filename]

 

刪除storage節點:

fdfs_monitor   /etc/fdfs/client.conf   delete group1  [節點IP]