Minio 是一个基于Apache License v2.0开源协议的对象存储服务,虽然轻量,却拥有着不错的性能。它兼容亚马逊S3云存储服务接口,非常适合于存储大容量非结构化的数据。
例如图片、视频、日志文件、备份数据和容器/虚拟机镜像等,而一个对象文件可以是任意大小,从几 kb 到最大 5T 不等。
命令 | 描述 |
---|---|
docker pull minio/minio | 下载最新版Minio镜像 (其实此命令就等同于 : docker pull minio/minio:latest ) |
docker pull minio/minio:RELEASE.2022-06-20T23-13-45Z.fips | 下载指定版本的Minio镜像 (xxx指具体版本号) |
检查当前所有Docker下载的镜像
1 |
docker images |
一个用来存放配置,一个用来存储上传文件的目录
启动前需要先创建Minio外部挂载的配置文件( /home/minio/config),和存储上传文件的目录( /home/minio/data)
1 2 |
mkdir -p /home/minio/config mkdir -p /home/minio/data |
多行模式
1 2 3 4 5 6 7 8 9 10 |
docker run -p 9000:9000 -p 9090:9090 \ --net=host \ --name minio \ -d --restart=always \ -e "MINIO_ACCESS_KEY=minioadmin" \ -e "MINIO_SECRET_KEY=minioadmin" \ -v /home/minio/data:/data \ -v /home/minio/config:/root/.minio \ minio/minio server \ /data --console-address ":9090" -address ":9000" |
单行模式
1 |
docker run -p 9000:9000 -p 9090:9090 --net=host --name minio -d --restart=always -e "MINIO_ACCESS_KEY=minioadmin" -e "MINIO_SECRET_KEY=minioadmin" -v /home/minio/data:/data -v /home/minio/config:/root/.minio minio/minio server /data --console-address ":9090" -address ":9000" |
9090端口指的是minio的客户端端口
MINIO_ACCESS_KEY :账号
MINIO_SECRET_KEY :密码(账号长度必须大于等于5,密码长度必须大于等于8位)
访问:http://192.168.124.132:9090/login 用户名:密码 minioadmin:minioadmin
创建用户
创建组
创建accessKey和secretKey
点击下载
文件内容如下,保存文件,SDK操作文件的API需要用到
1 |
{<span class="hljs-string">"url"</span>:<span class="hljs-string">"http://192.168.124.132:9000"</span>,<span class="hljs-string">"accessKey"</span>:<span class="hljs-string">"XO1JDovW2FTmGaBb"</span>,<span class="hljs-string">"secretKey"</span>:<span class="hljs-string">"uG6wMfylUnOVH5WzwxqnldOWw2dMshNX"</span>,<span class="hljs-string">"api"</span>:<span class="hljs-string">"s3v4"</span>,<span class="hljs-string">"path"</span>:<span class="hljs-string">"auto"</span>} |
创建Bucket
上传文件
官方文档:https://docs.min.io/docs/
javaSDK:https://docs.min.io/docs/java-client-quickstart-guide.html
maven依赖
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#低版本的okhttp会报错提示 <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>4.9.0</version> </dependency> <dependency> <groupId>io.minio</groupId> <artifactId>minio</artifactId> <version>8.4.2</version> <exclusions> <exclusion> <artifactId>okhttp</artifactId> <groupId>com.squareup.okhttp3</groupId> </exclusion> </exclusions> </dependency> |
测试文件上传
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
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; 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("http://192.168.124.132:9000") .credentials("XO1JDovW2FTmGaBb", "uG6wMfylUnOVH5WzwxqnldOWw2dMshNX") .build(); // Make 'asiatrip' bucket if not exist. boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket("public").build()); if (!found) { // Make a new bucket called 'asiatrip'. minioClient.makeBucket(MakeBucketArgs.builder().bucket("public").build()); } else { System.out.println("Bucket 'public' already exists."); } // Upload '/home/user/Photos/asiaphotos.zip' as object name 'asiaphotos-2015.zip' to bucket // 'asiatrip'. minioClient.uploadObject( UploadObjectArgs.builder() .bucket("public") .object("credentials.json") .filename("C:/Users/lai.huanxiong/Downloads/credentials.json") .build()); System.out.println("'C:/Users/lai.huanxiong/Downloads/credentials.json' is successfully uploaded as " + "object 'credentials.json' to bucket 'public'."); } catch (MinioException e) { System.out.println("Error occurred: " + e); System.out.println("HTTP trace: " + e.httpTrace()); } } } |
文件上传成功展示
至此,Docker搭建Minio服务器和简单操作完成!!!
from:https://blog.csdn.net/BThinker/article/details/125412751