本文共 3920 字,大约阅读时间需要 13 分钟。
你是否正在为商城应用图片文件处理而烦恼?众所周知,商城图片作为商城应用核心资源之一,为实现商城相关功能,需要解决图片文件存储、图片压缩、图片缩放、图片水印等核心技术问题。本章以大规模商城实践为例,技术选型采用“作为图片文件存储系统,兼具图片文件资源访问;作为图片压缩、缩放与水印等功能”,为您揭开其中的奥秘。
单机Minio服务存在单点故障,相反,如果是⼀个有N块硬盘的分布式Minio,只要有N/2硬盘在线,你的数
据就是安全的。不过你需要⾄少有N/2+1个硬盘来创建新的对象。以下以一般生产环境中配置“一台服务器2块盘“作为独立部署(可以选择基于K8S部署)实例: 以部署三台服务器为例:192.168.1.11192.168.1.12192.168.1.13
(1)文件下载
登录:https://docs.min.io/cn/ 地址,下载minio文件大小几十MB,国内网可能存在延迟。 (2)文件部署并启动 将文件minio.zip解压到/appuser目录,在集群每个节点分别按照顺序执行如下命令,则可以启动成功;其中ACCESS_KEY为设置登录用户名,SECRET_KEY为设置登录密码,端口默认为9000。export MINIO_ACCESS_KEY=minioexport MINIO_SECRET_KEY=minionohup /appuser/minio --address ":9000" server http://192.168.1.11/minio/data1 http://192.168.1.11/minio/data2 \http://192.168.1.12/minio/data1 http://192.168.1.12/minio/data2 \http://192.168.1.13/minio/data1 http://192.168.1.13/minio/data2 >> /applog/minio.log 2>&1 &
(3)成功验证
mc 提供了⼀些UNIX常⽤命令的替代品,像ls, cat, cp, mirror, diff这些。 它⽀持⽂件系统和亚⻢逊S3
云存储服务。 更多信息请参考./mc alias set minio http:192.168.1.11:9000 minio minio --api s3v4
(1)查看buckets ./mc ls minio (2)创建buckets ./mc mb minio/watermark (3)检查权限并设置download权限 ./mc policy get minio/watermark ./mc policy set download minio/watermark (4)检查bucket ./mc tree minio (5)查看bucket下所有文件 ./mc tree minio -f (6)上传图片测试 ./mc cp watermask.png minio/watermark
imgproxy安装手册,mgproxy(v2.5.10)使用golang语言编写,强依赖于libvips(8.10.2)库,提供图片缩放、水印等功能。
在线文档地址:https://docs.imgproxy.net/,https://github.com/imgproxy/imgproxy Centos7一键安装执行脚本: https://gist.github.com/AndiSusanto15/a2c49b271d945ff2dbf6a7a5b8789bc4注意:Red Hat Enterprise Linux Server release 7.x 版本无法直接编译,整个过程采用Centos安装依赖与编译,拷贝动态链接库与二进制文件至redhat运行的策略执行。
一、centos7下编译
二、redhat7下执行
安装时获取编译好的文件imgproxy.tar,默认安装端口为8080。
(1)查看图片:例如提前上传到bucket的图片为imgTest.png
http://192.168.1.11:9000/bucket/imgTest.png
(2)查看图片缩放
http://192.168.1.11:8080/pr:cm/rs:fit:100:100/plain/bucket/imgTest.png
(3)查看图片水印
http://192.168.1.11:8080/pr:cm/wm:1:re/plain/bucket/imgTest.png
server { listen 9001; set $minio_host http://192.168.1.11:9000; #目前为单机,此处可以设置F5地址 set $imgproxy_host http://192.168.1.11:8080; #目前为单机,此处可以设置F5地址 set $resize '0'; if ($args ~ rs=(\d+)_(\d+)) { set $w $1; set $h $2; set $resize '1'; rewrite ^/wm/(\w+).(\w+) /pr:cm/rs:fit:$w:$h/wm:0.7:re/plain/images/$1.$2 break; rewrite ^/(\w+)/(\w+).(\w+) /pr:cm/rs:fit:$w:$h/plain/$1/$2.$3 break; } if ($resize != '1') { rewrite ^/wm/(\w+).(\w+) /pr:cm/wm:0.7:re/plain/images/$1.$2 break; } # proxy to imgporxy endpoint with url start with '/pr:cm' location /pr:cm { proxy_pass $imgproxy_host; } # proxy to minio to left request location / { proxy_pass $minio_host; }}
转载地址:http://tccpi.baihongyu.com/