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

简介: MinIO【部署 01】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
   $ mc alias set 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 &
# 自定义账号密码后的启动
export MINIO_ACCESS_KEY=minio
export MINIO_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:9000
  accessKey: SllF5SkIozb1n0b1D84M
  secretKey: ZQSiCm3UDST1Q5lL1sImpOUNKIQSv6qZGucB4ku0
  bucketName: tcloud-minio

2.2 代码

Minio配置类:

@Configuration
@ConfigurationProperties(prefix = "minio")
@Data
public class MinioConfig {
    private String url;
    private String accessKey;
    private String secretKey;
    private String bucketName;
}

Minio工具类:

@Slf4j
@Component
public class MinioUtil {
    private MinioClient minioClient;
    @Resource
    private FileSystemConfig fileSystemConfig;
    @Resource
    private MinioConfig minioConfig;
    private String bucketName;
    @PostConstruct
    private void connectToServer() {
        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 名称
     */
    public void bucketExists(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();
        }
    }
    public void fileUploader(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();
        }
    }
    public void fileDownload(String objectName, String targetFilePath) {
        Path path = new File(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信息:

查看对象信息:

目录
相关文章
|
4天前
|
消息中间件 Java Kafka
Springboot集成高低版本kafka
Springboot集成高低版本kafka
|
10天前
|
NoSQL Java Redis
SpringBoot集成Redis解决表单重复提交接口幂等(亲测可用)
SpringBoot集成Redis解决表单重复提交接口幂等(亲测可用)
45 0
|
1月前
|
JavaScript Linux 区块链
DApp测试网络Ganache本地部署并实现远程连接
DApp测试网络Ganache本地部署并实现远程连接
|
22天前
|
NoSQL Java Redis
小白版的springboot中集成mqtt服务(超级无敌详细),实现不了掐我头!!!
小白版的springboot中集成mqtt服务(超级无敌详细),实现不了掐我头!!!
204 1
|
4天前
|
Java 测试技术
SpringBoot整合单元测试&&关于SpringBoot单元测试找不到Mapper和Service报java.lang.NullPointerException的错误
SpringBoot整合单元测试&&关于SpringBoot单元测试找不到Mapper和Service报java.lang.NullPointerException的错误
10 0
|
22天前
|
缓存 NoSQL Java
springboot中集成redis,二次封装成工具类
springboot中集成redis,二次封装成工具类
154 0
|
23天前
|
Java PHP 数据库
在护卫神上部署javaWeb项目,已经测试通过
在护卫神上部署javaWeb项目,已经测试通过
9 0
|
25天前
|
前端开发 JavaScript Java
springboot 集成easy-captcha实现图像验证码显示和登录
springboot 集成easy-captcha实现图像验证码显示和登录
134 0
|
25天前
|
XML Java 数据格式
springboot 微服务项目如何集成 html 页面
springboot 微服务项目如何集成 html 页面
26 0
|
25天前
|
前端开发 Java
springboot集成knife4j接口文档
springboot集成knife4j接口文档
springboot集成knife4j接口文档