分类
RustFS
软件工具
2026-08-06
5

RustFS

世界上增长最快的分布式对象存储,根据 GitHub 的数据,RustFS 是增长最快的分布式对象存储。 RustFS 用热门安全的 Rust 语言开发,兼容 S3 协议。适用于 AI/ML 及海量数据存储、大数据、互联网、工业和保密存储等全部场景,支持国产保密设备和系统。

文档地址

安装

Github下载地址

注意:

  • 树莓派4b使用:rustfs-linux-aarch64-musl-latest.zip
  • 正常ubuntu使用:rustfs-linux-x86_64-musl-latest.zip

第一步:下载安装包

wget xxx
unzip rustfs-linux-x86_64-musl-latest.zip
mv rustfs /usr/local/bin/
cd /usr/local/bin/
chmod +x rustfs

第二步:配置系统服务

注意挂载磁盘调整:/root/data/rustfs_oss/

sudo tee /etc/systemd/system/rustfs.service <<'EOF'
[Unit]
Description=RustFS Object Storage Server
Documentation=https://rustfs.com/docs/
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
NotifyAccess=main
User=root
Group=root

Environment="RUSTFS_ACCESS_KEY=rustfsadmin"
Environment="RUSTFS_SECRET_KEY=rustfsadmin"
Environment="RUSTFS_OBS_LOG_DIRECTORY=/var/logs/rustfs/"

ExecStart=/usr/local/bin/rustfs \
  server \
  --address :9000 \
  --console-enable \
  /root/data/rustfs_oss/

StandardOutput=append:/var/logs/rustfs/rustfs.log
StandardError=append:/var/logs/rustfs/rustfs-err.log

Restart=always
RestartSec=10s
TimeoutStartSec=30s

[Install]
WantedBy=multi-user.target
EOF

第三步:启动

sudo mkdir -p /root/data/rustfs_oss /var/logs/rustfs /opt/tls
sudo chmod -R 750 /root/data/rustfs_oss* /var/logs/rustfs


# 1. 重新加载配置
sudo systemctl daemon-reload

# 2. 启动服务
sudo systemctl start rustfs

# 3. 查看状态
systemctl status rustfs

访问

IP:9000  API 数据接口
IP:9001  后台管理页面

Java接口示例

依赖

<!--RustFS-->
<dependency>
  <groupId>software.amazon.awssdk</groupId>
  <artifactId>s3</artifactId>
  <version>2.25.27</version>
</dependency>

代码

package com.fan.model.image;

import com.fan.entity.vo.ComResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.*;

import java.net.URI;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

/**
 * 文件上传
 */
@Slf4j
@Controller
public class ImageController {

    /**
     * 图片上传
     */
    @RequestMapping("/image/upload")
    @ResponseBody
    public ComResult<String> uploadImg(@RequestParam("file") MultipartFile file) throws IOException {
        // 文件为空
        if (file.isEmpty()) {
            return ComResult.failMsg("文件不能为空");
        }
        // 文件后缀
        String suffix = Objects.requireNonNull(file.getOriginalFilename()).substring(file.getOriginalFilename().lastIndexOf("."));
        // 文件格式限制
        if (!suffix.contains("png") && !suffix.contains("jpg") && !suffix.contains("gif")) {
            return ComResult.failMsg("仅支持png/jpg/gif图片");
        }
        // 随机数字6位数字,多机模式
        String random = String.valueOf((int) (Math.random() * 1000000));
        // 新的文件名
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String newFileName = sdf.format(new Date());
        // 最终文件名
        String name = newFileName + "_" + random;
        // 完整文件名
        String objectName = name + suffix;

        // 初始化 S3 客户端
        S3Client s3 = S3Client.builder()
                .endpointOverride(URI.create("http://8.156.74.169:6003")) // RustFS 地址
                .region(Region.US_EAST_1) // 可写死,RustFS 不校验 region
                .credentialsProvider(
                        StaticCredentialsProvider.create(
                                AwsBasicCredentials.create("xxx", "xxx")
                        )
                )
                .forcePathStyle(true) // 关键配置!RustFS 需启用 Path-Style
                .build();

        // Bucket
        String bucket = "house";
        // 上传文件
        s3.putObject(
                PutObjectRequest.builder().bucket(bucket).key(objectName).build(),
                RequestBody.fromByteBuffer(
                        java.nio.ByteBuffer.wrap(file.getBytes())
                )
        );
        // 返回图片请求路径
        return ComResult.data("添加成功", "https://fanmr.cn/oss/" + bucket + "/" + objectName);
    }

}
目录
统计
23
分类
218
文档
7
坚持