FastDFS原理
- FastDFS简介
- FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理、功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线符文,如相册网站等等
- FastDFS为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用、高性能等指标,适应FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。
- Tracker server
- 跟踪服务器,主要做调度工作,起到均衡的作用,负责管理所有的Storage Server和group
- Storage Server
- 存储服务器,主要提供容量和备份符文;以group为单位,每个group内部可以有多台storage Server,数据互为备份
- Client
- 客户端,上传下载数据的服务器,也就是所我们自己的项目所部署在的服务器。FastDFS向使用者提供基本文件访问端口。比如upload、download、append、delete等,以客户端的方式提供给用户使用
文件的上传流程
- 选择tracker server
- 选择storage server
- 选择storage path
- 生成Fileid(文件标识)
- 生成文件名

文件的下载
- 定位文件
- 文件所在位置的group
- 定位文件位置

FastDFS部署
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost libfastcommon-1.0.36]
[root@localhost libfastcommon-1.0.36]
[root@localhost ~]
[root@localhost ~]
[root@localhost fastdfs-5.11]
[root@localhost fastdfs-5.11]
[root@localhost ~]
配置tracker服务器(101,102)
[root@localhost ~] cp /etc/fdfs/tracker. conf. sample /etc/fdfs/tracker.conf
[root@localhost~]
disabled=false
base_path=/fastdfs/tracker
[root@localhost ~] mkdir -p /fastdfs/tracker
[root@localhost ~]
[root@localhost ~]
配置 STORAGE 服务(103,104)
[root@localhost ~]
[root@localhost ~]
base_path=/fastdfs/storage
store_pathθ=/fastdfs/storage
tracker_server=192.168.10.101:22122
tracker_server=192.168.10.102:22122
group_name=group1
[root@localhost ~] mkdir -p /fastdfs/storage
[root@localhost~]
[root@localhost ~]
配置client(在任意一个Fastdfs节点上配置)
[root@localhost~]
[root@localhost ~] mkdir -p /fastdfs/tracker
[root@localhost ~] vim /etc/fdfs/client.conf
base_path=/fastdfs/tracker
tracker_server=192.100.139.121:22122
tracker_server=192.100.139.122:22122
[rootelocalhost ~] fdfs_upload_file /etc/fdfs/client.conf logo.jpg
group1/M00/00/00/wKgKaGadD5aAZBiJAAFMnKMUrMI833.jpg
在所有storage 节点安装fastdfs-nginx-module 和nginx
[root@localhost ~]
[root@localhost ~] cd fastdfs-nginx-module/src
[root@localhost src]
[root@localhost ~]
[root@localhost ~] cd nginx-1.19.5
[root@localhost nginx-1.19.5]
[root@localhost nginx-1.19.5]
--prefix=/usr/local/nginx -add-module=/root/fastdfs-nginx-module/src
[root@localhost nginx-1.19.5]
[root@localhost nginx-1.19.5]
[rootelocalhost ~] cp /root/ fastdfs-nginx-module/src/mod fastdfs. conf /etc/fdfs/
[rootelocalhost ~] vim /etc/fdfs/mod fastdfs.conf
tracker_server=192.168.10.101:22122
tracker_server=192.168.10.102:22122
url_have group_name=true
store pathe=/fastdfs/storage
[root@localhost~]
[root@localhost~]
[root@localhost~]
配置NGINX(103,104)
[rootelocalhost ~] cd /usr/local/nginx/
[root@localhost nginx]
location /group1/M00{
ngx_fastdfs module;
}
root@localhost nginx]
[root@localhost nginx]
配置NGINX反向代理(105)
[root@localhost ~]
[rootelocalhost ~] tar zxvf nginx-1.19.5. tar. gz
[root@localhost nginx-1.19.5]
[root@localhost nginx-1.19.5]
[root@localhost nginx-1.19.5]
[root@localhost ~]
[root@localhost~]
upstream storage_server_group {
server 192.168. 10.103:80 weight=1;
server 192.168.10. 104:80 weight=1;
}
location /
proxy_pass http: //storage_server_group1; }
}