一個實踐,屬於業務需求:
需求
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接口 - 流程說明
- 主要實現了cache(靜態資源的處理)
url rewrite 解決fastdfs 暴露的group1 問題,同時對於一些s3 bucket做些規則處理 - 基於minio的gateway模式暴露s3標准服務
包含了處理遺留數據的兼容,以及新創建的s3 bukcet 管理,同時提供安裝訪問規則處理 - 原有fastdfs文件服務
當前為了提供一個過度以及保障業務影響對小fastdfs服務同時保留,對於遺留系統依然可以使用,但是安全上不太好 - 基於s3的文件服務
使用minio提供的標准服務處理文件(或者開放以及有安全訪問控制的) - 遺留系統
當時依然可以使用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