Linux部署私有文件管理系统MinIO

news2025/7/30 17:41:32

最近需要用到一个文件管理服务,但是又不想花钱,所以就想着自己搭建一个,刚好我们用的一个开源框架已经集成了MinIO,所以就选了这个
我这边对文件服务性能要求不是太高,单机版就可以
安装非常简单,几个命令就可以

# 下载服务文件
wget https://dl.min.io/server/minio/release/linux-amd64/minio
# 设置权限
chmod +x minio
# 移动目录方便执行
sudo mv minio /usr/local/bin/
# 创建数据目录
mkdir -p /data/minio
# 添加用户
export MINIO_ROOT_USER=minioadmin
# 添加密码
export MINIO_ROOT_PASSWORD=minio123

上面配置完后我们再来配置开机自启服务,直接执行下面命令即可

cat <<EOF > /etc/systemd/system/minio.service
[Unit]
Description=MinIO Object Storage
After=network.target

[Service]
User=root
ExecStart=/usr/local/bin/minio server /data/minio --console-address ":9001"
Environment=MINIO_ROOT_USER=minioadmin
Environment=MINIO_ROOT_PASSWORD=minio123
Restart=always
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
EOF

然后依次执行下面的命令

# 加载配置
systemctl daemon-reexec
# 加入开机项
systemctl enable minio
# 启动服务
systemctl start minio
# 查看服务
systemctl status minio

如果 systemctl status minio 返回下面内容就说明启动成功了

[root@ecm-74de bin]# systemctl status minio
● minio.service - MinIO Server
   Loaded: loaded (/etc/systemd/system/minio.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2025-06-09 16:09:49 CST; 2h 51min ago
 Main PID: 25443 (minio)
    Tasks: 14
   Memory: 235.5M
   CGroup: /system.slice/minio.service
           └─25443 /usr/local/bin/minio server /data/minio --console-address :9001

Jun 09 16:09:49 ecm-74de systemd[1]: Started MinIO Server.
Jun 09 16:09:49 ecm-74de minio[25443]: MinIO Object Storage Server
Jun 09 16:09:49 ecm-74de minio[25443]: Copyright: 2015-2025 MinIO, Inc.
Jun 09 16:09:49 ecm-74de minio[25443]: License: GNU AGPLv3 - https://www.gnu.org/licenses/agpl-3.0.html
Jun 09 16:09:49 ecm-74de minio[25443]: Version: RELEASE.2025-05-24T17-08-30Z (go1.24.3 linux/amd64)
Jun 09 16:09:49 ecm-74de minio[25443]: API: http://10.0.0.5:9000  http://127.0.0.1:9000
Jun 09 16:09:49 ecm-74de minio[25443]: WebUI: http://10.0.0.5:9001 http://127.0.0.1:9001
Jun 09 16:09:49 ecm-74de minio[25443]: Docs: https://docs.min.io
Jun 09 16:09:49 ecm-74de minio[25443]: WARN: Detected Linux kernel version older than 4.0 release, there are some known potential performance problems with this kernel version. MinIO recommends a minimum of 4.x linux... best performance
Hint: Some lines were ellipsized, use -l to show in full.

这里我给服务配置了两个域名,一个是控制台的,一个是给 api 调用的,分别对应两个端口 9000 和 9001
控制台 nginx 配置
这里主要注意里面有个 websocket 配置,一开始没有配置这个发现文件列表刷新不出来

server {
    listen 80;
    server_name oss-console.sakura.com;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name oss-console.sakura.com;

    ssl_certificate /etc/nginx/ssl/sakura.com.pem;
    ssl_certificate_key /etc/nginx/ssl/sakura.com.key;

    client_max_body_size 512m;
	
	# WebSocket 支持
	location /ws/ {
		proxy_pass http://127.0.0.1:9001;

		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";

		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto https;

		proxy_buffering off;
	}

    # 控制台页面(9001)
    location / {
        proxy_pass http://127.0.0.1:9001;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_buffering off;
    }

    access_log /etc/nginx/logs/oss-console.access.log;
    error_log  /etc/nginx/logs/oss-console.error.log;
}

api nginx 配置

server {
    listen 80;
    server_name oss.sakura.com;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name oss.sakura.com;

    ssl_certificate /etc/nginx/ssl/sakura.com.pem;
    ssl_certificate_key /etc/nginx/ssl/sakura.com.key;

    client_max_body_size 512m;

    # S3 API 接口(9000)
    location / {
        proxy_pass http://127.0.0.1:9000/;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_buffering off;
    }

    access_log /etc/nginx/logs/oss.access.log;
    error_log  /etc/nginx/logs/oss.error.log;
}

重启 nginx 配置

# 校验配置文件语法
nginx -t
# 重新加载配置
nginx -s reload

正常情况下访问 https://oss-console.sakura.com 就可以看到下面页面了
在这里插入图片描述
然后就是项目集成
首先是 pom
我这里多了个 okhttp 是因为启动的时候提示 minio 里面自带的 okhttp 和我之前的冲突了

		<dependency>
            <groupId>io.minio</groupId>
            <artifactId>minio</artifactId>
            <version>8.5.3</version>
        </dependency>

        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>4.12.0</version>
        </dependency>

然后 yml 配置文件

minio:
  endpoint: https://oss.sakura.com
  access-key: minioadmin
  secret-key: sakura123
  bucket: doyike-bucket

配置文件

import io.minio.MinioClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Sakura
 * @date 2025/6/9 16:37
 */
@Configuration
@ConfigurationProperties(prefix = "minio")
@Data
public class MinioConfig {
    private String endpoint;
    private String accessKey;
    private String secretKey;
    private String bucket;

    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(endpoint)
                .credentials(accessKey, secretKey)
                .build();
    }
}

测试方法

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Sakura
 * @date 2025/6/9 16:38
 */
@RestController
@RequestMapping("/minio")
@RequiredArgsConstructor
public class MinioController {

    private final MinioService minioService;

    @PostMapping("/upload")
    public ResponseEntity<String> upload(@RequestParam("file") MultipartFile file) {
        try {
            String url = minioService.uploadFile(file);
            return ResponseEntity.ok(url);
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
                    .body("上传失败:" + e.getMessage());
        }
    }
}

这里特别要注意,MinIO 默认所有的桶都是私有的,上传的文件访问会有很多限制,然后访问连接特别的长,然后我在控制台又没有找到可以设置权限的地方(不知道是不是安装有问题),接着我又安装 mc 发现还是设置不了,没办法我就自己写了一个修改桶权限的 main 方法,这样上传的文件就能直接域名加桶加文件名访问了

import io.minio.*;
import io.minio.errors.MinioException;
import io.minio.http.Method;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

/**
 * @author Sakura
 * @date 2025/6/9 16:40
 */
@Service
@RequiredArgsConstructor
public class MinioService {

    private final MinioClient minioClient;
    private final MinioConfig minioConfig;

    public String uploadFile(MultipartFile file) throws Exception {
        String bucket = minioConfig.getBucket();
        String filename = UUID.randomUUID() + "_" + file.getOriginalFilename();

        // 自动创建 bucket(可选)
        boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucket).build());
        if (!found) {
            minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
        }

        // 上传文件
        minioClient.putObject(
                PutObjectArgs.builder()
                        .bucket(bucket)
                        .object(filename)
                        .stream(file.getInputStream(), file.getSize(), -1)
                        .contentType(file.getContentType())
                        .build()
        );

        // 返回可访问链接(可选)
        return minioClient.getPresignedObjectUrl(
                GetPresignedObjectUrlArgs.builder()
                        .bucket(bucket)
                        .object(filename)
                        .method(Method.GET)
                        .build()
        );
    }

    public static void main(String[] args) {
        try {
            // 连接 MinIO 服务端,替换为你的配置
            MinioClient minioClient = MinioClient.builder()
                    .endpoint("https://oss.sakura.com")
                    .credentials("minioadmin", "sakura123")
                    .build();

            String bucketName = "doyike-bucket";

            // 桶公开读权限策略,JSON格式(允许匿名读取所有对象)
            String policyJson = "{\n" +
                    "  \"Version\":\"2012-10-17\",\n" +
                    "  \"Statement\":[\n" +
                    "    {\n" +
                    "      \"Effect\":\"Allow\",\n" +
                    "      \"Principal\":{\"AWS\":[\"*\"]},\n" +
                    "      \"Action\":[\"s3:GetObject\"],\n" +
                    "      \"Resource\":[\"arn:aws:s3:::" + bucketName + "/*\"]\n" +
                    "    }\n" +
                    "  ]\n" +
                    "}";

            // 设置桶策略
            minioClient.setBucketPolicy(
                    SetBucketPolicyArgs.builder()
                            .bucket(bucketName)
                            .config(policyJson)
                            .build()
            );

            System.out.println("桶权限设置成功,桶 " + bucketName + " 现在公开可读");

        } catch (MinioException e) {
            System.err.println("Error occurred: " + e);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

最后上传的文件可以登录控制台查看的
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2407000.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Ubuntu系统复制(U盘-电脑硬盘)

所需环境 电脑自带硬盘&#xff1a;1块 (1T) U盘1&#xff1a;Ubuntu系统引导盘&#xff08;用于“U盘2”复制到“电脑自带硬盘”&#xff09; U盘2&#xff1a;Ubuntu系统盘&#xff08;1T&#xff0c;用于被复制&#xff09; &#xff01;&#xff01;&#xff01;建议“电脑…

认识CMake并使用CMake构建自己的第一个项目

1.CMake的作用和优势 跨平台支持&#xff1a;CMake支持多种操作系统和编译器&#xff0c;使用同一份构建配置可以在不同的环境中使用 简化配置&#xff1a;通过CMakeLists.txt文件&#xff0c;用户可以定义项目结构、依赖项、编译选项等&#xff0c;无需手动编写复杂的构建脚本…

HybridVLA——让单一LLM同时具备扩散和自回归动作预测能力:训练时既扩散也回归,但推理时则扩散

前言 如上一篇文章《dexcap升级版之DexWild》中的前言部分所说&#xff0c;在叠衣服的过程中&#xff0c;我会带着团队对比各种模型、方法、策略&#xff0c;毕竟针对各个场景始终寻找更优的解决方案&#xff0c;是我个人和我司「七月在线」的职责之一 且个人认为&#xff0c…

协议转换利器,profinet转ethercat网关的两大派系,各有千秋

随着工业以太网的发展&#xff0c;其高效、便捷、协议开放、易于冗余等诸多优点&#xff0c;被越来越多的工业现场所采用。西门子SIMATIC S7-1200/1500系列PLC集成有Profinet接口&#xff0c;具有实时性、开放性&#xff0c;使用TCP/IP和IT标准&#xff0c;符合基于工业以太网的…

9-Oracle 23 ai Vector Search 特性 知识准备

很多小伙伴是不是参加了 免费认证课程&#xff08;限时至2025/5/15&#xff09; Oracle AI Vector Search 1Z0-184-25考试&#xff0c;都顺利拿到certified了没。 各行各业的AI 大模型的到来&#xff0c;传统的数据库中的SQL还能不能打&#xff0c;结构化和非结构的话数据如何和…

mac:大模型系列测试

0 MAC 前几天经过学生优惠以及国补17K入手了mac studio,然后这两天亲自测试其模型行运用能力如何&#xff0c;是否支持微调、推理速度等能力。下面进入正文。 1 mac 与 unsloth 按照下面的进行安装以及测试&#xff0c;是可以跑通文章里面的代码。训练速度也是很快的。 注意…

DBLP数据库是什么?

DBLP&#xff08;Digital Bibliography & Library Project&#xff09;Computer Science Bibliography是全球著名的计算机科学出版物的开放书目数据库。DBLP所收录的期刊和会议论文质量较高&#xff0c;数据库文献更新速度很快&#xff0c;很好地反映了国际计算机科学学术研…

Xela矩阵三轴触觉传感器的工作原理解析与应用场景

Xela矩阵三轴触觉传感器通过先进技术模拟人类触觉感知&#xff0c;帮助设备实现精确的力测量与位移监测。其核心功能基于磁性三维力测量与空间位移测量&#xff0c;能够捕捉多维触觉信息。该传感器的设计不仅提升了触觉感知的精度&#xff0c;还为机器人、医疗设备和制造业的智…

DeepSeek源码深度解析 × 华为仓颉语言编程精粹——从MoE架构到全场景开发生态

前言 在人工智能技术飞速发展的今天&#xff0c;深度学习与大模型技术已成为推动行业变革的核心驱动力&#xff0c;而高效、灵活的开发工具与编程语言则为技术创新提供了重要支撑。本书以两大前沿技术领域为核心&#xff0c;系统性地呈现了两部深度技术著作的精华&#xff1a;…

stm32wle5 lpuart DMA数据不接收

配置波特率9600时&#xff0c;需要使用外部低速晶振

Unity中的transform.up

2025年6月8日&#xff0c;周日下午 在Unity中&#xff0c;transform.up是Transform组件的一个属性&#xff0c;表示游戏对象在世界空间中的“上”方向&#xff08;Y轴正方向&#xff09;&#xff0c;且会随对象旋转动态变化。以下是关键点解析&#xff1a; 基本定义 transfor…

Elastic 获得 AWS 教育 ISV 合作伙伴资质,进一步增强教育解决方案产品组合

作者&#xff1a;来自 Elastic Udayasimha Theepireddy (Uday), Brian Bergholm, Marianna Jonsdottir 通过搜索 AI 和云创新推动教育领域的数字化转型。 我们非常高兴地宣布&#xff0c;Elastic 已获得 AWS 教育 ISV 合作伙伴资质。这一重要认证表明&#xff0c;Elastic 作为 …

MySQL的pymysql操作

本章是MySQL的最后一章&#xff0c;MySQL到此完结&#xff0c;下一站Hadoop&#xff01;&#xff01;&#xff01; 这章很简单&#xff0c;完整代码在最后&#xff0c;详细讲解之前python课程里面也有&#xff0c;感兴趣的可以往前找一下 一、查询操作 我们需要打开pycharm …

渗透实战PortSwigger靶场:lab13存储型DOM XSS详解

进来是需要留言的&#xff0c;先用做简单的 html 标签测试 发现面的</h1>不见了 数据包中找到了一个loadCommentsWithVulnerableEscapeHtml.js 他是把用户输入的<>进行 html 编码&#xff0c;输入的<>当成字符串处理回显到页面中&#xff0c;看来只是把用户输…

[论文阅读]TrustRAG: Enhancing Robustness and Trustworthiness in RAG

TrustRAG: Enhancing Robustness and Trustworthiness in RAG [2501.00879] TrustRAG: Enhancing Robustness and Trustworthiness in Retrieval-Augmented Generation 代码&#xff1a;HuichiZhou/TrustRAG: Code for "TrustRAG: Enhancing Robustness and Trustworthin…

水泥厂自动化升级利器:Devicenet转Modbus rtu协议转换网关

在水泥厂的生产流程中&#xff0c;工业自动化网关起着至关重要的作用&#xff0c;尤其是JH-DVN-RTU疆鸿智能Devicenet转Modbus rtu协议转换网关&#xff0c;为水泥厂实现高效生产与精准控制提供了有力支持。 水泥厂设备众多&#xff0c;其中不少设备采用Devicenet协议。Devicen…

Linux中《基础IO》详细介绍

目录 理解"文件"狭义理解广义理解文件操作的归类认知系统角度文件类别 回顾C文件接口打开文件写文件读文件稍作修改&#xff0c;实现简单cat命令 输出信息到显示器&#xff0c;你有哪些方法stdin & stdout & stderr打开文件的方式 系统⽂件I/O⼀种传递标志位…

【Veristand】Veristand环境安装教程-Linux RT / Windows

首先声明&#xff0c;此教程是针对Simulink编译模型并导入Veristand中编写的&#xff0c;同时需要注意的是老用户编译可能用的是Veristand Model Framework&#xff0c;那个是历史版本&#xff0c;且NI不会再维护&#xff0c;新版本编译支持为VeriStand Model Generation Suppo…

Ubuntu系统多网卡多相机IP设置方法

目录 1、硬件情况 2、如何设置网卡和相机IP 2.1 万兆网卡连接交换机&#xff0c;交换机再连相机 2.1.1 网卡设置 2.1.2 相机设置 2.3 万兆网卡直连相机 1、硬件情况 2个网卡n个相机 电脑系统信息&#xff0c;系统版本&#xff1a;Ubuntu22.04.5 LTS&#xff1b;内核版本…

《Docker》架构

文章目录 架构模式单机架构应用数据分离架构应用服务器集群架构读写分离/主从分离架构冷热分离架构垂直分库架构微服务架构容器编排架构什么是容器&#xff0c;docker&#xff0c;镜像&#xff0c;k8s 架构模式 单机架构 单机架构其实就是应用服务器和单机服务器都部署在同一…