type
Post
status
Published
date
Oct 24, 2022
slug
article-18
summary
MinIO 环境搭建 + java api 基本操作
tags
java
MinIO
分布式
存储
category
技术分享
icon
password
Property
Oct 24, 2022 12:45 PM
官方文档:
中文文档(不推荐, 更新慢)
服务器端部署
包地址可能会更新, 及时关注官方文档
VOL_HOME=/home/podman mkdir -p /home/podman/minio/data mkdir -p /home/podman/minio/config podman run -d \ --name minio \ -p 9000:9000 \ -p 9001:9001 \ -e MINIO_ROOT_USER=用户名 \ -e MINIO_ROOT_PASSWORD=密码 \ -v $VOL_HOME/minio/data:/data \ -v $VOL_HOME/minio/config:/root/.minio \ quay.io/minio/minio \ server /data \ --console-address ":9001"
模拟多存储开启纠删码模式
VOL_HOME=/home/podman; for ((i=1;i<=4;i++)) do mkdir -p $VOL_HOME/minio/data/data$i; done mkdir -p /home/podman/minio/config; podman run -d \ --name minio \ -p 9000:9000 \ -p 9001:9001 \ -e MINIO_ROOT_USER=用户名 \ -e MINIO_ROOT_PASSWORD=密码 \ -v $VOL_HOME/minio/data:/data \ -v $VOL_HOME/minio/config:/root/.minio \ minio/minio \ server /data/data{1..4} \ --console-address ":9001";
由于新版本MinIO将控制台独立因此需要开放两个端口

踩坑: 密码一定不要设置过于简单, 否则会无法启动
客户端
- 安装
# linux # get client wget https://dl.min.io/client/mc/release/linux-amd64/mc # install chmod +x mc # move system environment mv ./mc /bin # read help mc --help # windows wget https://dl.min.io/client/mc/release/windows-amd64/mc.exe # set system environment variables
- 使用
alias set, remove and list aliases in configuration file ls list buckets and objects mb make a bucket rb remove a bucket cp copy objects mirror synchronize object(s) to a remote site cat display object contents head display first 'n' lines of an object pipe stream STDIN to an object share generate URL for temporary access to an object find search for objects sql run sql queries on objects stat show object metadata mv move objects tree list buckets and objects in a tree format du summarize disk usage recursively retention set retention for object(s) legalhold set legal hold for object(s) diff list differences in object name, size, and date between two buckets rm remove objects encrypt manage bucket encryption config event manage object notifications watch listen for object notification events undo undo PUT/DELETE operations policy manage anonymous access to buckets and objects tag manage tags for bucket(s) and object(s) ilm manage bucket lifecycle version manage bucket versioning replicate configure server side bucket replication admin manage MinIO servers update update mc to latest release
Java api
依赖
<!-- https://mvnrepository.com/artifact/io.minio/minio --> <dependency> <groupId>io.minio</groupId> <artifactId>minio</artifactId> <version>8.4.3</version> </dependency> <!-- https://mvnrepository.com/artifact/me.tongfei/progressbar --> <dependency> <groupId>me.tongfei</groupId> <artifactId>progressbar</artifactId> <version>0.9.3</version> </dependency> <!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp --> <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>5.0.0-alpha.10</version> </dependency>
FileUploader 文件上传Demo
package com.example.minio.demo; 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; /** * @author mushan * @date 7/29/2022 * @apiNote */ public class FileUploader { public static void main(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeyException { try { // Create a minioClient with the MinIO server playground, its access key and secret key. MinioClient minioClient = MinioClient.builder() .endpoint("IP:Port") .credentials("username", "password") .build(); // 创建bucket String bucketName = "testSDK"; boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build()); if (!found) { // 判断是否存在, 不存在则创建 minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build()); } else { System.out.println("Bucket " + bucketName +" already exists."); } // 文件上传 minioClient.uploadObject( UploadObjectArgs.builder() .bucket(bucketName) .object("one.jpg") .filename("./static/img/one.jpg") .build()); System.out.println("文件上传成功"); } catch (MinioException e) { System.out.println("Error occurred: " + e); System.out.println("HTTP trace: " + e.httpTrace()); } } }
- Author:mushan
- URL:https://blog.mushan.xyz/article/article-18
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
Relate Posts
