FastDFS增加存储目录

警告
本文最后更新于 2023-02-20,文中内容可能已过时。

摘要

FastDFS使用一段时间你会发现存储空间不够了,新文件无法上传。这个时候需要加磁盘也就是需要加存储目录。

基于FastDFS文件服务器的特性,在做文件扩充容量时,可采取如下两种方案:

  • 扩充group的存储空间,配置多个存储文件目录地址。
  • 扩充存储节点,新加服务器配置多个storage。

group模式扩容是通过给group的机器添加硬盘的方式,实现某个group的扩容。fastdfs在一台服务器支持多个store_path,每个store_path指向一个存储路径。如:M00/00/06/wKgBe1xOehmATFFpAAAAAAAAAAA042.txtM00表示使用store_path0,如果没有配置store_path,就使用base_path的路径。添加了硬盘后,通过把新的store_path指向新硬盘的挂载点,再修改配置文件,就能实现group的扩容。扩容后的地址如:M01/00/04/wKgBe1xOehmATFFpAAAAAAAAAAA042.txtM01表示使用store_path1。group模式扩容主要步骤如下

停止现有的tracker服务,storage服务。

1
2
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf stop
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf stop
1
vi /etc/fdfs/tracker.conf
1
2
3
4
store_path=2	##将原来的0修改为2
# 上传文件选择路径的规则
# 0:轮询(默认)
# 2:负载均衡,选择可用空间最大的文件夹
1
vi /etc/fdfs/storage.conf
1
2
store_path_count=2	#将原来的1改为2
store_path1=/data/fastdfs/group1/storage2	#新增store_path1

image-20230220095154819

1
vi /etc/fdfs/mod_fastdfs.conf
1
2
store_path_count=2	#将原来的1改为2
store_path1=/data/storage2	#新增store_path1

image-20230220094733356

查看状态

1
/usr/bin/fdfs_monitor /etc/fdfs/client.conf
1
vi /usr/local/nginx/conf/nginx.conf

在nginx的配置文件中添加新store_path的路径

https://img.bwcxtech.com/img/20200928155207.jpeg

1
/usr/bin/fdfs_test /etc/fdfs/client.conf upload test.txt

https://img.bwcxtech.com/img/20200928155705.png

成功上传到新的目录

复制一份storage.conf并修改文件名group2.conf

1
cp /etc/fdfs/storage.conf /etc/fdfs/group2.conf

修改组名

1
group_name=group2

修改端口

1
port=23001

https://img.bwcxtech.com/img/20200928154545.png

修改日志文件目录

1
base_path=/data/fastdfs/group2/storage

修改资源保存路径

1
store_path0=/data/fastdfs/group2/storage
1
vi /etc/fdfs/mod_fastdfs.conf

修改组名,多个用/区分开

1
group_name=group1/group2

设置组个数

1
group_count = 2

设置每一组信息:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/data/fastdfs/group1/storage
[group2]
group_name=group2
storage_server_port=23001
store_path_count=1
store_path0=/data/fastdfs/group2/storage

image-20230220095327060

等以此类推

1
/usr/bin/fdfs_storaged /etc/fdfs/group2.conf

nginx日志报错ERROR - file: ../common/fdfs_global.c, line: 52, the format of filename

解决办法:

1
vi /etc/fdfs/mod_fastdfs.conf

url_have_group_name=false改为url_have_group_name=true

1
2
3
4
5
6
7
8
9
/usr/bin/fdfs_monitor /etc/fdfs/client.conf

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    :在线,可以提供服务

相关内容