准备三台机器、配置防火墙规则或关闭防火墙、关闭selinux、时钟同步 、解析和安装好docker
ps: 官方推荐4台起步
192.168.1.21
192.168.1.22
192.168.1.23
ps:目前演示中使用的版本为:RELEASE.2022-08-13T21-54-44Z
#!/bin/bash
docker run -d --network=host --name minio \
--restart=always \
--privileged=true \
-v /data/minio-data1:/data1 \
-v /data/minio-data2:/data2 \
-e "MINIO_ROOT_USER=admin" \
-e "MINIO_ROOT_PASSWORD=12345678" \
minio/minio:RELEASE.2022-08-13T21-54-44Z server \
http://192.168.1.21/data1 \
http://192.168.1.21/data2 \
http://192.168.1.22/data1 \
http://192.168.1.22/data2 \
http://192.168.1.23/data1 \
http://192.168.1.23/data2 \
--console-address ":7000" --address ":7001"
网络选host模式,每个节点挂载2个目录,节点数量和数据目录数量以实际为准;默认端口分别为:9000
和:9001
MINIO_ROOT_USER为用户名,5位及以上
MINIO_ROOT_PASSWORD为密码,8位及以上
docker logs -f --tail 200 minio
ps:centos7内核版本警告,暂时不用关心
出现以上日志证明启动成功
浏览器端口输入其中一个ip地址 192.168.1.2{1…3}:7000,然后输入用户名MINIO_ROOT_USER
和密码MINIO_ROOT_PASSWORD
maven依赖
<dependency>
<groupId>io.miniogroupId>
<artifactId>minioartifactId>
<version>8.4.3version>
dependency>
代码
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import io.minio.GetObjectArgs;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
public class Minio {
public static void main(String[] args) {
//上传对象
putObject(new File("F:\\images\\counter.jpg"), "test");
// 下载对象
getObject(new File("F:\\images\\counter-down.jpg"), "test", "counter.jpg");
}
/**
* 创建minio客户端
*/
private static MinioClient client() {
MinioClient minioClient = MinioClient.builder()//
.endpoint("http://192.168.1.21:7001")//
.credentials("admin", "12345678")//
.build();
return minioClient;
}
/**
* PUT对象
*/
public static void putObject(File file, String bucketName) {
//创建minio客户端
MinioClient minioClient = client();
try (InputStream is = new FileInputStream(file)) {
// 上传对象
minioClient.putObject( //
PutObjectArgs.builder().//
bucket(bucketName)//
.object(file.getName())//
.stream(is, is.available(), -1).build()//
);
System.out.println(file.getName() + " is uploaded successfully");
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* GET对象
*/
public static void getObject(File file, String bucketName, String objectName) {
//创建minio客户端
MinioClient minioClient = client();
try ( //
InputStream is = minioClient.getObject(//
GetObjectArgs.builder().bucket(bucketName).object(objectName).build()//
);
OutputStream os = new FileOutputStream(file)//
) {
byte[] buf = new byte[16384];
int bytesRead;
while ((bytesRead = is.read(buf, 0, buf.length)) >= 0) {
os.write(buf, 0, bytesRead);
}
System.out.println(objectName + " is download successfully");
} catch (Exception e) {
e.printStackTrace();
}
}
}
https://github.com/minio/minio-java/tree/release/examples