文件服务器fdfs集群切换和上传或者下载条数限制问题的解决方案

问题一:搭建双击热备(keepalived+fdfs)文件服务器fdfs后,如果一台文件服务器挂了之后浮点ip漂移到另一台的时候正在下载的文件进程会卡死下载不下载(上传也一样);

问题二:下载文件数量超过1000会卡死;

              解决方案:由于老板版问题连接资源没有及时释放导致卡死状态;注意版本号一定要1.29以上

核心配置流程和工具类封装一下

   org.csourcefastdfs-client-java1.29-SNAPSHOTsystem${project.basedir}/src/main/resources/jar/fastdfs-client-java-1.29.jar
package com.people.util;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.csource.fastdfs.*;
import org.csource.fastdfs.pool.Connection;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;import com.people.exception.RRException;import java.io.File;
import java.io.IOException;@Component
public class FileDfsUtils {static {try {ClientGlobal.initByProperties("fastdfs-client.properties");
//            ClientGlobal.initByTrackers("192.168.98.20:22122,192.168.98.22:22122");} catch (Exception e) {Slf4jLogUtil.error("FastFds初始化失败", e);}}/*** 上传文件(通用)** @param multipartFile 文件* @return 路径*/public String upload(MultipartFile multipartFile) throws Exception {if (multipartFile.getSize() == 0){return null;}String extName = FilenameUtils.getExtension(multipartFile.getOriginalFilename());String path = getStorageClient().upload_file1(multipartFile.getBytes(), extName, null);return path;}/*** 上传文件** @param filePath 文件路径* @return 路径*/public String uploadFile(String filePath)  throws Exception {return uploadFile(new File(filePath));}/*** 上传文件** @param file 文件* @return 路径* @throws Exception*/public String uploadFile(File file)  throws Exception {if (file == null || !file.exists()) {return null;}String extName = FilenameUtils.getExtension(file.getName());String path = getStorageClient().upload_file1(FileUtils.readFileToByteArray(file), extName, null);return path;}/*** 下载文件** @param filePath 文件路径* @return 文件字节数据* @throws Exception*/public byte[] downFile(String filePath)  throws Exception {if (StringUtils.isEmpty(filePath)) {Slf4jLogUtil.info("fileUrl == >>文件路径为空...");return null;}String groupName = getGroupName(filePath);String remoteFilename = getPath(filePath, groupName);byte[]  files = getStorageClient().download_file(groupName, remoteFilename);return files;}/*** 删除文件** @param fileUrl 文件路径*/public void deleteFile(String fileUrl)  throws Exception {if (StringUtils.isEmpty(fileUrl)) {Slf4jLogUtil.info("fileUrl == >>文件路径为空...");return;}String groupName = getGroupName(fileUrl);String remoteFilename = getPath(fileUrl, groupName);getStorageClient().delete_file(groupName, remoteFilename);}private StorageClient1 getStorageClient() throws Exception {TrackerClient trackerClient = new TrackerClient();TrackerServer trackerServer = trackerClient.getTrackerServer();StorageClient1 storageClient = new StorageClient1(trackerServer, null);return storageClient;}private String getGroupName(String filePath) {String[] paths = filePath.split("/");if (paths.length == 1) {throw new RRException("解析文件路径错误,有效的路径样式为(group/path) 而当前解析路径为".concat(filePath));} else {String[] var2 = paths;int var3 = paths.length;for (int var4 = 0; var4 < var3; ++var4) {String item = var2[var4];if (item.indexOf("group") != -1) {return item;}}throw new RRException("解析文件路径错误,被解析路径url没有group,当前解析路径为".concat(filePath));}}private String getPath(String filePath, String group) {int pathStartPos = filePath.indexOf(group) + group.length() + 1;return filePath.substring(pathStartPos);}}

 


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部