Docker多节点部署Minio分布式文件系统并测试

文章目录

一、前提准备

准备如下文件夹和文件

txt 复制代码
./
├── docker-compose-minio.yml
├── .env
├── env
│   ├── minio.env
├── minio
│   ├── minio1
│   │   ├── data1
│   │   └── data2
│   ├── minio2
│   │   ├── data1
│   │   └── data2
│   ├── minio3
│   │   ├── data1
│   │   └── data2
│   └── minio4
│       ├── data1
│       └── data2

二、文件配置

1. .env

env 复制代码
MINIO_VERSION=RELEASE.2024-01-29T03-56-32Z

2. env/minio.env

env 复制代码
MINIO_ROOT_USER=minio
MINIO_ROOT_PASSWORD=minio123

3. docker-compose-minio.yml

yml 复制代码
version: "3.8"
networks:
  docker_xuecheng:
    ipam:
      config:
        - subnet: 172.20.0.0/16

services:
  minio1:
    container_name: minio1
    image: minio/minio:${MINIO_VERSION}
    volumes:
      - ./minio/minio1/data1:/data1
      - ./minio/minio1/data2:/data2
    ports:
      - "9001:9000"
      - "9011:9001"
    env_file:
      - ./env/minio.env
    command: server --address ":9000" --console-address ":9001" http://172.20.2.{1...4}/data{1...2}
    networks:
      docker_xuecheng:
        ipv4_address: 172.20.2.1

  minio2:
    container_name: minio2
    image: minio/minio:${MINIO_VERSION}
    volumes:
      - ./minio/minio2/data1:/data1
      - ./minio/minio2/data2:/data2
    ports:
      - "9002:9000"
      - "9012:9001"
    env_file:
      - ./env/minio.env
    command: server --address ":9000" --console-address ":9001" http://172.20.2.{1...4}/data{1...2}
    networks:
      docker_xuecheng:
        ipv4_address: 172.20.2.2

  minio3:
    container_name: minio3
    image: minio/minio:${MINIO_VERSION}
    volumes:
      - ./minio/minio3/data1:/data1
      - ./minio/minio3/data2:/data2
    ports:
      - "9003:9000"
      - "9013:9001"
    env_file:
      - ./env/minio.env
    command: server --address ":9000" --console-address ":9001" http://172.20.2.{1...4}/data{1...2}
    networks:
      docker_xuecheng:
        ipv4_address: 172.20.2.3

  minio4:
    container_name: minio4
    image: minio/minio:${MINIO_VERSION}
    volumes:
      - ./minio/minio4/data1:/data1
      - ./minio/minio4/data2:/data2
    ports:
      - "9004:9000"
      - "9014:9001"
    env_file:
      - ./env/minio.env
    command: server --address ":9000" --console-address ":9001" http://172.20.2.{1...4}/data{1...2}
    networks:
      docker_xuecheng:
        ipv4_address: 172.20.2.4

三、测试

访问宿主机ip:9011,输入账号密码。

txt 复制代码
MINIO_ROOT_USER=minio
MINIO_ROOT_PASSWORD=minio123

点到Monitoring -> Metrics

四、Java测试

1. 引入依赖

xml 复制代码
        <dependency>
            <groupId>io.minio</groupId>
            <artifactId>minio</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

2. 增删改

在这之前先去网页端,创建一个Bucket

java 复制代码
package com.xuecheng.media;

import io.minio.*;
import io.minio.errors.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.compress.utils.IOUtils;
import org.junit.jupiter.api.Test;

import java.io.*;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class MinioTest {
    private MinioClient minioClient = MinioClient.builder()
                    .endpoint("http://192.168.101.65:9001") //改成你的宿主机ip
                    .credentials("minio", "minio123")
                    .build();

    @Test
    public void testCreate() throws IOException, ServerException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        ObjectWriteResponse file = minioClient.uploadObject(
                UploadObjectArgs.builder()
                        .bucket("test")
                        .filename("C:\\Users\\mumu\\Desktop\\1C6091EF9671978A9F1B6C6F8A3666FD.png")
                        .object("1.png")
                        .build()
        );
    }

    @Test
    public void testDelete() throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
         minioClient.removeObject(
                RemoveObjectArgs.builder()
                        .bucket("test")
                        .object("12.msi")
                        .build()
        );
    }

    @Test
    public void testGet() throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        InputStream inputStream = minioClient.getObject(
                GetObjectArgs.builder()
                        .bucket("test")
                        .object("1.png")
                        .build()
        );
        FileOutputStream outputStream = new FileOutputStream(new File("C:\\Users\\mumu\\Desktop\\2.png"));
        IOUtils.copy(inputStream, outputStream);
    }

}
相关推荐
阿尔帕兹1 小时前
构建 HTTP 服务端与 Docker 镜像:从开发到测试
网络协议·http·docker
ZHOU西口3 小时前
微服务实战系列之玩转Docker(十八)
分布式·docker·云原生·架构·数据安全·etcd·rbac
景天科技苑5 小时前
【云原生开发】K8S多集群资源管理平台架构设计
云原生·容器·kubernetes·k8s·云原生开发·k8s管理系统
wclass-zhengge6 小时前
K8S篇(基本介绍)
云原生·容器·kubernetes
颜淡慕潇6 小时前
【K8S问题系列 |1 】Kubernetes 中 NodePort 类型的 Service 无法访问【已解决】
后端·云原生·容器·kubernetes·问题解决
川石课堂软件测试8 小时前
性能测试|docker容器下搭建JMeter+Grafana+Influxdb监控可视化平台
运维·javascript·深度学习·jmeter·docker·容器·grafana
昌sit!14 小时前
K8S node节点没有相应的pod镜像运行故障处理办法
云原生·容器·kubernetes
追风林15 小时前
mac 本地docker-mysql主从复制部署
mysql·macos·docker
A ?Charis17 小时前
Gitlab-runner running on Kubernetes - hostAliases
容器·kubernetes·gitlab
城南vision17 小时前
Docker学习—Docker核心概念总结
java·学习·docker