介绍
最近才知道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服务上。
这样完成了minio服务的三种docker compose部署方式,逐次递进地讲解了每种方式的优势。如果我们只是为了集成minio到我们的应用程序中,只需要搭建一个单机版的服务即可。更多相关Docker compose内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
暂无评论内容