好物优选点击查看详情 京东购买

暂无内容

文件服务器-docker-Minio分布式+nginx负载均衡+反向代理+nginx图片剪切(一站式)

一、 分布式部署minio :拒绝花里胡哨 已封装的minio–image:registry.cn-hangzhou.aliyuncs.com/yyzhan_images/docker-minio:2020-12-14
编写docker-compose 我起了四个minio对应四个docker容器 访问:宿主机:端口

version: '3.7' services: minio1: image: minio/minio:RELEASE.2020-11-13T20-10-18Z volumes: - /storage/minio/data1-1:/data1 # /storage/minio/data1-1 要挂载的宿主机文件绝对路径 - /storage/minio/data1-2:/data2 ports: - "9000:9000" #冒号前是宿主机开放端口 后是docker容器内端口 此配置目的是将docker容器端口映射到宿主机上 这样就能访问了。 environment: MINIO_ACCESS_KEY: ***** #minio账号设置 MINIO_SECRET_KEY: *********** #minio账号密码设置 command: server http://minio{1...4}/data{1...2} #定义访问url healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] interval: 30s timeout: 20s retries: 3 minio2: image: minio/minio:RELEASE.2020-11-13T20-10-18Z volumes: - /storage/minio/data2-1:/data1 - /storage/minio/data2-2:/data2 ports: - "9001:9000" environment: MINIO_ACCESS_KEY: ***** MINIO_SECRET_KEY: *********** command: server http://minio{1...4}/data{1...2} healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] interval: 30s timeout: 20s retries: 3 minio3: image: minio/minio:RELEASE.2020-11-13T20-10-18Z ports: - /storage/minio/data3-1:/data1 - /storage/minio/data3-2:/data2 ports: - "9002:9000" environment: MINIO_ACCESS_KEY: ***** MINIO_SECRET_KEY: *********** command: server http://minio{1...4}/data{1...2} healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] interval: 30s timeout: 20s retries: 3 minio4: image: minio/minio:RELEASE.2020-11-13T20-10-18Z volumes: - /storage/minio/data4-1:/data1 - /storage/minio/data4-2:/data2 ports: - "9003:9000" environment: MINIO_ACCESS_KEY: ***** MINIO_SECRET_KEY: *********** command: server http://minio{1...4}/data{1...2} healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] interval: 30s timeout: 20s retries: 3 volumes: data1-1: data1-2: data2-1: data2-2: data3-1: data3-2: data4-1: data4-2: 

PS:使用docker-compose构建命令如下
docker-compose up -d 如果报错没有此命令
yum -y install docker-compose

完成后如下效果–自个可以上传点图片啥的

在这里插入图片描述
如此分布式minio就部署好了,如需要扩展请参照官方文档

二、
nginx部署我的方式是编写dockerfile自个构建自个需要的nginx环境 内容如下
ps:已封装镜像路径:registry.cn-hangzhou.aliyuncs.com/yyzhan_images/minio_nginx:2020-12-14

#第一行先定义基础镜像,表示当前镜像文件是基于哪个进行编辑的. FROM centos:centos7.9.2009 #指定镜像维护者的信息. MAINTAINER @自在拉基 helpdesk81@outlook.com #除了安装编译nginx的依赖的安装包外,还可以将一些常用的命令工具也安装上 #类似于这样的安装命令(或者经常改动相对较小的命令)应该尽量往前写,这样在多次编译时就不会重复执行了(因为默认会使用缓嫿,从而提升编译效猿 #顺带将centos的yum源改成阿里云瘿 RUN mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup && curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo && sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo && yum makecache && yum update -y RUN yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel gd gd-devel vim wget unzip zip libxslt-dev libexif-devel #下载软件包并解压 RUN wget https://github.com/linsongze/ngx_http_image_filter_module/archive/master.zip #最新的剪切插件 RUN unzip master.zip #最新的剪切插件 RUN wget http://nginx.org/download/nginx-1.16.1.tar.gz RUN tar zxf nginx-1.16.1.tar.gz # 创建nginx 用户yum方式安装无需做此步骤,因为默认yum安装会自动创建nginx用户,咱们下面指令以nginx用户运行,因此我们需要在镜像中创广nginx用户" RUN useradd -M -s /sbin/nologin nginx #切换工作目录 WORKDIR nginx-1.16.1 #编译安装nginx RUN ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --add-module=/ngx_http_image_filter_module-master --with-http_ssl_module #将最新的插件编译安装进去编译的路径很关键等下docker run启动容器的时候需要用到要特别注意 RUN make && make install #将access.log日志重定向到docker的标准输兿将error.log日志重定向到docker标准错误,这样docker logs 的时候就可以看到日志了⾿ RUN ln -sf /dev/stdout /usr/local/nginx/logs/access.log && ln -sf /dev/stderr /usr/local/nginx/logs/error.log #相比COPY指令,ADD指令可以解压"*.tar.gz"的文乿但如果你的安装包斿*.zip"文件的话,ADD指令也不好使,得咱们自己使用unzip相关命令自行解压,索性我上面已经安装了unzip相关的软件包 # ADD code.tar.gz /yinzhengjie/softwares/nginx/html #定义向外暴露的端口号,多个端口用空格做间隔,启动容器的时便-p"需要使用此端向外端映射. EXPOSE 80/tcp 443/tcp #定义前台运行的命乿每个Docker只能有一条,如果定义了多替CMD"指令那么最后一条CMD指令会覆盖之前的(即只有最后一条CMD被执蟿. # CMD ["nginx"] # WORKDIR /root/nginx # ADD nginx.sh /nginx.sh # RUN chmod 755 /nginx.sh #启动容器执行指令,Dockerfile中添加了一个自定义CMD,需要➕ ᾿g᾿“daemon off᾿ CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"] 

PS: 在dockerfile目录下执行docker image build -t nginx_filter_module:1 . 来打包构建镜像

nginx_filter_module这个是镜像名称:1 1是标签

三、重点!!!:nginx.conf配置文件(正则耗了我好长时间)这里去掉了花里胡哨留了自个需要的东西

worker_processes 4; events { worker_connections 1024; } http { include mime.types; #default_type application/octet-stream; sendfile on; keepalive_timeout 65; proxy_cache_path /usr/local/nginx/conf/cache levels=1:2 keys_zone=minio_cache:100m max_size=10g inactive=5d; #设置缓存 -缓存路径usr/local/nginx/conf/cache #gzip on; upstream minio { server 宿主机IP:9000 weight=10; server 宿主机IP:9001 weight=10; server 宿主机IP:9002 weight=10; server 宿主机IP:9003 weight=10; } server { listen 9009; server_name localhost; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~^/files/(.*)\.(?i)(jpg|jpeg|jpg|gif|png)/(\d+)x(\d+) { set $w $3; set $h $4; if ($w != "0") { rewrite ^/files/(.*)\.(?i)(jpg|jpeg|jpg|gif|png)/(\d+)x(\d+)$ /$1.$2 break; } image_filter resize $w $h; image_filter_buffer 100M; proxy_set_header Authorization ''; proxy_cache minio_cache; proxy_cache_valid 200 206 304 301 302 5d; proxy_pass http://minio; } location ~^/files/(.*)\.(?i)(jpg|jpeg|jpg|gif|png)!(\d+)x(\d+) { set $w $3; set $h $4; if ($w != "0") { rewrite ^/files/(.*)\.(?i)(jpg|jpeg|jpg|gif|png)!(\d+)x(\d+)$ /$1.$2 break; } image_filter resize $w $h; image_filter_buffer 100M; proxy_set_header Authorization ''; #后端自定义请求头时需要用到!! proxy_cache minio_cache; #走这个location时缓存数据 proxy_cache_valid 200 206 304 301 302 5d; proxy_pass http://minio; } location ~^/files/ { proxy_set_header Authorization ''; proxy_set_header Host $http_host; rewrite ^/files/(.*)$ /$1 break; proxy_pass http://minio; } #直接访问/files/eop返回404 location = /files/eop { return 404; } #直接访问/files/eop/返回404 location = /files/eop/ { return 404; } } } 

直接来docker run 本地映射文件想清楚了再docker run
docker run -itd -p 9009:9009 –name Master_minio_nginx -v /storage/minio/location_nginxMinioWeb/image_filter_nginx/:/usr/local/nginx/conf -v /etc/localtime:/etc/localtime:ro nginx_filter_module:1
PS:-v /storage/minio/location_nginxMinioWeb/image_filter_nginx/:/usr/local/nginx/conf
注意!!!
/storage/minio/location_nginxMinioWeb/image_filter_nginx/此路径与docker容器的/usr/local/nginx/conf是映射关系所以直接将我们编辑完毕的nginx.conf文件存放到宿主机上的 /storage/minio/location_nginxMinioWeb/image_filter_nginx/这个路径docker 容器启动的时候才能读到我们的配置。

补充:部署完毕后启动docker时会报错
将这个文件也弄进配置文件目录下 在nginx.conf文件同级下新建文件mime.types编辑内容如下:

types { text/html html htm shtml; text/css css; text/xml xml; image/gif gif; image/jpeg jpeg jpg; application/javascript js; application/atom+xml atom; application/rss+xml rss; text/mathml mml; text/plain txt; text/vnd.sun.j2me.app-descriptor jad; text/vnd.wap.wml wml; text/x-component htc; image/png png; image/svg+xml svg svgz; image/tiff tif tiff; image/vnd.wap.wbmp wbmp; image/webp webp; image/x-icon ico; image/x-jng jng; image/x-ms-bmp bmp; font/woff woff; font/woff2 woff2; application/java-archive jar war ear; application/json json; application/mac-binhex40 hqx; application/msword doc; application/pdf pdf; application/postscript ps eps ai; application/rtf rtf; application/vnd.apple.mpegurl m3u8; application/vnd.google-earth.kml+xml kml; application/vnd.google-earth.kmz kmz; application/vnd.ms-excel xls; application/vnd.ms-fontobject eot; application/vnd.ms-powerpoint ppt; application/vnd.oasis.opendocument.graphics odg; application/vnd.oasis.opendocument.presentation odp; application/vnd.oasis.opendocument.spreadsheet ods; application/vnd.oasis.opendocument.text odt; application/vnd.openxmlformats-officedocument.presentationml.presentation pptx; application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx; application/vnd.openxmlformats-officedocument.wordprocessingml.document docx; application/vnd.wap.wmlc wmlc; application/x-7z-compressed 7z; application/x-cocoa cco; application/x-java-archive-diff jardiff; application/x-java-jnlp-file jnlp; application/x-makeself run; application/x-perl pl pm; application/x-pilot prc pdb; application/x-rar-compressed rar; application/x-redhat-package-manager rpm; application/x-sea sea; application/x-shockwave-flash swf; application/x-stuffit sit; application/x-tcl tcl tk; application/x-x509-ca-cert der pem crt; application/x-xpinstall xpi; application/xhtml+xml xhtml; application/xspf+xml xspf; application/zip zip; application/octet-stream bin exe dll; application/octet-stream deb; application/octet-stream dmg; application/octet-stream iso img; application/octet-stream msi msp msm; audio/midi mid midi kar; audio/mpeg mp3; audio/ogg ogg; audio/x-m4a m4a; audio/x-realaudio ra; video/3gpp 3gpp 3gp; video/mp2t ts; video/mp4 mp4; video/mpeg mpeg mpg; video/quicktime mov; video/webm webm; video/x-flv flv; video/x-m4v m4v; video/x-mng mng; video/x-ms-asf asx asf; video/x-ms-wmv wmv; video/x-msvideo avi; } 

wq保存restart即可!!!

原文链接:https://www.cnblogs.com/yyzhan/p/14156321.html

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享