Docker compose如何部署minio服务

2023-05-16,,

这篇文章主要介绍了Docker compose如何部署minio服务的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Docker compose如何部署minio服务文章都会有所收获,下面我们一起来看看吧。

介绍

最近才知道minio这个对象存储服务中间件,简直相见恨晚,只怪我见识太短浅(哭泣脸)。

说得通俗易懂点,minio的作用就是用来存储文件的,比如图片、视频、音频等各种类型的文件。

那么问题来了,java本身就可以直接把文件写到磁盘里面,为什么还要用minio呢?

  • minio有完善的文件管理功能,包括针对文件的上传,下载,删除等

  • minio有强大的纠删功能,即便磁盘损坏,在一定程度上时可以避免丢失文件的

  • minio有完善的权限管理功能,它可以针对不同的业务角色,分配不同的操作权限

  • 天然的分布式存储功能

  • 高性能;在标准硬件上,对象存储的读/写速度最高可以高达183 GB/s和171 GB/s

  • 文档全面,简单易用

所以综上所述,相较于其他的文件存储方案,minio的竞争力还是很大的。下面附上官网链接。

单机版部署

一般为了简单集成minio client,我们会自己部署一个单机版的先用用。现在我们开始,讲解一下如何快速部署一个单机版minio服务:

version: "3.7"
services:
  minio:
    image: "quay.io/minio/minio:RELEASE.2022-08-02T23-59-16Z"
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - "./minio/data1:/data1"
      - "./minio/data2:/data2"
    command: server --console-address ":9001" http://minio/data{1...2}
    environment:
      - MINIO_ROOT_USER=admin
      - MINIO_ROOT_PASSWORD=12345678
      #- MINIO_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE
      #- MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

以上需要注意的几个点:

  • 需要暴露的端口有两个,一个是API暴露端口9000,一个是服务管理页面暴露端口9001。启动成功后,访问9001端口即可进入管理页面。

  • 单机版部署也可挂载多个磁盘,单个服务挂载超过(等于)4个磁盘,自动启动纠删码模式,可以预防磁盘损坏的情况下,导致文件丢失。

  • 最新版本里面已经不使用MINIO_ACCESS_KEY和MINIO_SECRET_KEY两个环境变量了,改由MINIO_ROOT_USER和MINIO_ROOT_PASSWORD替换。

  • 启动命令中--console-address代表指定服务管理页面暴露的端口,http://minio/data{1...2}代表指定的minio服务下面挂载的目标磁盘为/data1和/data2,否则磁盘挂载不起作用。API暴露端口可通过参数--address指定。

纠删码模式部署

为了启动纠删码模式,我们需要在部署的服务上挂载至少4块磁盘:

version: "3.7"
services:
  minio:
    image: "quay.io/minio/minio:RELEASE.2022-08-02T23-59-16Z"
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - "./minio/data1:/data1"
      - "./minio/data2:/data2"
      - "./minio/data3:/data3"
      - "./minio/data4:/data4"
    command: server --console-address ":9001" http://minio/data{1...4}
    environment:
      - MINIO_ROOT_USER=admin
      - MINIO_ROOT_PASSWORD=12345678
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

在单机模式部署的情况下,调整为纠删码模式,我们需要修改两个地方:

  • 挂载的磁盘增加到四个

  • 启动命令里面补上对应的挂载磁盘

该模式运行其中某个磁盘出现损坏的情况,在磁盘损坏后也能保证文件不会丢失。

分布式部署

在单机上部署纠删码模式只能保证磁盘损坏的情况下,文件不丢失;并不能解决单点故障的问题,所以我们下面为了避免单点故障导致服务不可用,把minio服务改成分布式部署。

我们就部署四个机器,每个机器挂载四个磁盘,这样的话,我们就形成了分布式纠删码模式了,这样的话,我们文件存储服务的可靠性就大大地增强了。

  • 首先准备四台主机,ip地址分别为192.168.2.231,192.168.2.232,192.168.2.233,192.168.2.234;

  • 其次,我们分别在四台机器上部署一个minio服务实例,参考以下docker-compose.yml:

version: "3.7"
services:
  minio:
    image: "quay.io/minio/minio:RELEASE.2022-08-02T23-59-16Z"
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - "./minio/data1:/data1"
      - "./minio/data2:/data2"
      - "./minio/data3:/data3"
      - "./minio/data4:/data4"
    command: server --console-address ":9001" http://192.168.2.231:9000/data{1...4} http://192.168.2.232:9000/data{1...4} http://192.168.2.233:9000/data{1...4} http://192.168.2.234:9000/data{1...4}
    environment:
      - MINIO_ROOT_USER=admin
      - MINIO_ROOT_PASSWORD=12345678
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

在启动命令中,我们需要把集群中所有的服务ip都写进去,这样的话,minio分布式服务才能正常通信。

  • 部署负载均衡服务nginx

当四台机器上的服务全部起来后,我们需要提供一个负载均衡服务作为访问minio分布式服务的统一的入口,首当其冲我们就想到了nginx,所以我们在使用docker compose部署一个nginx服务:

version: '3.7'
services:
  nginx:
    image: nginx:1.19.2-alpine
    hostname: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
      - "9000:9000"
      - "9001:9001"

下面是nginx配置文件:

user  nginx;
worker_processes  auto;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  4096;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;

    # include /etc/nginx/conf.d/*.conf;

    upstream minio {
        server 192.168.2.231:9000;
        server 192.168.2.232:9000;
        server 192.168.2.233:9000;
        server 192.168.2.234:9000;
    }

    upstream console {
        ip_hash;
        server 192.168.2.231:9001;
        server 192.168.2.232:9001;
        server 192.168.2.233:9001;
        server 192.168.2.234:9001;
    }
    server {
        listen       9000;
        listen  [::]:9000;
        server_name  localhost;

        # To allow special characters in headers
        ignore_invalid_headers off;
        # Allow any size file to be uploaded.
        # Set to a value such as 1000m; to restrict file size to a specific value
        client_max_body_size 0;
        # To disable buffering
        proxy_buffering off;
        proxy_request_buffering off;

        location / {
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;

            proxy_connect_timeout 300;
            # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            chunked_transfer_encoding off;

            proxy_pass http://minio;
        }
    }
    server {
        listen       9001;
        listen  [::]:9001;
        server_name  localhost;

        # To allow special characters in headers
        ignore_invalid_headers off;
        # Allow any size file to be uploaded.
        # Set to a value such as 1000m; to restrict file size to a specific value
        client_max_body_size 0;
        # To disable buffering
        proxy_buffering off;
        proxy_request_buffering off;

        location / {
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-NginX-Proxy true;

            # This is necessary to pass the correct IP to be hashed
            real_ip_header X-Real-IP;

            proxy_connect_timeout 300;
            
            # To support websocket
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            
            chunked_transfer_encoding off;

            proxy_pass http://console;
        }
    }
}

启动nginx服务,这样所有的请求都通过nginx负载均衡到minio服务上。

关于“Docker compose如何部署minio服务”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“Docker compose如何部署minio服务”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注本站行业资讯频道。