对象存储服务MinIO

一、MinIO简介

MinIO基于Apache License v2.0开源协议的对象存储服务,可以做为云存储的解决方案用来保存海量的 图片,视频,文档。由于采用Golang实现,服务端可以工作在Windows,Linux, OS X和FreeBSD上。配 置简单,基本是复制可执行程序,单行命令可以运行起来。

MinIO兼容亚马逊S3云存储服务接口,非常适合于存储大容量非结构化的数据,例如图片、视频、日志 文件、备份数据和容器/虚拟机镜像等,而一个对象文件可以是任意大小,从几kb到最大5T不等。

S3 ( Simple Storage Service简单存储服务)

基本概念

  • bucket -- 类比于文件系统的目录
  • Object -- 类比文件系统的文件
  • Keys -- 类比文件名

官网文档: http://docs.minio.org.cn/docs/

1.1MinIO特点

数据保护:

Minio使用Minio Erasure Code(纠删码)来防止硬件故障。即便损坏一半以上的driver,但是仍 然可以从中恢复。

高性能:

作为高性能对象存储,在标准硬件条件下它能达到55GB/s的读、35GB/s的写速率

可扩容:

不同MinIO集群可以组成联邦,并形成一个全局的命名空间,并跨越多个数据中心

SDK支持:

基于Minio轻量的特点,它得到类似Java、Python或Go等语言的sdk支持

有操作页面:

面向用户友好的简单操作界面,非常方便的管理Bucket及里面的文件资源

功能简单:

这一设计原则让MinIO不容易出错、更快启动

丰富的API:

支持文件资源的分享连接及分享链接的过期策略、存储桶操作、文件列表访问及文件上传下载的基 本功能等。

文件变化主动通知:

存储桶(Bucket)如果发生改变,比如上传对象和删除对象,可以使用存储桶事件通知机制进行监 控,并通过以下方式发布出去:AMQP、MQTT、Elasticsearch、Redis、NATS、MySQL、Kafka、 Webhooks等。

二、开箱使用

2.1 安装启动

下载地址:MinIO | Code and downloads to create high performance object storage

具体安装过程参见这位大佬的博客,写的十分详细 Windows安装Minio(超详细)_minio windows安装-CSDN博客

2.2 管理控制台

三、快速入门

3.1创建工程,导入pom依赖

创建minio-demo,对应pom如下

复制代码
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>water-test</artifactId>
        <groupId>com.ape</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>minio-demo</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.minio</groupId>
            <artifactId>minio</artifactId>
            <version>7.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <dependency>
            <groupId>com.ape</groupId>
            <artifactId>water-file-starter</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

</project>

3.2引导类:

java 复制代码
@SpringBootApplication
public class MinIOApplication {

    public static void main(String[] args) {
        SpringApplication.run(MinIOApplication.class,args);
    }
}

3.3 application.yml文件

复制代码
minio:
  accessKey: admin
  secretKey: admin123
  bucket: mybucket
  endpoint: http://localhost:9005
  readPath: http://localhost:9005

3.4创建测试类,上传html文件

java 复制代码
@SpringBootTest
public class MinIOTest {
    public static void main(String[] args) {

        FileInputStream fileInputStream = null;
        try {

            fileInputStream =  new FileInputStream("E:\\water\\demo05.html");

            //1.创建minio链接客户端
            //*******************一定注意,端口是API端口**************************
            MinioClient minioClient = MinioClient.builder().credentials("admin", "12345678").endpoint("http://localhost:9005").build();
            //2.上传
            PutObjectArgs putObjectArgs = PutObjectArgs.builder()
                    .object("list.html")//文件名
                    .contentType("text/html")//文件类型
                    .bucket("zzz")//桶名词  与minio创建的名词一致
                    .stream(fileInputStream, fileInputStream.available(), -1) //文件流
                    .build();
            minioClient.putObject(putObjectArgs);

            System.out.println("http://localhost:9005/ape/list.html");

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @Autowired
    private FileStorageService fileStorageService;

    @Test
    public void testUpdateImgFile() {
        try {
            FileInputStream fileInputStream = new FileInputStream("E:\\water\\dog.jpg");
            String filePath = fileStorageService.uploadImgFile("", "dog.jpg", fileInputStream);
            System.out.println(filePath);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

}
相关推荐
骆晨学长15 分钟前
基于springboot学生健康管理系统的设计与实现
java·开发语言·spring boot·后端·spring
二十雨辰15 分钟前
[苍穹外卖]-09Spring Task定时任务
java·数据库·spring
我是小酒16 分钟前
掌握 Spring:从新手到高手的常见问题汇总
java·后端·spring·springboot
捕风捉你22 分钟前
Spring 源码解读:手动实现Environment抽象与配置属性
后端·spring
时间会证明一切.2 小时前
【Java面试】第十天
java·开发语言·spring·面试
wxin_VXbishe2 小时前
springboot瑜伽课约课小程序-计算机毕业设计源码87936
java·c++·spring boot·python·spring·servlet·php
灯火不休ᝰ3 小时前
7--SpringBoot-后端开发、原理
java·spring boot·spring
ChinaRainbowSea4 小时前
十六,Spring Boot 整合 Druid 以及使用 Druid 监控功能
java·spring boot·后端·spring·web
忘却的纪念6 小时前
基于SpringBoot的考研资讯平台设计与实现
java·spring boot·spring
开 端11 小时前
文件批量添加水印和密码合并单元格完整版
java·ide·spring