目录介绍单机版部署纠删码模式部署分布式部署介绍 最近才知道miNIO这个对象存储服务中间件,简直相见恨晚,只怪我见识太短浅(哭泣脸)。 说得通俗易懂点,minio的作用就是用来存储文
最近才知道miNIO这个对象存储服务中间件,简直相见恨晚,只怪我见识太短浅(哭泣脸)。
说得通俗易懂点,minio的作用就是用来存储文件的,比如图片、视频、音频等各种类型的文件。
那么问题来了,java本身就可以直接把文件写到磁盘里面,为什么还要用minio呢?
所以综上所述,相较于其他的文件存储方案,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
以上需要注意的几个点:
--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服务改成分布式部署。
我们就部署四个机器,每个机器挂载四个磁盘,这样的话,我们就形成了分布式纠删码模式了,这样的话,我们文件存储服务的可靠性就大大地增强了。
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分布式服务才能正常通信。
当四台机器上的服务全部起来后,我们需要提供一个负载均衡服务作为访问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服务上。
这样完成了minio服务的三种docker compose部署方式,逐次递进地讲解了每种方式的优势。如果我们只是为了集成minio到我们的应用程序中,只需要搭建一个单机版的服务即可。更多相关Docker compose内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: Docker compose部署minio服务
本文链接: https://lsjlt.com/news/171880.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0