日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

分布式文件系统MinIO

發(fā)布時(shí)間:2023/12/18 windows 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 分布式文件系统MinIO 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文件存儲(chǔ)方式對比

常見的分布式文件系統(tǒng)

1, MinIO簡介

MinIO基于Apache License v2.0開源協(xié)議的對象存儲(chǔ)服務(wù),可以做為云存儲(chǔ)的解決方案用來保存海量的圖片,視頻,文檔。

  • 由于采用Golang實(shí)現(xiàn),服務(wù)端可以工作在Windows,Linux, OS X和FreeBSD上。配置簡單,基本是復(fù)制可執(zhí)行程序,單行命令可以運(yùn)行起來。
  • MinIO兼容亞馬遜S3( Simple Storage Service簡單存儲(chǔ)服務(wù))云存儲(chǔ)服務(wù)接口,非常適合于存儲(chǔ)大容量非結(jié)構(gòu)化的數(shù)據(jù),例如圖片、視頻、日志文件、備份數(shù)據(jù)和容器/虛擬機(jī)鏡像等,而一個(gè)對象文件可以是任意大小,從幾kb到最大5T不等。
  • 官網(wǎng)文檔:http://docs.minio.org.cn/docs/

基本概念

  • bucket – 類比于文件系統(tǒng)的目錄
  • Object – 類比文件系統(tǒng)的文件
  • Keys – 類比文件名

2 MinIO特點(diǎn)

  • 數(shù)據(jù)保護(hù)
    Minio使用Minio Erasure Code(糾刪碼)來防止硬件故障。即便損壞一半以上的driver,但是仍然可以從中恢復(fù)。
  • 高性能
    作為高性能對象存儲(chǔ),在標(biāo)準(zhǔn)硬件條件下它能達(dá)到55GB/s的讀、35GB/s的寫速率
  • 可擴(kuò)容
    不同MinIO集群可以組成聯(lián)邦,并形成一個(gè)全局的命名空間,并跨越多個(gè)數(shù)據(jù)中心
  • SDK支持
    基于Minio輕量的特點(diǎn),它得到類似Java、Python或Go等語言的sdk支持
  • 有操作頁面
    面向用戶友好的簡單操作界面,非常方便的管理Bucket及里面的文件資源
  • 功能簡單
    這一設(shè)計(jì)原則讓MinIO不容易出錯(cuò)、更快啟動(dòng)
  • 豐富的API
    支持文件資源的分享連接及分享鏈接的過期策略、存儲(chǔ)桶操作、文件列表訪問及文件上傳下載的基本功能等。
  • 文件變化主動(dòng)通知
    存儲(chǔ)桶(Bucket)如果發(fā)生改變,比如上傳對象和刪除對象,可以使用存儲(chǔ)桶事件通知機(jī)制進(jìn)行監(jiān)控,并通過以下方式發(fā)布出去:AMQP、MQTT、Elasticsearch、Redis、NATS、MySQL、Kafka、Webhooks等。

3 開箱使用

3.1 安裝啟動(dòng)

我們提供的鏡像中已經(jīng)有minio的環(huán)境

我們可以使用docker進(jìn)行環(huán)境部署和啟動(dòng)

docker run -p 9000:9000 -p 9090:9090 \--net=host \--name minio \-d --restart=always \-e "MINIO_ACCESS_KEY=username" \-e "MINIO_SECRET_KEY=password" \-v /mydata/minio/data:/mydata/minio/data \-v /mydata/minio/config:/mydata/minio/config \minio/minio server \/data --console-address ":9090" -address ":9000"

3.2 管理控制臺(tái)

我們在地址欄輸入:http://192.168.200.130:9000/即可進(jìn)入登錄界面。

Access Key為minio ,Secret_key 為minio123 進(jìn)入系統(tǒng)后可以看到主界面

基本概念

  • bucket – 類比于文件系統(tǒng)的目錄
  • Object – 類比文件系統(tǒng)的文件
  • Keys – 類比文件名

點(diǎn)擊右下角的“+”號(hào) ,點(diǎn)擊下面的圖標(biāo),創(chuàng)建一個(gè)桶

4 快速入門

4.1 創(chuàng)建工程,導(dǎo)入依賴

創(chuàng)建minio-demo,對應(yīng)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>minio-test</artifactId><groupId>com.test</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></dependencies></project>

4.2 上傳文件

SpringBoot引導(dǎo)類:

package com.test.minio;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class MinIOApplication {public static void main(String[] args) {SpringApplication.run(MinIOApplication.class,args);}}

創(chuàng)建測試類,上傳html文件

package com.test.minio.test;import io.minio.MinioClient;import io.minio.PutObjectArgs;import java.io.FileInputStream;public class MinIOTest {public static void main(String[] args) {FileInputStream fileInputStream = null;try {fileInputStream = new FileInputStream("D:\\list.html");;//1.創(chuàng)建minio鏈接客戶端MinioClient minioClient = MinioClient.builder().credentials("minio", "minio123").endpoint("http://192.168.200.130:9000").build();//2.上傳PutObjectArgs putObjectArgs = PutObjectArgs.builder().object("list.html")//文件名.contentType("text/html")//文件類型.bucket("leadnews")//桶名詞 與minio創(chuàng)建的名詞一致.stream(fileInputStream, fileInputStream.available(), -1) //文件流.build();minioClient.putObject(putObjectArgs);System.out.println("http://192.168.200.130:9000/leadnews/ak47.jpg");} catch (Exception ex) {ex.printStackTrace();}}} # 如果文件上傳成功后不能訪問,則需要設(shè)置bucket的訪問權(quán)限

5 封裝MinIO為starter

5.1 創(chuàng)建模塊minio-file-starter

模塊名稱:minio-file-starter

導(dǎo)入依賴

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId></dependency><dependency><groupId>io.minio</groupId><artifactId>minio</artifactId><version>7.1.0</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency></dependencies>

5.2 配置類

MinIOConfigProperties

package com.test.file.config;import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties;import java.io.Serializable;@Data @ConfigurationProperties(prefix = "minio") // 文件上傳 配置前綴file.oss public class MinIOConfigProperties implements Serializable {private String accessKey;private String secretKey;private String bucket;private String endpoint;private String readPath; }

MinIOConfig

package com.test.file.config;import com.test.file.service.FileStorageService;import io.minio.MinioClient;import lombok.Data;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;import org.springframework.boot.context.properties.EnableConfigurationProperties;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;@Data@Configuration@EnableConfigurationProperties({MinIOConfigProperties.class})//當(dāng)引入FileStorageService接口時(shí)//@ConditionalOnClass(FileStorageService.class)public class MinIOConfig {@Autowiredprivate MinIOConfigProperties minIOConfigProperties;@Beanpublic MinioClient buildMinioClient(){return MinioClient.builder().credentials(minIOConfigProperties.getAccessKey(), minIOConfigProperties.getSecretKey()).endpoint(minIOConfigProperties.getEndpoint()).build();}}

5.3 封裝操作minIO類

FileStorageService

package com.test.file.service;import java.io.InputStream;/*** @author test*/public interface FileStorageService {/*** 上傳圖片文件* @param prefix 文件前綴* @param filename 文件名* @param inputStream 文件流* @return 文件全路徑*/public String uploadImgFile(String prefix, String filename,InputStream inputStream);/*** 上傳html文件* @param prefix 文件前綴* @param filename 文件名* @param inputStream 文件流* @return 文件全路徑*/public String uploadHtmlFile(String prefix, String filename,InputStream inputStream);/*** 刪除文件* @param pathUrl 文件全路徑*/public void delete(String pathUrl);/*** 下載文件* @param pathUrl 文件全路徑* @return**/public byte[] downLoadFile(String pathUrl);}

MinIOFileStorageService

package com.test.file.service.impl;import com.test.file.config.MinIOConfig; import com.test.file.config.MinIOConfigProperties; import com.test.file.service.FileStorageService; import io.minio.GetObjectArgs; import io.minio.MinioClient; import io.minio.PutObjectArgs; import io.minio.RemoveObjectArgs; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Import; import org.springframework.util.StringUtils;import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.Date;@Slf4j @EnableConfigurationProperties(MinIOConfigProperties.class) @Import(MinIOConfig.class) public class MinIOFileStorageService implements FileStorageService {@Autowiredprivate MinioClient minioClient;@Autowiredprivate MinIOConfigProperties minIOConfigProperties;private final static String separator = "/";/*** @param dirPath* @param filename yyyy/mm/dd/file.jpg* @return*/public String builderFilePath(String dirPath,String filename) {StringBuilder stringBuilder = new StringBuilder(50);if(!StringUtils.isEmpty(dirPath)){stringBuilder.append(dirPath).append(separator);}SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");String todayStr = sdf.format(new Date());stringBuilder.append(todayStr).append(separator);stringBuilder.append(filename);return stringBuilder.toString();}/*** 上傳圖片文件* @param prefix 文件前綴* @param filename 文件名* @param inputStream 文件流* @return 文件全路徑*/@Overridepublic String uploadImgFile(String prefix, String filename,InputStream inputStream) {String filePath = builderFilePath(prefix, filename);try {PutObjectArgs putObjectArgs = PutObjectArgs.builder().object(filePath).contentType("image/jpg").bucket(minIOConfigProperties.getBucket()).stream(inputStream,inputStream.available(),-1).build();minioClient.putObject(putObjectArgs);StringBuilder urlPath = new StringBuilder(minIOConfigProperties.getReadPath());urlPath.append(separator+minIOConfigProperties.getBucket());urlPath.append(separator);urlPath.append(filePath);return urlPath.toString();}catch (Exception ex){log.error("minio put file error.",ex);throw new RuntimeException("上傳文件失敗");}}/*** 上傳html文件* @param prefix 文件前綴* @param filename 文件名* @param inputStream 文件流* @return 文件全路徑*/@Overridepublic String uploadHtmlFile(String prefix, String filename,InputStream inputStream) {String filePath = builderFilePath(prefix, filename);try {PutObjectArgs putObjectArgs = PutObjectArgs.builder().object(filePath).contentType("text/html").bucket(minIOConfigProperties.getBucket()).stream(inputStream,inputStream.available(),-1).build();minioClient.putObject(putObjectArgs);StringBuilder urlPath = new StringBuilder(minIOConfigProperties.getReadPath());urlPath.append(separator+minIOConfigProperties.getBucket());urlPath.append(separator);urlPath.append(filePath);return urlPath.toString();}catch (Exception ex){log.error("minio put file error.",ex);ex.printStackTrace();throw new RuntimeException("上傳文件失敗");}}/*** 刪除文件* @param pathUrl 文件全路徑*/@Overridepublic void delete(String pathUrl) {String key = pathUrl.replace(minIOConfigProperties.getEndpoint()+"/","");int index = key.indexOf(separator);String bucket = key.substring(0,index);String filePath = key.substring(index+1);// 刪除ObjectsRemoveObjectArgs removeObjectArgs = RemoveObjectArgs.builder().bucket(bucket).object(filePath).build();try {minioClient.removeObject(removeObjectArgs);} catch (Exception e) {log.error("minio remove file error. pathUrl:{}",pathUrl);e.printStackTrace();}}/*** 下載文件* @param pathUrl 文件全路徑* @return 文件流**/@Overridepublic byte[] downLoadFile(String pathUrl) {String key = pathUrl.replace(minIOConfigProperties.getEndpoint()+"/","");int index = key.indexOf(separator);String bucket = key.substring(0,index);String filePath = key.substring(index+1);InputStream inputStream = null;try {inputStream = minioClient.getObject(GetObjectArgs.builder().bucket(minIOConfigProperties.getBucket()).object(filePath).build());} catch (Exception e) {log.error("minio down file error. pathUrl:{}",pathUrl);e.printStackTrace();}ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();byte[] buff = new byte[100];int rc = 0;while (true) {try {if (!((rc = inputStream.read(buff, 0, 100)) > 0)) break;} catch (IOException e) {e.printStackTrace();}byteArrayOutputStream.write(buff, 0, rc);}return byteArrayOutputStream.toByteArray();} }

5.4 對外加入自動(dòng)配置

在resources中新建META-INF/spring.factories

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\com.test.file.service.impl.MinIOFileStorageService

5.5 其他微服務(wù)使用

第一,minio-demo模塊中導(dǎo)入minio-file-starter的依賴

<dependency><groupId>com.test</groupId><artifactId>minio-file-starter</artifactId><version>1.0-SNAPSHOT</version> </dependency>

第二,在微服務(wù)中添加minio所需要的配置

minio:accessKey: miniosecretKey: minio123bucket: testendpoint: http://192.168.200.130:9000readPath: http://192.168.200.130:9000

第三,在對應(yīng)使用的業(yè)務(wù)類中注入FileStorageService,樣例如下:

package com.test.minio.test;import com.test.file.service.FileStorageService;import com.test.minio.MinioApplication;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringRunner;import java.io.FileInputStream;import java.io.FileNotFoundException;@SpringBootTest(classes = MinioApplication.class)@RunWith(SpringRunner.class)public class MinioTest {@Autowiredprivate FileStorageService fileStorageService;@Testpublic void testUpdateImgFile() {try {FileInputStream fileInputStream = new FileInputStream("E:\\tmp\\ak47.jpg");String filePath = fileStorageService.uploadImgFile("", "ak47.jpg", fileInputStream);System.out.println(filePath);} catch (FileNotFoundException e) {e.printStackTrace();}}}

總結(jié)

以上是生活随笔為你收集整理的分布式文件系统MinIO的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 免费在线观看成年人视频 | 非洲黄色大片 | 欧美成人免费播放 | 亚洲精品一区二区三区精华液 | 四虎影视www在线播放 | 叶山小百合av一区二区 | 久久av无码精品人妻系列试探 | 色综合天天综合网天天看片 | 特级丰满少妇一级aaa爱毛片 | 黄色亚洲精品 | 精品成人久久 | av中文字幕网址 | 国产精品普通话 | 国产高清视频一区二区 | 97超碰人人澡 | 青青草视频免费 | 国产剧情一区在线 | 黄色精品视频在线观看 | 欧美第一页在线观看 | 国产精品无遮挡 | 亚洲av无码国产综合专区 | 久久免费影院 | av国产成人 | 国产免费av片在线观看 | 91色交| 久久亚洲精精品中文字幕早川悠里 | 国产精品久久久久久白浆 | 免费国产黄色片 | 牛牛澡牛牛爽一区二区 | 99在线精品视频免费观看20 | 波多野结衣亚洲视频 | 欧美激情性生活 | 亚洲涩涩视频 | 日韩精品在线观看一区二区 | 少妇一级淫片免费观看 | 色哟哟视频| 国产大片一区二区 | 欧洲美女粗暴牲交免费观看 | 韩日精品在线 | 极品久久久 | 亚色综合 | 中国在线观看免费视频 | 在线只有精品 | 国产亚洲色婷婷久久99精品 | 国产精品区一 | 精品无码国产一区二区三区av | 色站av| 91大神久久| 91观看视频 | 无码人妻精品一区二区蜜桃网站 | 男人的天堂在线 | 亚洲av无码一区二区三区网站 | 亚洲人天堂 | 18久久| 国产精品久久国产精品99 | 18禁一区二区三区 | 亚洲无码国产精品 | 欧美日韩黄 | 精品视频久久久久久久 | 久久露脸| 就要日就要操 | 中文字幕在线不卡 | 精品人妻伦九区久久aaa片 | 91看篇| 亚洲精品国偷拍自产在线观看蜜桃 | 欧美成年人 | 永久在线视频 | 国产欧美一区二区三区白浆喷水 | 欧美在线色 | 婷婷的五月天 | 色婷婷久久综合 | 免费久久精品视频 | 日韩在线第二页 | 中文字幕第一页亚洲 | 国产av天堂无码一区二区三区 | 亚洲国产成人精品女人 | 免费看三级黄色片 | 成人免费看片网站 | 久久久久www | 午夜极品 | 欧亚毛片| 激情草逼 | 国产吧在线 | 一区二区日本视频 | 麻豆91在线播放 | 久久久久免费观看 | 韩国一区二区视频 | 亚洲AV无码片久久精品 | 欧美无专区 | 日本午夜影院 | 国产综合在线播放 | 在线看片资源 | 精品无码国产av一区二区三区 | 久久超级碰碰 | 视频在线观看电影完整版高清免费 | 男人的天堂av网站 | 精品久久久久久久久久久久久久 | 丰满少妇一区二区三区视频 | 欧美激情免费看 |