当前位置: 首页 > news >正文

黑糖不苦还做网站么婚礼摄影作品网站

黑糖不苦还做网站么,婚礼摄影作品网站,中关村在线官网,济南建网站送400电话MinIO从入门到飞翔 文章目录 MinIO从入门到飞翔0、前言1、分布式文件系统2、MinIO 介绍3、 MinIO安装#xff08;docker#xff09;4、基本概念5、通过代码上传文件到MinIO6、封装MinIO为starter7、在其他项目中集成封装好的模块 0、前言 对象存储是一种数据存储架构#x…MinIO从入门到飞翔 文章目录 MinIO从入门到飞翔0、前言1、分布式文件系统2、MinIO 介绍3、 MinIO安装docker4、基本概念5、通过代码上传文件到MinIO6、封装MinIO为starter7、在其他项目中集成封装好的模块 0、前言 对象存储是一种数据存储架构设计用于管理和处理大量非结构化数据。与传统的文件存储和块存储不同对象存储通过将数据分解为离散的、独立的单元或“对象”来存储每个对象包含数据本身、相关的元数据和一个唯一的标识符。 对象存储对比 存储方式优点缺点服务器磁盘开发便捷成本低扩展困难分布式文件系统容易实现扩容复杂度高第三方存储开发简单功能强大免维护收费 1、分布式文件系统 分布式文件系统Distributed File System, DFS是一种文件系统它使文件可以跨越多个服务器或存储设备存储和访问。DFS 通过网络将多个存储资源组合成一个统一的文件系统使用户和应用程序可以像访问本地文件一样透明地访问远程文件。 分布式文件系统的关键特性 透明性用户和应用程序可以像访问本地文件一样访问远程文件感受不到底层的复杂性。高可用性通过复制和冗余机制确保即使某些节点或硬件发生故障数据仍然可用。可扩展性能够处理随着数据量和用户数增加而增长的需求。容错性通过数据冗余和错误检测机制保证系统能继续运行即使发生部分硬件或网络故障。性能通过分布式架构能够有效地处理大量并发访问请求。 2、MinIO 介绍 MinIO 是一个高性能的分布式对象存储系统兼容 Amazon S3 云存储服务Min10基于Apache License v2.0开源协议的对象存储服务可以做为云存储的解决方案用来保存海量的图片视频文档。它专为大规模存储基础设施设计能够高效地存储海量非结构化数据如图片、视频、日志文件等。MinIO 提供了一组简单的 API用户可以方便地进行数据存储和管理。 官方文档 MinIO 的关键特性 兼容性 完全兼容 Amazon S3 API使用户可以使用现有的 S3 客户端和工具。 高性能 设计为高性能对象存储系统能够支持每秒数十GB的数据吞吐量。 可扩展性 支持横向扩展允许用户通过添加更多的存储节点来扩展存储容量和性能。 简易部署 提供简单的安装和配置过程可以在几分钟内启动和运行。 数据保护 通过纠删码Erasure Coding和位衰减Bit Rot保护机制确保数据完整性和持久性。 多租户支持 支持多用户和多租户环境提供隔离和权限管理。 Kubernetes 集成 提供原生的 Kubernetes Operator方便在 Kubernetes 集群中部署和管理 MinIO。 3、 MinIO安装docker 如果你有 Docker 环境可以通过以下命令快速拉取并运行 MinIO 容器 拉取镜像 docker pull minio/minio创建容器 docker run -p 9000:9000 --name minio -d --restartalways -e MINIO_ACCESS_KEYminio -e MINIO_SECRET_KEYminio123 -v /home/data:/data -v /home/config:/root/.minio minio/minio server /data访问minio系统: http://your_server_ip:9000 如http://192.168.200.130:9000 4、基本概念 bucket – 类比于文件系统的目录 Object – 类比文件系统的文件 Keys – 类比文件名 5、通过代码上传文件到MinIO 新建项目导入pom文件 dependenciesdependencygroupIdio.minio/groupIdartifactIdminio/artifactIdversion7.1.0/version/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactId/dependencydependencygroupIdcom.heima/groupIdartifactIdheima-file-starter/artifactIdversion1.0-SNAPSHOT/version/dependency/dependencies创建test测试文件 package com.heima.minio.test;import com.heima.file.service.FileStorageService; import io.minio.MinioClient; import io.minio.PutObjectArgs; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;import java.io.FileInputStream; import java.io.FileNotFoundException;public class MinIOTest {public static void main(String[] args) {FileInputStream fileInputStream null;try {fileInputStream new FileInputStream(E:\\list.html);;//1.创建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创建的名词一致.stream(fileInputStream, fileInputStream.available(), -1) //文件流.build();minioClient.putObject(putObjectArgs);System.out.println(http://192.168.200.130:9000/leadnews/list.html);} catch (Exception ex) {ex.printStackTrace();}} }上传文件点击控制台连接即可访问list.html文件 若不能访问在minio控制系统中打开访问权限 6、封装MinIO为starter 在项目中封装 导入依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-autoconfigure/artifactId /dependency dependencygroupIdio.minio/groupIdartifactIdminio/artifactIdversion7.1.0/version /dependency dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter/artifactId /dependency dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-configuration-processor/artifactIdoptionaltrue/optional /dependency dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId /dependency添加minio配置文件 package com.heima.file.config;import com.heima.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}) //当引入FileStorageService接口时 ConditionalOnClass(FileStorageService.class) public class MinIOConfig {Autowiredprivate MinIOConfigProperties minIOConfigProperties;Beanpublic MinioClient buildMinioClient() {return MinioClient.builder().credentials(minIOConfigProperties.getAccessKey(), minIOConfigProperties.getSecretKey()).endpoint(minIOConfigProperties.getEndpoint()).build();} }在spring管理的bean中注入MinIOFileStorageService在spring.factories中 org.springframework.boot.autoconfigure.EnableAutoConfiguration\com.heima.file.service.impl.MinIOFileStorageServiceMinIOFileStorageService文件详情大概就实现了对于文件资源上传的操作 package com.heima.file.service.impl;import com.heima.file.config.MinIOConfig; import com.heima.file.config.MinIOConfigProperties; import com.heima.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(separatorminIOConfigProperties.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(separatorminIOConfigProperties.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(index1);// 删除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(index1);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();} }具体模块下载 链接https://pan.baidu.com/s/17eWr0sLCOuF3bWoMravH_A?pwdm6ls 7、在其他项目中集成封装好的模块 在第5步创建的项目中进行测试使用 导入文件管理依赖自己封装好的第6步的模块 dependencygroupIdcom.heima/groupIdartifactIdheima-file-starter/artifactIdversion1.0-SNAPSHOT/version/dependency添加minio配置文件application.yml文件中 minio:accessKey: miniosecretKey: minio123bucket: leadnewsendpoint: http://192.168.200.130:9000readPath: http://192.168.200.130:9000在spring管理的bean中注入FileStorageService package com.heima.minio.test;import com.heima.file.service.FileStorageService; import io.minio.MinioClient; import io.minio.PutObjectArgs; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;import java.io.FileInputStream; import java.io.FileNotFoundException;SpringBootTest( classes MinIOApplication.class) RunWith(SpringRunner.class) public class MinIOTest {public static void main(String[] args) {Autowiredprivate FileStorageService fileStorageService;Testpublic void testUpdateImgFile() {try {FileInputStream fileInputStream new FileInputStream(E:\\test.jpg);String filePath fileStorageService.uploadImgFile(, test.jpg, fileInputStream);System.out.println(filePath);} catch (FileNotFoundException e) {e.printStackTrace();}}}查看上传
http://www.sczhlp.com/news/205737/

相关文章:

  • 中兴建设有限公司网站wordpress 遍历 子页面
  • 福建住房城乡建设厅网站网站群软件
  • 做网页第一步宁波seo关键词优化案例
  • 网站建设征税标准赤坎网站制作
  • 网站需备案高校网络网站建设意义及措施
  • 东阳网站优化以下哪个域名是做游戏网站的
  • 营销网站制作信ls15227网站建设的说明
  • 网站建设和建议深圳市招投标中心官网
  • 九江建网站报价做系统网站信息检索网站
  • 沈阳微信网站建设wordpress category archives:
  • 2025年拉链厂家推荐排行榜,TAB拉链,大棕拉链,金属拉链,树脂拉链,服装拉链,尼龙拉链,防水拉链,隐形拉链,男装拉链,女装拉链公司推荐!
  • 2025年开关按钮厂家推荐排行榜,带灯/防水/防爆/防腐/紧急式/开启式/联锁式/旋转式/钥匙式/蘑菇头/面板式开关按钮公司精选
  • 福州制作公司网站杭州本地网站有哪些
  • 好做的网站凡科互动游戏修改速度
  • 网站开发要学什么网络设计专业介绍
  • 知识付费网站开发教程关键词优化到首页怎么做到的
  • 杭州门户网站建设o2o有哪些电商平台
  • 做网站必须会php吗临沂网站建设培训学校
  • 西安wordpress建站网站直接跳转
  • 网站自动采集系统深圳移动网站建设制作公司
  • 网站云服务器上海建网站
  • 个人网站能做什么便利店网站建设拓扑图
  • 三水网站建设企业旅游电子商务网络营销是什么
  • 设计网站得多少钱哪些网站是做快消品的
  • 好的设计网站ppt模板大全百度云
  • 西安网站建设推荐q479185700上墙wordpress设置默认头像
  • 企业网站下载北京网站排名优化软件
  • 海康打开网站显示建设中网页制作培训哪里好
  • 用旧手机做网站服务器贵阳网站建设平台
  • nodejs 如何做网站后端网站建设相关话术