徐州网站建设xzqjwl,没有域名如何访问网站,青岛栈桥门票多少钱,域名地址大全MINIO干什么用的#xff1a; AI数据基础设施的对象存储 为人工智能系统提供数据支持#xff0c;数据存储#xff1b;对象存储#xff08;Object Storage#xff09;是一种数据存储架构#xff0c;它以对象为单位来处理、存储和检索数据#xff0c;每个对象都包含了数据本…MINIO干什么用的 AI数据基础设施的对象存储 为人工智能系统提供数据支持数据存储对象存储Object Storage是一种数据存储架构它以对象为单位来处理、存储和检索数据每个对象都包含了数据本身以及元数据MinIO存储的元数据主要包括对象的描述信息如用户account、存储桶bucket以及存储桶索引bucket index等对象存储系统通常通过基于HTTP或HTTPS协议的API应用程序编程接口进行数据读写 MINIO是使用go语言进行开发的。
MinIO具有双重许可
开源GNU AGPL v3完全免费商业企业许可证收费
在下载的时候就可以选择免费的AGPL许可。 MINIO的下载(LINUX版本)
wget https://dl.min.io/server/minio/release/linux-amd64/minio #下载
chmod x minio #赋予可执行权限
MINIO_ROOT_USERadmin MINIO_ROOT_PASSWORDpassword ./minio server /mnt/data --console-address :9001 #MINIO服务启动MINIO_ROOT_USER指定MinIO的用户名MINIO_ROOT_PASSWORD指定MinIO的密码/mnt/data指定MinIO服务器用于存储数据的目录console-address :9001 指定MinIO控制台的监听地址和端口 使用Docker启动运行MinIO
拉取镜像
docker pull minio/minio启动MinIO容器
docker run -p 9000:9000 -p 9001:9001 minio/minio server /mnt/docker/data --console-address :9001Springboot整合Minio
导入依赖 dependencygroupIdio.minio/groupIdartifactIdminio/artifactIdversion8.2.1/version/dependency编写config配置类
package com.example.springboot_demo.config;import io.minio.MinioClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;Configuration
public class MinIOConfig {Beanpublic MinioClient minioClient(){return MinioClient.builder().endpoint(http://192.168.114.128:9000).credentials(minioadmin,minioadmin).build();}
}
编写service
package com.example.springboot_demo.service;import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;Service
public class MinIOService {Autowiredprivate MinioClient minioClient;public void testMinioClient(){System.out.println(minioClient);}
}
写测试代码
package com.example.springboot_demo;import com.example.springboot_demo.service.MinIOService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;SpringBootTest
class SpringbootDemoApplicationTests {AutowiredMinIOService minIOService;Testvoid contextLoads() {minIOService.testMinioClient();}}
控制台输出 过程中可能碰到的问题看这 MinIO中的Bucket、Object
Bucket是存储Object的逻辑空间每个Bucket之间的数据是相互隔离的对用户而言相当于存放文件的顶层文件夹Object是存储到MinIO的基本对象对用户而言相当于文件
MinIO是线程安全的
MinioClient的常用API
bucketExists() 用于检查指定的存储桶是否存在返回布尔值表示存储桶是否存在 Autowiredprivate MinioClient minioClient;Testvoid test01() throws Exception {boolean isBuketExists minioClient.bucketExists(BucketExistsArgs.builder().bucket(myfile).build());//判断myfile bucket是否存在System.out.println(isBuketExists);}makeBucket() 用于创建一个新的存储桶bucket需要指定存储桶的名称 Autowiredprivate MinioClient minioClient;Testvoid test02() throws Exception{//创建一个myfile的bucketminioClient.makeBucket(MakeBucketArgs.builder().bucket(myfile).build());}登录http://ip地址:9001可以看到新添加的myfile
listBuckets() 用于列出用户有权访问的所有存储桶返回存储桶的列表 Autowiredprivate MinioClient minioClient;Testvoid test03() throws Exception{ListBucket bucketList minioClient.listBuckets();bucketList.forEach(bucket - {System.out.println(bucket.name()--bucket.creationDate());});}removeBucket() 用于删除一个已存在的存储桶bucket删除失败会抛出异常 Autowiredprivate MinioClient minioClient;Testvoid test04() throws Exception{minioClient.removeBucket(RemoveBucketArgs.builder().bucket(myfile).build());}MinioClient的常用API
putObject() 用于上传文件到指定的存储桶 Autowiredprivate MinioClient minioClient;Testvoid test06() throws Exception{File file new File(F:\\pic.jpg);minioClient.putObject(PutObjectArgs.builder().bucket(myfile).object(test.jpg).stream(new FileInputStream(file),file.length(),-1).build());//bucket(myfile):存到哪个bucket//object(test.jpg):存储的名字//stream(new FileInputStream(file),file.length(),-1)//Few FileInputStream(file):输入流//file.length():输入流的长度//-1:开启缓冲区的大小-1表示系统自己设定缓冲区大小}statObject() 用于检查指定的对象文件的状态 Autowiredprivate MinioClient minioClient;Testvoid test07() throws Exception{StatObjectResponse statObjectResponse minioClient.statObject(StatObjectArgs.builder().bucket(myfile).object(test.jpg).build());System.out.println(statObjectResponse);}getPresignedObjectUrl() 用于生成一个对象文件的签名URL以便可以通过HTTP访问 Testvoid test08() throws Exception{String objectUrl minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder().bucket(myfile).object(test.jpg).method(Method.GET).build());System.out.println(objectUrl);}输出 192.168.114.129:9000/myfile/test.jpg?X-Amz-AlgorithmAWS4-HMAC-SHA256X-A…… 若想通过192.168.114.129:9000/myfile/test.jpg访问文件需要修改权限 . 方式一在web管理后台修改访问策略修改为 public bucket-myfile-Summary-Access Policy-public 方式二:通过客户端API修改 Testvoid test02() throws Exception{minioClient.makeBucket(MakeBucketArgs.builder().bucket(myfile).build());String policyJsonString \{\Version\:\2012-10-17\,\Statement\\\:[{\\\Sid\\\:\\\PublicRead\\\,\\\Effect\\\:\\\Allow\\\,\\\Principal\\\:{\\\AWS\\\:\\\*\\\},\\\Action\\\:[\\\s3:GetObject\\\],\\\Resource\\\:[\\\arn:aws:s3:::\ bucketName \/*\\\]}]}\;;minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(myfile).config(policyJsonString).build());}getObject() 用于从指定的存储桶中下载文件 Testvoid test09() throws Exception{GetObjectResponse getObjectResponse minioClient.getObject(GetObjectArgs.builder().bucket(myfile).object(test.jpg).build());}listObjects() 用于列出指定存储桶中的所有对象文件 Testvoid test010() throws Exception{IterableResultItem listObjects minioClient.listObjects(ListObjectsArgs.builder().bucket(myfile).build());listObjects.forEach(itemResult-{try {Item item itemResult.get();System.out.println(item.objectName());} catch (Exception e) {e.printStackTrace();}});}removeObject() 用于删除指定存储桶中的对象需要指定存储桶名称和对象键 Testvoid test011() throws Exception{minioClient.removeObject(RemoveObjectArgs.builder().bucket(myfile).object(test.jpg).build());}