ITPub博客

首页 > 应用开发 > C/C++ > fastdfs数据迁移以及fastdfs问题排查记录

fastdfs数据迁移以及fastdfs问题排查记录

原创 C/C++ 作者:e71hao 时间:2021-03-01 19:21:35 0 删除 编辑

这段时间公司要迁移fastdfs ,折腾2天,现在做个记录:

一、fastdfs 是淘宝架构师编写。它的架构图网上很多,搜索一下就可以。网上能搜索到的东西我就不在这里记录了。


二、这里记录下目前我在网上没有搜索到的内容:

  1. fastdfs 迁移具体步骤我从网上拷贝  https://www.cnblogs.com/hanpengblog/p/fastdfs.html  ,理解的一点就是:当新增加一个storage连接到tracker,它会自动的拷贝文件到strorage,就是利用这个特性来进行迁移的。每个storage是对等的,当新增加一个storage的时候,fastdfs会自动的复制同步storage.比如下面例子192.167.1.17:23000这个节点添加到tracker节点时候,它会自动同步 192.167.1.13:23000节点数据同步到17节点,从而达到迁移数据的目的。保证2个fdfs之间的是可以通信的。具体迁移步骤细节如下:

前提:
新环境的fastdfs的tracker和storage服务都已经启动
老环境:
tracker 192.168.1.13:22122
storage 192.168.1.13:23000

新环境:
tracker 192.168.1.17:22122
storage 192.168.1.17:23000

迁移顺序:
1、停止新环境(192.168.1.17)的storage服务
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf stop
2、修改/etc/fdfs/storage.conf 将 tracker_server 改为 老的 tracker_server
tracker_server=192.168.1.17:22122 改为 192.168.1.13:22122
3、启动新环境的storage服务
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf

查看状态
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf


storage状态列表:

# FDFS_STORAGE_STATUS:INIT :初始化,尚未得到同步已有数据的源服务器

# FDFS_STORAGE_STATUS:WAIT_SYNC :等待同步,已得到同步已有数据的源服务器

# FDFS_STORAGE_STATUS:SYNCING :同步中

# FDFS_STORAGE_STATUS:DELETED :已删除,该服务器从本组中摘除

# FDFS_STORAGE_STATUS:OFFLINE :离线

# FDFS_STORAGE_STATUS:ONLINE :在线,尚不能提供服务

# FDFS_STORAGE_STATUS:ACTIVE :在线,可以提供服务


4、停止新环境的storage服务
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf stop
5、调整storage的文件列表(/home/fastdfs/storage)
storage server需要调整的文件列表:
data/.data_init_flag(将sync_src_server配置项留空,其它配置项不变)
data/sync/{ip_addr}_{port}.mark:此类文件,需要将文件名中的IP地址调整过来

cd /home/fastdfs/storage/data/sync
mv 192.168.1.13_23000.mark 192.168.1.17_23000.mark

6、修改新环境,将新环境的storage的tracker改为新的tracker /etc/fdfs/storage.conf 将
tracker_server=192.168.1.13:22122 改为 192.168.1.17:22122
7、启动新环境的storage服务
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf


三、理解storage,traceker 节点。FastDFS Tracker及Storage节点是可以添加的,也是可以删除的。tracker节点之间是leader和follow关系,storage节点之间是对等关系。

参考网友的如下文章: https://www.cnblogs.com/sunmmi/articles/7209308.html

  

1.fastdfs七种状态

1
2
3
4
5
6
7
# FDFS_STORAGE_STATUS:INIT      :初始化,尚未得到同步已有数据的源服务器
# FDFS_STORAGE_STATUS:WAIT_SYNC :等待同步,已得到同步已有数据的源服务器
# FDFS_STORAGE_STATUS:SYNCING   :同步中
# FDFS_STORAGE_STATUS:DELETED   :已删除,该服务器从本组中摘除
# FDFS_STORAGE_STATUS:OFFLINE   :离线
# FDFS_STORAGE_STATUS:ONLINE    :在线,尚不能提供服务
# FDFS_STORAGE_STATUS:ACTIVE    :在线,可以提供服务

 2.正常状态必须是ACTIVE

1
2
3
4
5
[root@tracker02 ~] # fdfs_monitor /etc/fdfs/client.conf | grep ACTIVE
         ip_addr = 10.1.8.45  ACTIVE
         ip_addr = 10.1.8.46  ACTIVE
         ip_addr = 10.1.8.54  ACTIVE
         ip_addr = 10.1.8.55  ACTIVE

 

3.增加Storage节点(通过配置,自动加入)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 安装Storage并配置mod_fastdfs.conf及storage.conf,设置fdfs_storaged及nginx自启动
vim  /etc/fdfs/storage .conf
tracker_server=10.1.8.43:22122
tracker_server=10.1.8.44:22122
 
vim  /etc/fdfs/mod_fastdfs .conf
tracker_server=10.1.8.43:22122
tracker_server=10.1.8.44:22122
......
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0= /data/fastdfs/data
 
# 启动新加的storage节点(会自动同步相同group的内容)
/etc/init .d /fdfs_storage  start
 
# 执行fdfs_monitor /etc/fdfs/client.conf查看集群同步情况(会看到新增的storage节点)
fdfs_monitor  /etc/fdfs/client .conf

 4.删除Storage节点及删除后重新加入(通过fdfs_monitor删除)

1
2
3
4
5
6
7
# 停止某个storage节点
/etc/init .d /fdfs_storage  stop
 
fdfs_monitor  /etc/fdfs/client .conf delete group1 10.1.8.x
 
# 查看集群情况 fdfs_monitor /etc/fdfs/client.conf 可以到对应的storage节点状态为DELETED
fdfs_monitor  /etc/fdfs/client .conf

 5.重新加入storage节点

1
2
3
4
5
# 启动被删除的storage节点,查看集群状态,一开始会是 OFFILINE状态
fdfs_monitor  /etc/fdfs/client .conf
 
# 过一会儿再查看集群状态,显示为ACTIVE状态
fdfs_monitor  /etc/fdfs/client .conf

 6.增加Tracker节点

1
2
3
4
5
6
7
# 在所有storage节点的storage.conf, mod_fastdfs.conf 中配置多条tracker_server记录
tracker_server=10.2.x.1:22122
tracker_server=10.2.x.2:22122
 
# 在client.conf中也配置多条tracker_server记录
执行 fdfs_monitor  /etc/fdfs/client .conf 查看集群情况,可以看到tracker_serve_count变为2
另外可以指定tracker,进行集群监控  fdfs_monitor  /etc/fdfs/client .conf -h 10.2.x.1 list

 7.删除Tracker节点

1
去掉配置文件中不需要的tracker_server的记录,停止对应服务器上的tracker进程

8.storage不同步处理

1
2
3
4
5
6
7
8
9
10
11
# 从集群中删除storage
fdfs_monitor  /etc/fdfs/client .conf delete group1 10.1.8.101
 
# 删除数据文件夹
rm  -rf  /home/storage1/fastdfs/data
 
# 重启storage
fdfs_storaged  /etc/fdfs/storage .conf
 
# 重新查状态
fdfs_monitor  /etc/fdfs/client .con

四、同步问题的排查,之间同步迁移遇到很多问题,排查主要靠查看日志和使用 fdfs_monitor工具

日志存放目录:

错误日志是每个进程都有一个,启动bin/fdfs_storaged /opt/fastdfs_lifekh-mp/conf/storage_accsett.conf

错误日志在base_path下面会有一个logs文件夹

 /data/fastdfs_lifekh-mp/accsett/logs/storaged.log


同步迁移的时候方便监听状态工具: fdfs_monitor ,这个工具非常有用。

fdfs_monitor  /etc/fdfs/client .conf


参考文章: https://www.cnblogs.com/sunmmi/articles/7209308.html

https://www.cnblogs.com/aresxin/p/4952600.html

https://www.cnblogs.com/hanpengblog/p/fastdfs.html

https://blog.csdn.net/markfengfeng/article/details/102528782


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30393770/viewspace-2760380/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-08-05

  • 博文量
    133
  • 访问量
    235589