Fastdfs扩容方案
FastDFS服务的存储服务器,创建时由于规划不合理。目前存储空间已经使用了85%,需要添加磁盘扩容,group模式扩容是通过给group的机器添加硬盘的方式,实现某个group的扩容。fastdfs在一台服务器支持多个store_path,每个store_path指向一个存储路径。如果没有配置store_path,就使用base_path的路径。添加了硬盘后,通过把新的store_path指向新硬盘的挂载点,再修改配置文件,就能实现group的扩容(文档中的配置文件路径具体参考安装fastdfs的实际情况,特别要注意的是如果是集群则多个服务器都需要更改)。
group模式扩容主要步骤如下:
停止服务:
停止tracker服务,storage服务,nginx服务。
fdfs_trackerd /etc/fdfs/tracker.conf stop
fdfs_storaged /etc/fdfs/storage.conf stop
停止nginx服务
cd /usr/local/nginx/sbin/
./nginx -s stop
修改tracker.conf配置文件
修改storage.conf配置文件
修复nginx.conf配置文件
重启tracker服务,storage服务,nginx服务
修改tracker.conf配置文件
cd /etc/fdfs/
vim tracker.conf
修改配置文件中的store_path=2
修改后如下:
# which path(means disk or mount point) of the storage server to upload file
# 0: round robin
# 2: load balance, select the max free space path to upload file
store_path=2
# which storage server to download file
# 0: round robin (default)
# 1: the source storage server which the current file uploaded to
download_server=0
注释:
0 - 代表轮询进行存储,意思是在一个storage中配置的store_path0、store_path1……之间进行轮询存储文件
2- 代表选择storage中存储路径中空闲空间最大的进行保存文件
修改storage.conf配置文件
cd /etc/fdfs/
vim storage.conf
修改store_path_count=2 增加store_path1=新挂载的目录
# path(disk or mount point) count, default value is 1
store_path_count=2
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/home/fdfs/data/storage
store_path1=/home/fdfs/data/storage1
# subdir_count * subdir_count directories will be auto created under each
# store_path (disk), value can be 1 to 256, default value is 256
subdir_count_per_path=256
注释:
store_path_count 指的是当前一个storage有几个存储文件的目录
store_path0 storage存储文件路径,对应上传后文件名为M00/xxxxxx
store_path1 storage存储文件路径,对应上传后文件名为M01/xxxxxx,(扩展成功之后可通过此上传的文件名判断新上传的文件是否存储到新的路径下)
修改mod_fastdfs.conf配置文件
cd /etc/fdfs/
vim mod_fastdfs.conf
修改store_path_count=2 和 新增store_path1=新挂载的目录(此目录和storage.conf中的一样)
# path(disk or mount point) count, default value is 1
store_path_count=2
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/home/fdfs/data/storage
store_path1=/home/fdfs/data/storage1
注意:里面的store_path_count和store_path1必须和storage.conf中的值是一样。
修改nginx的配置
方式1:通过正则匹配查找
删除原来的配置,更改为新的配置
location ~ /group[1-9]/M0[0-9] {
ngx_fastdfs_module;
}
方式2:多个代理配置
删除原来的配置,修改为如下
location /group1/M00 {
root /home/fastdfs/storage;
ngx_fastdfs_module;
}
location /group1/M01 {
root /home/fastdfs/storage1;
ngx_fastdfs_module;
}
启动tracker
fdfs_trackerd /etc/fdfs/tracker.conf
启动storage
fdfs_storaged /etc/fdfs/storage.conf
启动nginx
cd /usr/local/nginx/sbin/
./nginx -c /usr/local/nginx/conf/nginx.conf -t
./nginx -c /usr/local/nginx/conf/nginx.conf
nginx启动之后正常有两个进程同时运行,可通过下面的命令进行查看
ps -ef|grep nginx
[fdfs@redis_cluster-1 fdfs]$ ps -ef|grep nginx
fdfs 2984 1 0 2022 ? 00:00:00 nginx: master process /home/fdfs/nginx/sbin/nginx -p /home/fdfs/nginx/ -c /home/fdfs/nginx/conf/nginx.conf
fdfs 2985 2984 0 2022 ? 00:00:00 nginx: worker process
fdfs 6678 3896 0 16:57 pts/6 00:00:00 grep --color=auto nginx
检查挂载服务是否正常
使用命令/home/fdfs/fastdfs/bin/fdfs_monitor /home/fdfs/fastdfs/fdfs/storage.conf
[fdfs@redis_cluster-1 ~]$ /home/fdfs/fastdfs/bin/fdfs_monitor /home/fdfs/fastdfs/fdfs/storage.conf
[2023-05-11 17:18:35] INFO - base_path=/home/fdfs/data/storage, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0
server_count=1, server_index=0
tracker server is 10.10.202.118:22122
group count: 1
Group 1:
group name = group1
disk free space = 6 GB
trunk free space = 0 GB
storage server count = 1
active server count = 1
storage server port = 23000
storage HTTP port = 80
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0
Storage 1:
ip_addr = 10.10.202.118 (redis_cluster-1) ACTIVE
http domain =
version = 3.06
join time = 2016-07-16 07:11:39
up time = 2022-05-16 10:30:34
total storage = 44GB
free storage = 6GB
upload priority = 10
store_path_count = 1
subdir_count_per_path = 256
storage_port = 23000
storage_http_port = 80
current_write_path = 0
source ip_addr =
if_trunk_server= 0
total_upload_count = 119024
success_upload_count = 119024
total_append_count = 216513
success_append_count = 216513
total_set_meta_count = 10
success_set_meta_count = 10
total_delete_count = 110936
success_delete_count = 110936
total_download_count = 439846
success_download_count = 439846
total_get_meta_count = 0
success_get_meta_count = 0
total_create_link_count = 0
success_create_link_count = 0
total_delete_link_count = 0
success_delete_link_count = 0
total_upload_bytes = 25520237166
success_upload_bytes = 25520237166
total_append_bytes = 7542443323
success_append_bytes = 7542443323
stotal_download_bytes = 10279169200
success_download_bytes = 10279169200
total_sync_in_bytes = 0
success_sync_in_bytes = 0
total_sync_out_bytes = 0
success_sync_out_bytes = 0
total_file_open_count = 775384
success_file_open_count = 775384
total_file_read_count = 447278
success_file_read_count = 447278
total_file_write_count = 401397
success_file_write_count = 401397
last_heart_beat_time = 2023-05-11 17:18:18
last_source_update = 2023-05-11 15:04:11
last_sync_update = 1970-01-01 08:00:00
last_synced_timestamp = 1970-01-01 08:00:00
编写fastdfs启动脚本
vi start_service.sh
#!/bin/sh
userdir="/home/fdfs"
#start tracker
${userdir}/fastdfs/bin/fdfs_trackerd ${userdir}/fastdfs/fdfs/tracker.conf
sleep 1
#start stroage
${userdir}/fastdfs/bin/fdfs_storaged ${userdir}/fastdfs/fdfs/storage.conf
sleep 1
#start nginx
[ ! -e "/tmp/http.conf" ] && ln -s ${userdir}/fastdfs/fdfs/http.conf /tmp/
[ ! -e "/tmp/mod_fastdfs.conf" ] && ln -s ${userdir}/fastdfs/fdfs/mod_fastdfs.conf /tmp/
${userdir}/nginx/sbin/nginx -p ${userdir}/nginx/ -c ${userdir}/nginx/conf/nginx.conf