0


MinIO【部署 01】MinIO安装及SpringBoot集成简单测试

MinIO安装及SpringBoot集成测试

1.下载安装

下载 https://min.io/download#/linux;
安装文档 https://min.io/docs/minio/linux/index.html。

在这里插入图片描述

1.1 Install the MinIO Server

# 指导安装方式wget https://dl.min.io/server/minio/release/linux-arm64/archive/minio-20230804174021.0.0.aarch64.rpm -O minio.rpm
sudo dnf install minio.rpm

# 实际安装rpm-ivh minio-20230804174021.0.0.x86_64.rpm

1.2 Launch the MinIO Server

# 指导启动方式mkdir ~/minio
minio server ~/minio --console-address :9090

# 实际启动mkdir-p /home/minio/data
minio server /home/minio/data --console-address tcloud:9090
[root@tcloud data]# minio server /home/minio/data --console-address tcloud:9090
WARNING: Detected Linux kernel version older than 4.0.0 release, there are some known potential performance problems with this kernel version. MinIO recommends a minimum of 4.x.x linux kernel version for best performance
Formatting 1st pool, 1 set(s), 1 drives per set.
WARNING: Host local has more than 0 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
MinIO Object Storage Server
Copyright: 2015-2023 MinIO, Inc.
License: GNU AGPLv3 <https://www.gnu.org/licenses/agpl-3.0.html>
Version: RELEASE.2023-08-04T17-40-21Z (go1.19.12 linux/amd64)

Status:         1 Online, 0 Offline.
S3-API: http://172.17.0.8:9000  http://172.18.0.1:9000  http://172.81.0.1:9000  http://172.20.240.0:9000  http://127.0.0.1:9000
RootUser: minioadmin
RootPass: minioadmin

Console: http://tcloud:9090
RootUser: minioadmin
RootPass: minioadmin

Command-line: https://min.io/docs/minio/linux/reference/minio-mc.html#quickstart
   $ mcaliasset myminio http://172.17.0.8:9000 minioadmin minioadmin

Documentation: https://min.io/docs/minio/linux/index.html
Warning: The standard parity is set to 0. This can lead to data loss.
# 后台启动命令nohup /usr/local/bin/minio server /home/minio/data --console-address tcloud:9090 > /home/minio/data/minio.log 2>&1&# 自定义账号密码后的启动exportMINIO_ACCESS_KEY=minio
exportMINIO_SECRET_KEY=miniostorage
nohup /usr/local/bin/minio server  /home/minio/data --console-address tcloud:9090 > /home/minio/data/minio.log 2>&1&

1.3 Connect Your Browser to the MinIO Server

工作台详细使用文档 https://min.io/docs/minio/linux/administration/minio-console.html#minio-console

登录页面:

在这里插入图片描述
登录成功:

在这里插入图片描述

2.SpringBoot集成

Java Quickstart Guide https://min.io/docs/minio/linux/developers/java/minio-java.html#minio-java-quickstart

Java SDK https://github.com/minio/minio-java/tree/release

在这里插入图片描述

2.1 依赖及配置

<!--当前的最新版本--><dependency><groupId>io.minio</groupId><artifactId>minio</artifactId><version>8.5.5</version></dependency>

Minio Console

上生成的两个 Key:

在这里插入图片描述

在这里插入图片描述

{"accessKey":"SllF5SkIozb1n0b1D84M","api":"s3v4","path":"auto","secretKey":"ZQSiCm3UDST1Q5lL1sImpOUNKIQSv6qZGucB4ku0","url":"http://tcloud:9090/api/v1/service-account-credentials"}

yml配置:

minio:url: http://tcloud:9000accessKey: SllF5SkIozb1n0b1D84M
  secretKey: ZQSiCm3UDST1Q5lL1sImpOUNKIQSv6qZGucB4ku0
  bucketName: tcloud-minio

2.2 代码

Minio配置类:

@Configuration@ConfigurationProperties(prefix ="minio")@DatapublicclassMinioConfig{privateString url;privateString accessKey;privateString secretKey;privateString bucketName;}

Minio工具类:

@Slf4j@ComponentpublicclassMinioUtil{privateMinioClient minioClient;@ResourceprivateFileSystemConfig fileSystemConfig;@ResourceprivateMinioConfig minioConfig;privateString bucketName;@PostConstructprivatevoidconnectToServer(){if(fileSystemConfig.isMinioEnable()){// 初始化 MinioClient
            minioClient =MinioClient.builder().endpoint(minioConfig.getUrl()).credentials(minioConfig.getAccessKey(), minioConfig.getSecretKey()).build();// 检测 bucket 是否存在
            bucketName = minioConfig.getBucketName();bucketExists(bucketName);}}/**
     * 根据 bucketName 检测是否存在 不存在则创建
     *
     * @param bucketName 名称
     */publicvoidbucketExists(String bucketName){try{boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());if(!found){
                minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());}}catch(Exception e){
            log.error("bucketExists Failed!");
            e.printStackTrace();}}publicvoidfileUploader(String objectName,String filePath){try{UploadObjectArgs uploadObjectArgs =UploadObjectArgs.builder().bucket(bucketName).object(objectName).filename(filePath).build();
            minioClient.uploadObject(uploadObjectArgs);}catch(Exception e){
            log.error("fileUploader [{}] Failed!", filePath);
            e.printStackTrace();}}publicvoidfileDownload(String objectName,String targetFilePath){Path path =newFile(targetFilePath).toPath();try{GetObjectArgs getObjectArgs =GetObjectArgs.builder().bucket(bucketName).object(objectName).build();InputStream stream = minioClient.getObject(getObjectArgs);Files.copy(stream, path,StandardCopyOption.REPLACE_EXISTING);}catch(Exception e){
            log.error("fileDownload [{}] Failed!", targetFilePath);
            e.printStackTrace();}}}

2.3 测试结果

查看Buckets信息:

在这里插入图片描述
查看对象信息:

在这里插入图片描述


本文转载自: https://blog.csdn.net/weixin_39168541/article/details/132475329
版权归原作者 シ風箏 所有, 如有侵权,请联系我们删除。

“MinIO【部署 01】MinIO安装及SpringBoot集成简单测试”的评论:

还没有评论