1. fastdfs: https://github.com/happyfish100/fastdfs/tags
2. Libfastcommon: https://github.com/happyfish100/libfastcommon/tags
3. Libserverframe: https://github.com/happyfish100/libserverframe/tags
上传相关文件如下图
2. 进入Libserverframe目录 执行 1 ./make 然后执行2 ./make install
5. 检测是否可连接 fdfs_monitor /etc/fdfs/client.conf
# 先停掉nginx服务
/usr/local/nginx/sbin/nginx -s stop
# 进入解压包目录
cd /usr/local/nginx-1.12.1/
# 添加模块
./configure --add-module=/usr/local/fastdfs/fastdfs-nginx-module-1.23/src
#重新编译、安装
make && make install
5. 复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录, 并修改
cd /usr/local/fastdfs/fastdfs-nginx-module-1.23/ /src
cp mod_fastdfs.conf /etc/fdfs/
cd /usr/local/fastdfs/fastdfs-6.9.4/
cp anti-steal.jpg http.conf mime.types /etc/fdfs/
location ~/group([0-9])/M00 {
ngx_fastdfs_module;
}
listen 8089 端口值是要与 /etc/fdfs/storage.conf 中的 http.server_port=8089 相对应。如果改成其它端口,则需要统一,同时在防火墙中打开该端口。location 的配置,如果有多个group则配置location ~/group([0-9])/M00 ,没有则不用配group。
I. 启动nginx 打印如下则成功
远程访问需要开通相关端口 如示例配置中端口
Nginx 8089
tracker 22122
storage 23000
<dependency>
<groupId>com.github.tobatogroupId>
<artifactId>fastdfs-clientartifactId>
<version>1.27.2version>
dependency>
fdfs:
connect-timeout: 60
tracker-list:
- 192.168.1.156:22122 #f服务地址
pool:
max-total: 200
max-total-per-key: 50
max-wait-millis: 5000
thumb-image:
height: 300
width: 300
@RestController
public class FastDFSController {
@Autowired
private FastFileStorageClient fastFileStorageClient;
@PostMapping("/upload")
public StorePath upload(MultipartFile file) throws Exception {
String originalFilename = file.getOriginalFilename();
String fileName = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
StorePath storePath = fastFileStorageClient.uploadFile(file.getInputStream(), file.getSize(), fileName, null);
String fullPath = storePath.getFullPath();
return storePath;
}
@GetMapping("/download")
public void download(String fullPath, HttpServletRequest request, HttpServletResponse response) throws Exception {
int index = fullPath.indexOf("/");
String groupName = fullPath.substring(0, index);
String path = fullPath.substring(index + 1);
byte[] bytes = fastFileStorageClient.downloadFile(groupName, path, new DownloadByteArray());
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("下载文件名.jpg", "UTF-8"));
ServletOutputStream outputStream = response.getOutputStream();
IOUtils.write(bytes, outputStream);
}
}
参考:
https://www.cnblogs.com/chiangchou/p/fastdfs.html
https://blog.csdn.net/qq_64011418/article/details/132226771