zoukankan      html  css  js  c++  java
  • 使用minio替换fastdfs 文件系统

    一个实践,属于业务需求:

    需求

    fastdfs的灵活性以及安全控制上不是很方便,而且语言调用上也不方便,所以需要无缝的迁移老的
    fastdfs到一个合适的分布式文件系统(语言友好,web友好,高性能,灵活)

    原有架构模式

    参考如图,很简单,也很标准基于group同名节点之间自动数据同步,同时使用nginx_fastdfs 模块提供http访问,入口同时基于nginx 提供
    cache 以及proxy 的能力,为了提供ha能力,基于lvs 实现一个ha 处理,业务代码基于fastdfs 的sdk 进行通信(上传以及部分下载)

    问题

    不是很灵活,基于s3 模式的更加方便,同时能加速业务对于文件处理的灵活行,s3 的 bucket 模式就是一个天然的多租户模式
    同时s3对于文件的安全控制上更加灵活

    调整的方案

    因为系统属于遗留系统的改造,不能简单的直接迁移,所以设计了一个可以兼容的方法,参考图


    简单说明:

    • 原理
      通过minio 的gateway模式代码以前的文件并
      通过nginx的url重写解决原有url包含group的问题,新的服务服务统一通过s3标准接口暴露文件访问(分为开放以及安全有效期访问方式),遗留系统暂时不好改动的系统可以暂时依然使用
      fastdfs接口
    • 流程说明
    1. 主要实现了cache(静态资源的处理)
      url rewrite 解决fastdfs 暴露的group1 问题,同时对于一些s3 bucket做些规则处理
    2. 基于minio的gateway模式暴露s3标准服务
      包含了处理遗留数据的兼容,以及新创建的s3 bukcet 管理,同时提供安装访问规则处理
    3. 原有fastdfs文件服务
      当前为了提供一个过度以及保障业务影响对小fastdfs服务同时保留,对于遗留系统依然可以使用,但是安全上不太好
    4. 基于s3的文件服务
      使用minio提供的标准服务处理文件(或者开放以及有安全访问控制的)
    5. 遗留系统
      当时依然可以使用fastdfs提供服务,同时基于minio的gateway提供标准s3服务

    nginx 参考配置

    • nginx 配置
      参考,实际结合场景修改
     
    worker_processes  auto;
    user root;  
    events {
        worker_connections  65536;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        lua_need_request_body on;
        gzip on;
        gzip_min_length  2k;
        gzip_buffers   4 16k;
        gzip_comp_level 4;
        gzip_vary on;
        gzip_types       text/plain application/javascript text/css    image/jpeg image/gif;
        real_ip_header     X-Forwarded-For;
        real_ip_recursive on;
        upstream  minio_prod {
          server xxxxxx:xxxx weight=10 max_fails=2 fail_timeout=30s;
        }
        server {
            listen       80;
            server_name domain;
            charset utf-8;
            client_max_body_size 10G;
            default_type text/html;
            location / {
                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 Host $http_host;
                # 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_prod;
            }
            # 老存储 fastdfs兼容处理
            location /group1/M00/ {
                rewrite ^/group1/M00/(.*) /s3-gateway-bucket/$1 break;
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-For $remote_addr;
                client_body_buffer_size 10M;
                proxy_cache_valid  200 304 12h;
                proxy_cache_key $uri$is_args$args;
                add_header Access-Control-Allow-Origin *;
                add_header Access-Control-Allow-Methods GET,POST,OPTIONS,PUT,DELETE,HEAD,PATCH;
                expires 30d;
                proxy_next_upstream error timeout http_404;
                proxy_pass http://minio_prod;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
        server {
            listen       443 ssl http2;
            server_name  domain;
            client_max_body_size 10G;
            ssl_certificate      xxxx.crt;
            ssl_certificate_key  xxxx.key;
            ssl_session_cache    shared:SSL:1m;
            ssl_session_timeout  5m;
            ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:AES256+EDH';
            #ssl_ciphers  HIGH:!aNULL:!MD5;
            ssl_prefer_server_ciphers  on;
            location /{          
                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 Host $http_host;
                # 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_prod;
           }
           # 老存储 fastdfs兼容处理
            location /group1/M00/ {
                rewrite ^/group1/M00/(.*) /<s3-gateway-bucket>/$1 break;
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-For $remote_addr;
                client_body_buffer_size 10M;
                proxy_cache_valid  200 304 12h;
                proxy_cache_key $uri$is_args$args;
                add_header Access-Control-Allow-Origin *;
                add_header Access-Control-Allow-Methods GET,POST,OPTIONS,PUT,DELETE,HEAD,PATCH;
                expires 30d;
                proxy_next_upstream error timeout http_404;
                proxy_pass http://minio_prod;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    }

    说明

    文章不是说明fastdfs不好,fastdfs是一个很不错的分布式文件系统方案,但是从业务的灵活性以及语言的支持以及通用性上fastdfs并不是一个很好的方案
    所以基于开源的monio s3 解决方案是一个很不错的选择

    参考资料

    https://github.com/minio/minio
    https://github.com/happyfish100/fastdfs
    https://docs.min.io/docs/minio-gateway-for-nas.html

  • 相关阅读:
    win7下设置smtp的方法
    win7下怎么安装IIS
    python语法笔记(二)
    python语法笔记(一)
    python 的类变量和对象变量
    mysql使用笔记(四)
    mysql使用笔记(三)
    mysql使用笔记(二)
    windows下重新安装TCP/IP协议栈
    c++程序编码
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/13708090.html
Copyright © 2011-2022 走看看