赞
踩
官网:https://min.io
中文:https://www.minio.org.cn/,http://docs.minio.org.cn/docs/
MinIO集群采用去中心化共享架构,每个结点是对等关系,通过Nginx可对MinIO进行负载均衡访问。
Minio使用纠删码技术来保护数据,它是一种恢复丢失和损坏数据的数学算法,它将数据分块冗余的分散存储在各各节点的磁盘上,所有的可用磁盘组成一个集合,上图由8块硬盘组成一个集合,当上传一个文件时会通过纠删码算法计算对文件进行分块存储,除了将文件本身分成4个数据块,还会生成4个校验块,数据块和校验块会分散的存储在这8块硬盘上。
使用纠删码的好处是即便丢失一半数量(N/2)的硬盘,仍然可以恢复数据。 比如上边集合中有4个以内的硬盘损害仍可保证数据恢复,不影响上传和下载,如果多于一半的硬盘坏了则无法恢复。
minio.exe server D:\develop\minio_data\data1 D:\develop\minio_data\data2 D:\develop\minio_data\data3 D:\develop\minio_data\data4
WARNING: MINIO_ACCESS_KEY and MINIO_SECRET_KEY are deprecated.
Please use MINIO_ROOT_USER and MINIO_ROOT_PASSWORD
Formatting 1st pool, 1 set(s), 4 drives per set.
WARNING: Host local has more than 2 drives of set. A host failure will result in data becoming unavailable.
WARNING: Detected default credentials 'minioadmin:minioadmin', we recommend that you change these values with 'MINIO_ROOT_USER' and 'MINIO_ROOT_PASSWORD' environment variables
6. 账号密码 : minioadmin/minioadmin
7. 创建桶,它相当于存储文件的目录,可以创建若干的桶
8. 输入bucket的名称,点击“CreateBucket”,创建成功
9. 点击“upload”上传文件。
10.下边去四个目录观察文件的存储情况 。
11.上传的文件存储在了这四个目录上,删除四个目录中的两个以内的目录上传的文件还可以预览,如删除三个目录则不会恢复,上传的文件损坏不可预览此时会报错
We encountered an internal error, please try again.
(Read failed. Insufficient number of drives online)在线驱动器数量不足。
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.4.3</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.8.1</version>
</dependency>
package com.xuecheng.media; import io.minio.BucketExistsArgs; import io.minio.MakeBucketArgs; import io.minio.MinioClient; import io.minio.UploadObjectArgs; import io.minio.errors.MinioException; import java.io.IOException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; /** * @description 测试MinIO * @author xuewen * @date 2023/2/12 21:24 * @version 1.0 */ public class MinIOTest { static MinioClient minioClient = MinioClient.builder() .endpoint("http://192.168.101.65:9000") .credentials("minioadmin", "minioadmin") .build(); //上传文件 public static void upload()throws IOException, NoSuchAlgorithmException, InvalidKeyException { try { boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket("testbucket").build()); //检查testbucket桶是否创建,没有创建自动创建 if (!found) { minioClient.makeBucket(MakeBucketArgs.builder().bucket("testbucket").build()); } else { System.out.println("Bucket 'testbucket' already exists."); } //上传1.mp4 minioClient.uploadObject( UploadObjectArgs.builder() .bucket("testbucket") .object("1.mp4") .filename("D:\\develop\\upload\\1.mp4") .build()); //上传1.avi,上传到avi子目录 minioClient.uploadObject( UploadObjectArgs.builder() .bucket("testbucket") .object("avi/1.avi") .filename("D:\\develop\\upload\\1.avi") .build()); System.out.println("上传成功"); } catch (MinioException e) { System.out.println("Error occurred: " + e); System.out.println("HTTP trace: " + e.httpTrace()); } } public static void main(String[] args)throws IOException, NoSuchAlgorithmException, InvalidKeyException { upload(); } }
//删除文件 public static void delete(String bucket,String filepath)throws IOException, NoSuchAlgorithmException, InvalidKeyException { try { minioClient.removeObject( RemoveObjectArgs.builder().bucket(bucket).object(filepath).build()); System.out.println("删除成功"); } catch (MinioException e) { System.out.println("Error occurred: " + e); System.out.println("HTTP trace: " + e.httpTrace()); } } public static void main(String[] args)throws IOException, NoSuchAlgorithmException, InvalidKeyException { // upload(); delete("testbucket","1.mp4"); delete("testbucket","avi/1.avi"); }
public static void getFile(String bucket,String filepath,String outFile)throws IOException, NoSuchAlgorithmException, InvalidKeyException { try { try (InputStream stream = minioClient.getObject( GetObjectArgs.builder() .bucket(bucket) .object(filepath) .build()); FileOutputStream fileOutputStream = new FileOutputStream(new File(outFile)); ) { // Read data from stream IOUtils.copy(stream,fileOutputStream); System.out.println("下载成功"); } } catch (MinioException e) { System.out.println("Error occurred: " + e); System.out.println("HTTP trace: " + e.httpTrace()); } } public static void main(String[] args)throws IOException, NoSuchAlgorithmException, InvalidKeyException { upload(); // delete("testbucket","1.mp4"); // delete("testbucket","avi/1.avi"); getFile("testbucket","avi/1.avi","D:\\develop\\minio_data\\1.avi"); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。