FastDFS是分布式文件系统。使用 FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。
FastDFS 架构包括 Tracker server 和 Storage server。
Storage Server:文件存储服务器
Tracker Server:追踪调度服务器



Storage Server 向Tracker Server, 汇报当前存储节点的状态信息(包括磁盘剩余空间、文件同步状况等统计信息)
客户端程序连接Tracker Server发给上传请求
Tracker Server计算可用的Storage Server 节点,返回
客户端将文件上传到Storage Server,并获取返回的file_id(包括路径信息和文件名称)
客户端保存请求地址
和文件上传类似
文件下载使用频率并不高,由于客户端记录的访问地址,直接拼接地址访问即可
version: '3.5'
services:
tracker:
image: delron/fastdfs
container_name: tracker
network_mode: "host"
volumes:
- /data/fastdfs/tracker:/var/fdfs
command: tracker
storage:
image: delron/fastdfs
container_name: storage
network_mode: "host"
volumes:
- /data/fastdfs/storage:/var/fdfs
environment:
- TRACKER_SERVER=192.168.136.160:22122
- GROUP_NAME=group1
command: storage
depends_on:
- tracker
docker-compose up –d
tracker服务器地址:192.168.136.160:22122
storage中nginx地址:http://192.168.136.160:8888/
<dependency>
<groupId>com.github.tobatogroupId>
<artifactId>fastdfs-clientartifactId>
<version>1.26.7version>
<exclusions>
<exclusion>
<groupId>ch.qos.logbackgroupId>
<artifactId>logback-classicartifactId>
exclusion>
exclusions>
dependency>
1.yaml文件配置
fdfs:
so-timeout: 1500
connect-timeout: 600
thumb-image: #缩略图参数
width: 150
height: 150
tracker-list: 192.168.136.160:22122 #TrackerList参数
web-server-url: http://192.168.136.160:8888/
2.java上传代码
@Autowired
private FastFileStorageClient client;
@Autowired
private FdfsWebServer webServer;
@GetMapping("testUpload")
public void testUpload() throws FileNotFoundException {
//1、指定文件
File file = new File("D:\\1.jpg");
//2、文件上传
StorePath path = client.uploadFile(new FileInputStream(file), file.length(), "jpg", null);
//3、拼接请求路径
String fullPath = path.getFullPath();
System.out.println(fullPath); //a/b/abc.jpg;
String url = webServer.getWebServerUrl() + fullPath;
System.out.println(url);
}
3.图示
