采用Docker部署方式
- 老版本
docker run -d -p 9000:9000 --name minio-server\
-e "MINIO_ACCESS_KEY=minio" \
-e "MINIO_SECRET_KEY=minio@123" \
-v /Users/zjw/data/minio/data:/data \
-v /Users/zjw/data/minio/config:/root/.minio \
minio/minio:RELEASE.2021-06-17T00-10-46Z server /data
- 新版本
docker run -p 9000:9000 -p 9001:9001 \
--restart=always \
-e MINIO_ROOT_USER=minio \
-e MINIO_ROOT_PASSWORD=minio@123 \
-v /Users/zjw/data/minio/data:/data \
-v /Users/zjw/data/minio/config:/root/.minio \
minio/minio:RELEASE.2022-01-27T03-53-02Z server /data \
--console-address ":9000" --address ":9001"
Java链接和使用
- POM 依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zjw</groupId>
<artifactId>hello-minio</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.3.6</version>
</dependency>
</dependencies>
</project>
- Java代码
package com.zjw.minio;
import io.minio.BucketExistsArgs;
import io.minio.MinioClient;
import io.minio.errors.MinioException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
public class BucketExists {
public static void main(String[] args)
throws IOException, NoSuchAlgorithmException, InvalidKeyException {
try {
MinioClient minioClient =
MinioClient.builder()
.endpoint("http://localhost:9000")
.credentials("minio", "minio@123")
.build();
boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket("hello").build());
if (found) {
System.out.println("hello exists");
} else {
System.out.println("hello does not exist");
}
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
}
}
注意: 两个版本之间有差异,新版本有两个端口,CONSOLE Port指的是WEB访问端口,API端口指程序访问端口。