手把手教你用Docker Compose一键部署RustFS私有云盘(SpringBoot后端+Vue3前端完整配置)

手把手教你用Docker Compose一键部署RustFS私有云盘(SpringBoot后端+Vue3前端完整配置) 5分钟极速部署基于Docker Compose的RustFS全栈私有云盘实战指南在当今数据驱动的商业环境中企业对于私有云存储的需求呈现爆发式增长。传统公有云存储虽然便捷但长期使用成本高昂且存在数据主权隐忧。本文将展示如何利用Docker Compose快速搭建一个基于RustFS的全栈私有云盘系统从存储后端到用户界面一气呵成。1. 环境准备与架构概览在开始部署前我们需要准备一台满足以下条件的机器操作系统Linux推荐Ubuntu 22.04 LTS硬件配置4核CPU/8GB内存/50GB存储软件依赖Docker 20.10和Docker Compose v2.2整个系统架构分为三个核心组件RustFS存储层基于Rust语言开发的高性能对象存储SpringBoot应用层提供REST API和业务逻辑处理Vue3展示层现代化的用户交互界面提示生产环境建议使用独立服务器部署各组件开发测试可使用单机部署2. 一键部署RustFS存储服务创建docker-compose.yml文件并写入以下内容version: 3.8 services: rustfs: image: rustfs/rustfs:latest container_name: rustfs ports: - 9000:9000 # API端口 - 9001:9001 # 管理控制台 volumes: - rustfs_data:/data environment: - RUSTFS_ROOT_USERadmin - RUSTFS_ROOT_PASSWORDyour_strong_password healthcheck: test: [CMD, curl, -f, http://localhost:9000/minio/health/live] interval: 30s timeout: 5s retries: 3 volumes: rustfs_data:启动服务只需执行docker-compose up -d验证服务是否正常运行docker ps --filter namerustfs --format table {{.Names}}\t{{.Status}}预期输出应显示容器状态为healthy。3. SpringBoot后端服务集成3.1 项目基础配置在SpringBoot项目的application.yml中添加RustFS连接配置rustfs: endpoint: http://rustfs:9000 access-key: admin secret-key: your_strong_password bucket-name: user-files spring: servlet: multipart: max-file-size: 10MB max-request-size: 100MB3.2 文件服务核心实现创建文件存储服务类处理核心逻辑Service RequiredArgsConstructor public class FileStorageService { private final S3Client s3Client; public String uploadFile(MultipartFile file, String userId) { String objectKey String.format(%s/%s-%d, userId, UUID.randomUUID(), System.currentTimeMillis()); s3Client.putObject( PutObjectRequest.builder() .bucket(user-files) .key(objectKey) .contentType(file.getContentType()) .build(), RequestBody.fromInputStream(file.getInputStream(), file.getSize()) ); return objectKey; } public InputStream downloadFile(String objectKey) { return s3Client.getObject( GetObjectRequest.builder() .bucket(user-files) .key(objectKey) .build() ); } }3.3 REST API设计实现文件上传下载的API端点RestController RequestMapping(/api/files) RequiredArgsConstructor public class FileController { private final FileStorageService fileService; PostMapping public ResponseEntityFileUploadResponse uploadFile( RequestParam MultipartFile file, RequestHeader(X-User-Id) String userId) { String objectKey fileService.uploadFile(file, userId); return ResponseEntity.ok( new FileUploadResponse(objectKey, file.getSize()) ); } GetMapping(/{objectKey}) public ResponseEntityResource downloadFile( PathVariable String objectKey) { InputStream fileStream fileService.downloadFile(objectKey); return ResponseEntity.ok() .contentType(MediaType.APPLICATION_OCTET_STREAM) .body(new InputStreamResource(fileStream)); } }4. Vue3前端开发实战4.1 项目初始化与配置创建Vue3项目并安装必要依赖npm init vuelatest cloud-drive-frontend cd cloud-drive-frontend npm install axios pinia element-plus element-plus/icons-vue配置API基础URL在.env文件中VITE_API_BASE_URLhttp://localhost:80804.2 文件上传组件实现创建可拖拽上传的组件template el-upload classupload-demo drag multiple :actionuploadUrl :headersheaders successhandleSuccess el-icon :size60upload-filled //el-icon div classel-upload__text 拖拽文件到此处或em点击上传/em /div /el-upload /template script setup import { UploadFilled } from element-plus/icons-vue import { useUserStore } from /stores/user const userStore useUserStore() const uploadUrl ${import.meta.env.VITE_API_BASE_URL}/api/files const headers { X-User-Id: userStore.userId } const handleSuccess (response) { ElMessage.success(文件上传成功) } /script4.3 文件列表展示实现带分页的文件列表组件template el-table :datafiles stylewidth: 100% el-table-column propname label文件名 / el-table-column propsize label大小 width120 template #default{row} {{ formatSize(row.size) }} /template /el-table-column el-table-column label操作 width180 template #default{row} el-button clickdownload(row)下载/el-button el-button clickremove(row) typedanger删除/el-button /template /el-table-column /el-table /template script setup import { ref, onMounted } from vue import { ElMessage } from element-plus const files ref([]) const loadFiles async () { const res await axios.get(/api/files) files.value res.data } const formatSize (bytes) { const units [B, KB, MB, GB] let size bytes let unitIndex 0 while (size 1024 unitIndex units.length) { size / 1024 unitIndex } return ${size.toFixed(2)} ${units[unitIndex]} } onMounted(() { loadFiles() }) /script5. 全栈Docker Compose集成部署将前后端服务整合到之前的docker-compose.yml中version: 3.8 services: rustfs: image: rustfs/rustfs:latest # ...保持原有配置不变 backend: build: ./backend ports: - 8080:8080 environment: - RUSTFS_ENDPOINThttp://rustfs:9000 - RUSTFS_ACCESS_KEYadmin - RUSTFS_SECRET_KEYyour_strong_password depends_on: rustfs: condition: service_healthy frontend: build: ./frontend ports: - 80:80 depends_on: - backend volumes: rustfs_data:构建并启动完整系统docker-compose up -d --build访问http://localhost即可使用完整的私有云盘系统。这套方案特别适合需要快速搭建内部文件共享平台的中小企业所有组件都容器化部署维护升级十分便捷。