溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Docker?compose如何部署minio服務(wù)

發(fā)布時(shí)間:2022-08-05 13:50:13 來源:億速云 閱讀:515 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要介紹了Docker compose如何部署minio服務(wù)的相關(guān)知識,內(nèi)容詳細(xì)易懂,操作簡單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇Docker compose如何部署minio服務(wù)文章都會有所收獲,下面我們一起來看看吧。

介紹

最近才知道m(xù)inio這個對象存儲服務(wù)中間件,簡直相見恨晚,只怪我見識太短淺(哭泣臉)。

說得通俗易懂點(diǎn),minio的作用就是用來存儲文件的,比如圖片、視頻、音頻等各種類型的文件。

那么問題來了,java本身就可以直接把文件寫到磁盤里面,為什么還要用minio呢?

  • minio有完善的文件管理功能,包括針對文件的上傳,下載,刪除等

  • minio有強(qiáng)大的糾刪功能,即便磁盤損壞,在一定程度上時(shí)可以避免丟失文件的

  • minio有完善的權(quán)限管理功能,它可以針對不同的業(yè)務(wù)角色,分配不同的操作權(quán)限

  • 天然的分布式存儲功能

  • 高性能;在標(biāo)準(zhǔn)硬件上,對象存儲的讀/寫速度最高可以高達(dá)183 GB/s和171 GB/s

  • 文檔全面,簡單易用

所以綜上所述,相較于其他的文件存儲方案,minio的競爭力還是很大的。下面附上官網(wǎng)鏈接。

單機(jī)版部署

一般為了簡單集成minio client,我們會自己部署一個單機(jī)版的先用用?,F(xiàn)在我們開始,講解一下如何快速部署一個單機(jī)版minio服務(wù):

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

以上需要注意的幾個點(diǎn):

  • 需要暴露的端口有兩個,一個是API暴露端口9000,一個是服務(wù)管理頁面暴露端口9001。啟動成功后,訪問9001端口即可進(jìn)入管理頁面。

  • 單機(jī)版部署也可掛載多個磁盤,單個服務(wù)掛載超過(等于)4個磁盤,自動啟動糾刪碼模式,可以預(yù)防磁盤損壞的情況下,導(dǎo)致文件丟失。

  • 最新版本里面已經(jīng)不使用MINIO_ACCESS_KEY和MINIO_SECRET_KEY兩個環(huán)境變量了,改由MINIO_ROOT_USER和MINIO_ROOT_PASSWORD替換。

  • 啟動命令中--console-address代表指定服務(wù)管理頁面暴露的端口,http://minio/data{1...2}代表指定的minio服務(wù)下面掛載的目標(biāo)磁盤為/data1和/data2,否則磁盤掛載不起作用。API暴露端口可通過參數(shù)--address指定。

糾刪碼模式部署

為了啟動糾刪碼模式,我們需要在部署的服務(wù)上掛載至少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

在單機(jī)模式部署的情況下,調(diào)整為糾刪碼模式,我們需要修改兩個地方:

  • 掛載的磁盤增加到四個

  • 啟動命令里面補(bǔ)上對應(yīng)的掛載磁盤

該模式運(yùn)行其中某個磁盤出現(xiàn)損壞的情況,在磁盤損壞后也能保證文件不會丟失。

分布式部署

在單機(jī)上部署糾刪碼模式只能保證磁盤損壞的情況下,文件不丟失;并不能解決單點(diǎn)故障的問題,所以我們下面為了避免單點(diǎn)故障導(dǎo)致服務(wù)不可用,把minio服務(wù)改成分布式部署。

我們就部署四個機(jī)器,每個機(jī)器掛載四個磁盤,這樣的話,我們就形成了分布式糾刪碼模式了,這樣的話,我們文件存儲服務(wù)的可靠性就大大地增強(qiáng)了。

  • 首先準(zhǔn)備四臺主機(jī),ip地址分別為192.168.2.231,192.168.2.232,192.168.2.233,192.168.2.234;

  • 其次,我們分別在四臺機(jī)器上部署一個minio服務(wù)實(shí)例,參考以下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

在啟動命令中,我們需要把集群中所有的服務(wù)ip都寫進(jìn)去,這樣的話,minio分布式服務(wù)才能正常通信。

當(dāng)四臺機(jī)器上的服務(wù)全部起來后,我們需要提供一個負(fù)載均衡服務(wù)作為訪問minio分布式服務(wù)的統(tǒng)一的入口,首當(dāng)其沖我們就想到了nginx,所以我們在使用docker compose部署一個nginx服務(wù):

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服務(wù),這樣所有的請求都通過nginx負(fù)載均衡到minio服務(wù)上。

關(guān)于“Docker compose如何部署minio服務(wù)”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對“Docker compose如何部署minio服務(wù)”知識都有一定的了解,大家如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI