分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

一次替换FastDFS数据目录引发的文件上传和访问异常

发布时间:2023-09-06 02:13责任编辑:熊小新关键词:文件上传
1、图片访问异常

问题描述

搭建一台新环境的FastDFS文件服务器,刚搭建好的时候,上传了一张图片,正常,但是因为当时端口没有开,没有验证访问的问题。环境暂时搁置等待测试。
后来在测试环节,因为需要上传的图片文件太多,因此直接将生产环境的dfs的数据目录拷贝过去,替换了新环境的数据目录,同时以下文件还是用的新环境原有的文件( /data/dfs就是数据目录):

/data/dfs/tracker 目录 ???
/data/dfs/group1/data/fdfs_storaged.pid
/data/dfs/group1/data/storage_stat.dat
/data/dfs/group1/data/storage_trunk.dat
/data/dfs/group1/data/sync 目录
/data/dfs/group1/data/trunk 目录

然后重启了tracker、storage和nginx服务,但是发现图片访问不到,直接页面是一片空白,使用curl访问,也是没有任何返回,就卡在那里,只能Ctrl+c退出来:

[root@host10 logs]# ?curl ?http://10.0.0.10:8090/groupA/M00/00/00/cErM6luMkf-IbhOWAAhHLHLDXwwAAAABQKwYD8ACEdE376.jpg-m#没有任何返回,只能Ctrl+c退出来。[root@host10 logs]#

原因分析

1、查看端口和进程

查看storage和tracker进程,都还在:

[root@host10 ~]# ?ps -ef|grep storage.confroot ?????1126 ????1 ?0 14:57 ? ???????00:00:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restartroot ?????5139 ?5071 ?0 15:13 pts/8 ???00:00:00 grep --color=auto storage.conf[root@host10 ~]# ?ps -ef|grep tracker.confroot ?????5149 ?5071 ?0 15:13 pts/8 ???00:00:00 grep --color=auto tracker.confroot ????30168 ????1 ?0 14:44 ? ???????00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart[root@host10 ~]#

查看tracker、storage的端口,都是起来的,防火墙也打开了相应的端口:

[root@host10 ~]# netstat -tlunp|grep 23000tcp ???????0 ?????0 0.0.0.0:23000 ??????????0.0.0.0:* ??????????????LISTEN ?????1126/fdfs_storaged[root@host10 ~]# netstat -tlunp|grep 22122tcp ???????0 ?????0 0.0.0.0:22122 ??????????0.0.0.0:* ??????????????LISTEN ?????30168/fdfs_trackerd

然后查看nginx,发现端口也是起来的,但是进程有异常,只有一个master进程:

[root@host10 sbin]# ps -ef|grep nginxroot ??????744 22962 ?0 10:37 pts/8 ???00:00:00 grep --color=auto nginxroot ????29076 ????1 ?0 10:21 ? ???????00:00:00 nginx: master process ./nginx ????#只有一个master进程[root@host10 sbin]#

2、查看日志

查看nginx日志,在error_log重复报下面几行错误

ngx_http_fastdfs_process_init pid=29077[2018-09-05 10:21:46] ERROR - file: shared_func.c, line: 960, open file /etc/fdfs/mod_fastdfs.conf fail, errno: 13, error info: Permission denied[2018-09-05 10:21:46] ERROR - file: /usr/local/fastdfs-nginx-module/src/common.c, line: 155, load conf file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 132018/09/05 10:21:46 [alert] 29076#0: worker process 29077 exited with fatal code 2 and cannot be respawned

根据报错信息的Permission denied和网上一些博文,同时对比了生产环境FastDFs服务器上的/etc/dfs目录的权限,尝试修改了/etc/dfs目录的权限,改成了755,并重启tracker、storage、nginx服务:

# chmod 755 /etc/fdfs# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart# cd /usr/local/nginx/sbin/# ./nginx -s reload

然后查看nginx的进程,就有worker进程了:

[root@host10 ~]# ps -ef|grep nginxnobody ????363 29076 ?0 14:55 ? ???????00:00:00 nginx: worker process ????????#有worker进程了root ?????8456 ?8381 ?0 15:27 pts/8 ???00:00:00 grep --color=auto nginxroot ????29076 ????1 ?0 10:21 ? ???????00:00:00 nginx: master process ./nginx[root@host10 ~]#

访问图片,有内容返回了:

[root@host10 logs]# ?curl ?http://10.0.0.10:8090/groupA/M00/00/00/cErM6luMkf-IbhOWAAhHLHLDXwwAAAABQKwYD8ACEdE376.jpg-mfileExtNamejpgfileLength542508fileNameIMG_1171.jpg[root@host10 logs]#

让测试在新环境上测试了一下,图片能够正常访问了。

2、图片上传异常

问题描述

在测试反馈图片访问可以正常的时候,为了保险,测试了一下图片上传功能,发现上传图片出现问题:

[root@host10 ~]# ?/usr/bin/fdfs_test /etc/fdfs/client.conf upload /tmp/test/test10.pngThis is FastDFS client test program v5.05Copyright (C) 2008, Happy Fish / YuQingFastDFS may be copied only under the terms of the GNU GeneralPublic License V3, which may be found in the FastDFS source kit.Please visit the FastDFS Home Page http://www.csource.org/for more detail.[2018-09-05 11:08:23] DEBUG - base_path=/data/dfs/tracker, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0tracker_query_storage_store_list_without_group: ???????server 1. group_name=, ip_addr=10.0.0.10, port=23000group_name=groupA, ip_addr=10.0.0.10, port=23000[2018-09-05 11:08:23] ERROR - file: tracker_proto.c, line: 48, server: 10.0.0.10:23000, response status 17 != 0storage_upload_by_filenameupload file fail, error no: 17, error info: File exists ???#这里报File exists,但是换了很多张新图片上传,都报这个错[root@host10 ~]#

原因分析

查看storaged.log日志,发现在上传文件的同时,日志就会打印出这几行报错信息:

[2018-09-05 11:15:45] ERROR - file: storage_dio.c, line: 885, trunk file: /data/dfs/group1/data/00/00/000001, offset: 299076 already occupied by other file, trunk header info: file_type=-88, alloc_size=-1127393023, file_size=-397478323, crc32=485419875, mtime=-592647312, ext_name(7)=(<\?f§r[2018-09-05 11:15:45] WARNING - file: trunk_mgr/trunk_mem.c, line: 1620, trunk space already be occupied, delete this trunk space, trunk info: store_path_index=0, sub_path_high=0, sub_path_low=0, id=1, offset=299076, size=24885, status=1

第一次遇到这种问题,于是将报错信息在百度和Google找了很久,没有找到相应的解决办法。因为刚刚安装好FastDFs服务的时候,图片上传功能是正常的于是怀疑可能是替换数据目录引发的问题。因此尝试将数据目录还原成了最初安装的那个原始的数据目录,发现可以正常上传。那就是数据目录的问题了

再看报错信息,指出了是和/data/dfs/group1/data/00/00/000001这个文件有关。而且用生产环境拷贝过去数据目录,就只能访问到文件,但是不能上传。所以结合报错信息,重新使用线上环境的那套数据目录。除了上面提到的

/data/dfs/tracker 目录 ???
/data/dfs/group1/data/fdfs_storaged.pid
/data/dfs/group1/data/storage_stat.dat
/data/dfs/group1/data/storage_trunk.dat
/data/dfs/group1/data/sync 目录
/data/dfs/group1/data/trunk 目录

这部分文件使用的新环境本身的文件之外,还将/data/dfs/group1/data/00/00/000001文件也替换成了新环境本身原始的000001文件。然后重启tracker、storage、nginx服务,发现上传功能恢复了:

[root@host10 data]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /tmp/test/test2.png ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????This is FastDFS client test program v5.05Copyright (C) 2008, Happy Fish / YuQingFastDFS may be copied only under the terms of the GNU GeneralPublic License V3, which may be found in the FastDFS source kit.Please visit the FastDFS Home Page http://www.csource.org/for more detail.[2018-09-05 15:40:56] DEBUG - base_path=/data/dfs/tracker, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0tracker_query_storage_store_list_without_group: ???????server 1. group_name=, ip_addr=10.0.0.10, port=23000group_name=groupA, ip_addr=10.0.0.10, port=23000storage_upload_by_filenamegroup_name=groupA, remote_filename=M00/00/00/rDN5CluPiIiIV-bEAABFIRkNTkMAAAAAQAGYYsAAEU5442.pngsource ip address: 10.0.0.10file timestamp=2018-09-05 15:40:56file size=17697file crc32=420302403example file url: http://10.0.0.10:8090/groupA/M00/00/00/rDN5CluPiIiIV-bEAABFIRkNTkMAAAAAQAGYYsAAEU5442.pngstorage_upload_slave_by_filenamegroup_name=groupA, remote_filename=M00/00/00/rDN5CluPiIiIV-bEAABFIRkNTkMAAAAAQAGYYsAAEU5442_big.pngsource ip address: 10.0.0.10file timestamp=2018-09-05 15:40:56file size=17697file crc32=420302403example file url: http://10.0.0.10:8090/groupA/M00/00/00/rDN5CluPiIiIV-bEAABFIRkNTkMAAAAAQAGYYsAAEU5442_big.png[root@host10 data]#

查看数据目录,这个文件也是存在的:

[root@host10 data]# ?ll /data/dfs/group1/data/00/00/|grep 5442-rw-r--r-- 1 root root ???17697 Sep ?5 15:40 rDN5CluPiIiIV-bEAABFIRkNTkMAAAAAQAGYYsAAEU5442_big.png-rw-r--r-- 1 root root ??????49 Sep ?5 15:40 rDN5CluPiIiIV-bEAABFIRkNTkMAAAAAQAGYYsAAEU5442_big.png-m-rw-r--r-- 1 root root ??????49 Sep ?5 15:40 rDN5CluPiIiIV-bEAABFIRkNTkMAAAAAQAGYYsAAEU5442.png-m[root@host10 data]#

查看该图片,也是可以查看到的了:

[root@host10 data]# curl http://10.0.0.10:8090/groupA/M00/00/00/rDN5CluPiIiIV-bEAABFIRkNTkMAAAAAQAGYYsAAEU5442_big.png-mext_namejpgfile_size115120height80width160[root@host10 data]#[root@host10 data]#[root@host10 data]# curl http://10.0.0.10:8090/groupA/M00/00/00/rDN5CluPiIiIV-bEAABFIRkNTkMAAAAAQAGYYsAAEU5442.png-mext_namejpgfile_size115120height80width160[root@host10 data]#

在浏览器访问
http://10.0.0.10:8090/groupA/M00/00/00/rDN5CluPiIiIV-bEAABFIRkNTkMAAAAAQAGYYsAAEU5442_big.png
也能看到图片:

小记:
综上,用生产环境FastDFs数据目录替换新环境的数据目录后,需要做下面的操作:
1、清空生产环境数据目录里面的log文件;
2、以下文件用的是新环境自身的文件:

/data/dfs/tracker 目录
/data/dfs/group1/data/fdfs_storaged.pid
/data/dfs/group1/data/storage_stat.dat
/data/dfs/group1/data/storage_trunk.dat
/data/dfs/group1/data/sync 目录
/data/dfs/group1/data/trunk 目录
/data/dfs/group1/data/00/00/000001

一次替换FastDFS数据目录引发的文件上传和访问异常

原文地址:http://blog.51cto.com/10950710/2170754

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved