minio部署,搭建

先下载:MinIO | Code and downloads to create high performance object storage

启动命令:

nohup ./minio server /opt/minio/data --console-address ":9001" --address 0.0.0.0:9000 &

账号密码:

minioadmin

minioadmin

java使用:

接口文档:Java Client API Reference — MinIO Baremetal Documentation

pom:


        
        
            io.minio
            minio
            8.4.2
            
                
                    okhttp
                    com.squareup.okhttp3
                
            
        

        
            com.squareup.okhttp3
            okhttp
            4.9.0
        

config:

package com.vazyme.kf.config.minio;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;

/**
 */
@Slf4j
@Configuration
@ConditionalOnProperty(value = "minio.switch")
public class MinioConfig {

    @Value("${minio.endpoint}")
    private String endpoint;

    @Value("${minio.port}")
    private Integer port;

    @Value("${minio.ak}")
    private String ak;

    @Value("${minio.sk}")
    private String sk;

    @Value("${minio.bucket}")
    private String bucket;


    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(endpoint, port, true)
                .credentials(ak, sk)
//                        .region("eu-east-1")
//                        .httpClient(customHttpClient)
                .build();
    }



}

nacos:


minio:
  switch: true
  endpoint: https://itdev.vazyme.com
  port: 9000
  ak: minioadmin
  sk: minioadmin
  bucket: concert-working

util:

package com.vazyme.kf.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import javax.annotation.Resource;

import io.minio.BucketExistsArgs;
import io.minio.GetPresignedObjectUrlArgs;
import io.minio.ListObjectsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.RemoveBucketArgs;
import io.minio.Result;
import io.minio.StatObjectArgs;
import io.minio.StatObjectResponse;
import io.minio.http.Method;
import io.minio.messages.Item;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
@RefreshScope  // 会监听变化实时变化值
public class MinioUtils {

    // 文檔:https://docs.min.io/minio/baremetal/sdk/java/minio-java.html#object-operations

    @Resource
    private MinioClient minioClient;

    @Value("${minio.bucket}")
    private String bucket;

    /**
     * 创建桶
     *
     * @param bucketName 桶名称
     */
    @SneakyThrows
    public void createBucket(String bucketName) {
        boolean found =
                minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
        if (!found) {
            minioClient.makeBucket(
                    MakeBucketArgs.builder()
                            .bucket(bucketName)
                            .region("cn-nanjing")
                            .build());
        }
    }

    /**
     * 删除桶
     *
     * @param bucketName 桶名称
     */
    @SneakyThrows
    public void removeBucket(String bucketName) {
        minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
    }

    /**
     * 获取文件信息
     *
     * @param bucketName 桶名称
     * @param objectName 文件名称
     * @return
     */
    @SneakyThrows
    public StatObjectResponse getObjectInfo(String bucketName, String objectName) {
        return minioClient.statObject(StatObjectArgs.builder().bucket(bucket).object(objectName).build());
    }

    /**
     * 上传文件
     *
     * @param bucketName 桶名称
     * @param objectName 文件名
     * @param stream     流
     * @param fileSize   文件大小
     * @param type       文件类型
     * @throws Exception
     */
    public void putObject(String bucketName, String objectName, InputStream stream, Long fileSize, String type) throws Exception {
        minioClient.putObject(
                PutObjectArgs.builder().bucket(bucket).object(objectName).stream(
                        stream, fileSize, -1)
                        .contentType(type)
                        .build());
    }


    /**
     * 判断文件夹是否存在
     *
     * @param bucketName 桶名称
     * @param prefix     文件夹名字
     * @return
     */
    @SneakyThrows
    public Boolean folderExists(String bucketName, String prefix) {
        Iterable> results = minioClient.listObjects(ListObjectsArgs.builder().bucket(bucket)
                .prefix(prefix).recursive(false).build());
        for (Result result:results){
            Item item = result.get();
            if (item.isDir()){
                return true;
            }
        }
        return false;
    }

    /**
     * 创建文件夹
     * @param bucketName 桶名称
     * @param path 路径
     */
    @SneakyThrows
    public void createFolder(String bucketName,String path) {
        minioClient.putObject(PutObjectArgs.builder().bucket(bucket).object(path)
                .stream(new ByteArrayInputStream(new byte[]{}),0,-1).build());
    }

    /**
     * 获取文件在minio在服务器上的外链
     * @param bucketName 桶名称
     * @param objectName 文件名
     * @return
     */
    @SneakyThrows
    public String getObjectUrl(String bucketName,String objectName){
        return minioClient.getPresignedObjectUrl(
                GetPresignedObjectUrlArgs.builder()
                        .method(Method.GET)
                        .bucket(bucket)
                        .object(objectName)
                        .build());
    }
}

https问题:MinIo升级成https不会?5分钟搞定_和弦c调来编程的博客-CSDN博客_https minio

如果是登录提示ip问题,配置启动命令

nohup ./minio server /opt/minio/data --console-address ":9001" --address itdev.vazyme.com:9000 &

你可能感兴趣的:(java,eureka,postman)