FastDFS原理

FastDFS原理

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

文件的上传流程

  1. 选择tracker server
  2. 选择storage server
  3. 选择storage path
  4. 生成Fileid(文件标识)
  5. 生成文件名

文件的下载

  1. 定位文件
    • 组名
    • 虚拟磁盘路径
    • 数据两级目录
    • 文件名
  2. 文件所在位置的group
  3. 定位文件位置

FastDFS部署

shell 复制代码
#安装依赖环境
[root@localhost ~]# yum -y install gcc* libevent libevent-devel pcre-devel zlib-devel
# 解压libfastcommon-1.0.36.tar.gz当前目录
[root@localhost ~]# tar -zxvf libfastcommon-1.0.36.tar.gz
# 切换到解压后的libfastcommon目录
[root@localhost ~]# cd libfastcommon-1.0.36
# 执行make脚本进行编译
[root@localhost libfastcommon-1.0.36]# ./make.sh
#执行make install进行安装
[root@localhost libfastcommon-1.0.36]# ./make.sh install

#解压fastdfs-5.11.tar.gz当前目录
[root@localhost ~]#  tar -zxvf fastdfs-5.11.tar.gz
#切换到解压后FastDFS的目录
[root@localhost ~]# cd fastdfs-5.11
#执行make脚本进行编译
[root@localhost fastdfs-5.11]# ./make.sh
#执行make install进行安装
[root@localhost fastdfs-5.11]#  ./make.sh install

#查看安装后的效果
# 查看FastDFS相关的可执行程序
[root@localhost ~]# ll /etc/fdfs/
配置tracker服务器(101,102)
shell 复制代码
#复制tracker样例配置文件,并重命名
[root@localhost ~] cp /etc/fdfs/tracker. conf. sample /etc/fdfs/tracker.conf
#修改tracker配置文件
[root@localhost~]#vim/etc/fdfs/tracker.conf #修改的内容如下:
disabled=false
base_path=/fastdfs/tracker
#创建base_path指定的目录
[root@localhost ~] mkdir -p /fastdfs/tracker
#启动tracker服务器
[root@localhost ~]# /etc/init.d/fdfs_trackerd start 
#FastDFS Tracker Server 是否启动成功:
[root@localhost ~]# ps -ef I grep fdfs_trackerd
配置 STORAGE 服务(103,104)
shell 复制代码
#复制 storage样例配置文件,并重命名
[root@localhost ~]# cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
#编辑配置文件
[root@localhost ~]# vi /etc/fdfs/storage.conf
# storage 服务端口
base_path=/fastdfs/storage
# 数据和日志文件存储根日录
store_pathθ=/fastdfs/storage
# 第一个存储目录
tracker_server=192.168.10.101:22122 # tracker服务器IP和端口
tracker_server=192.168.10.102:22122 #tracker服务器IP2和端口
#和 tracker 中的组名保持一致
group_name=group1
#创建基础数据目录
[root@localhost ~] mkdir -p /fastdfs/storage
#启动storage服务器
[root@localhost~]# /etc/init.d/fdfs_storaged start 
#检查进程
[root@localhost ~]# ps-ef | grep fdfs_storaged
配置client(在任意一个Fastdfs节点上配置)
shell 复制代码
#复制 client样例配置文件,并重命名
[root@localhost~]#cp/etc/fdfs/client.conf.sample/etc/fdfs/client.conf 
[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
shell 复制代码
#解压fastdfs-nginx-module_v1.16.tar.gz
[root@localhost ~]# tar zxvf fastdfs-nginx-module_v1.16.tar.gz 
#修改fastdfs-nginx-module的配置文件
[root@localhost ~] cd fastdfs-nginx-module/src
#进入解压完的目录,到src目录,修改config文件,将文件路径中存在的local删掉
[root@localhost src]# vim config
#编译安装nginx
[root@localhost ~]# tar zxvf nginx-1.19.5,tar. gz [root@localhost ~]# useradd nginx
[root@localhost ~] cd nginx-1.19.5
[root@localhost nginx-1.19.5]# useradd -M -s /sbin/nologin nginx 
[root@localhost nginx-1.19.5]#./configure --prefix=/usr/local/nginx --user=nignx --group=nginx
--prefix=/usr/local/nginx -add-module=/root/fastdfs-nginx-module/src
[root@localhost nginx-1.19.5]# make install
#优化命令路径
[root@localhost nginx-1.19.5]# In -s /usr/local/nginx/sbin/* /usr/local/sbin/ 
#配置FASTDFS
#cp mod fastdfs.conf并修改
[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
#复制FastDFS的部分配置文件到/etc/fdfs目录
[root@localhost~]#cp /root/fastdfs-5.11/conf/http.conf/etc/fdfs 
[root@localhost~]# cp /root/fastdfs-5.11/conf/mime. types /etc/fdfs
#/fastdfs/storage/data将其链接到实际存放数据的目录
[root@localhost~]#In-s /fastdfs/storage/data/ /fastdfs/storage/data/M00 
配置NGINX(103,104)
shell 复制代码
[rootelocalhost ~] cd /usr/local/nginx/
#修改nginx.conf文件,在server指令块中新增如下配置
[root@localhost nginx]# vim conf/nginx.conf http
location /group1/M00{
ngx_fastdfs module;
}
root@localhost nginx]# fdfs storaged /etc/fdfs/storage. conf restart 
[root@localhost nginx]# nginx
配置NGINX反向代理(105)
shell 复制代码
#编译安装Nginx
[root@localhost ~]# yum -y install pcre-devel zlib-devel gcc* 
[rootelocalhost ~] tar zxvf nginx-1.19.5. tar. gz
[root@localhost nginx-1.19.5]# useradd nginx
[root@localhost nginx-1.19.5]#, /configure --prefix=/usr/local/nginx --user=nginx -group=nginx
[root@localhost nginx-1.19.5]# make 8& make install
[root@localhost ~]# In -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ 
[root@localhost~]#vim/usr/local/nginx/conf/nginx.conf
#http块中
upstream storage_server_group {
server 192.168. 10.103:80  weight=1;
server 192.168.10. 104:80  weight=1; 
}
#server块中
location /
proxy_pass http: //storage_server_group1; }
}
相关推荐
虾..39 分钟前
Linux 软硬链接和动静态库
linux·运维·服务器
Evan芙1 小时前
Linux常见的日志服务管理的常见日志服务
linux·运维·服务器
hkhkhkhkh1233 小时前
Linux设备节点基础知识
linux·服务器·驱动开发
HZero.chen4 小时前
Linux字符串处理
linux·string
张童瑶4 小时前
Linux SSH隧道代理转发及多层转发
linux·运维·ssh
汪汪队立大功1234 小时前
什么是SELinux
linux
石小千4 小时前
Linux安装OpenProject
linux·运维
柏木乃一4 小时前
进程(2)进程概念与基本操作
linux·服务器·开发语言·性能优化·shell·进程
Lime-30904 小时前
制作Ubuntu 24.04-GPU服务器测试系统盘
linux·运维·ubuntu
百年渔翁_肯肯5 小时前
Linux 与 Unix 的核心区别(清晰对比版)
linux·运维·unix