千家信息网

FasterDFS的安装配置

发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,基本概述FastDFS是一款类Google FS的开源分布式文件系统,它用纯C语言实现,支持Linux、FreeBSD、AIX等UNIX系统。它只能通过专有API对文件进行存取访问,不支持POSIX接
千家信息网最后更新 2025年12月02日FasterDFS的安装配置

基本概述

FastDFS是一款类Google FS的开源分布式文件系统,它用纯C语言实现,支持Linux、FreeBSD、AIX等UNIX系统。它只能通过专有API对文件进行存取访问,不支持POSIX接口方式,不能mount使用。准确地讲,Google FS以及FastDFS、mogileFS、HDFS、TFS等类Google FS都不是系统级的分布式文件系统,而是应用级的分布式文件存储服务。

FastDFS集群中的Tracker server也可以有多台,Tracker server和Storage server均不存在单点问题。Tracker server之间是对等关系,组内的Storage server之间也是对等关系。传统的Master-Slave结构中的Master是单点,写操作仅针对Master。如果Master失效,需要将Slave提升为Master,实现逻辑会比较复杂。和Master-Slave结构相比,对等结构中所有结点的地位是相同的,每个结点都是Master,不存在单点问题。

基本结构图

在卷中增加服务器时,同步已有的文件由系统自动完成,同步完成后,系统自动将新增服务器切换到线上提供服务。

基本实验部署

1、实验准备

名称角色IP地址
centos7-1tracker192.168.45.135
centos7-2storage+nginx192.168.45.132

实验软件包提取码

链接:https://pan.baidu.com/s/1_Xs09mdST6VNLue11dqhyQ
提取码:9ql5

2、开始安装

修改两台服务器的名称

一台改为tracker,一台改为storage

hostnamectl set-hostname tracker    storagesu
安装基本环境包
yum -y install libevent  libevent-devel perl  make gcc zlib  zlib-devel pcre pcre-devel  gcc-c++  openssl-devel
安装libfastcommon服务(所有节点均进行安装)
mount.cifs //192.168.100.3/lzp /mnt#安装libfastcommon服务cd /mnt/fastDFS/tar zxvf libfastcommon-1.0.39.tar.gz -C /optcd /opt/libfastcommon-1.0.39/#编译安装并建立软链接以方便系统识别./make.sh && ./make.sh installln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.soln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.soln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
安装FastDFS服务(所有节点均进行安装)
cd /mnt/fastDFS/tar zxvf fastdfs-5.11.tar.gz -C /opt#编译安装cd /opt/fastdfs-5.11/./make.sh && ./make.sh install cd /etc/fdfs/cp tracker.conf.sample tracker.confcp storage.conf.sample storage.confcp client.conf.sample client.conf
tracker监控配置
# 建立数据文件、日志文件存放目录[root@tracker ~]# mkdir -m 755 -p /opt/fastdfs修改tracker配置文件[root@tracker ~]# vim /etc/fdfs/tracker.conf#修改以下配置#port=22122         //tracker服务默认端口22122即可base_path=/opt/fastdfs      //22行tracker存储data和log的跟路径,必须提前创建好tracker存储data和log的跟路径,必须提前创建好#http.server_port=8080 //tracker服务器上启动http服务进程,没装忽略#开启服务fdfs_trackerd /etc/fdfs/tracker.conf start#设置开机自启[root@tracker ~]# vim  /etc/rc.local#末行添加fdfs_trackerd   /etc/fdfs/tracker.conf start #关闭防火墙和安全功能[root@tracker ~]# systemctl stop firewalld[root@tracker ~]# setenforce 0
storage服务端修改
#建立数据文件、日志文件存放目录[root@storage ~]# mkdir -m 755 -p /opt/fastdfs修改storage配置文件[root@storage ~]# vim /etc/fdfs/storage.conf#修改以下配置group_name=group1        //默认组名,根据实际情况修改port=23000       //storge默认23000,同一个组的storage端口号必须一致base_path=/opt/fastdfs          //storage日志文件的根路径store_path_count=1              //与下面路径个数相同,默认为1store_path0=/opt/fastdfs       //109提供的存储路径(默认与日志文件存放在一起)tracker_server=192.168.45.135:22122      //自己的tracker服务器IP(重点!!!)http.server_port=80            //http访问文件的端口默认为8888,nginx中配置的监听端口保持一致开启服务并设置开机自启#开启服务(命令支持start|stop|restart)[root@storage ~]# fdfs_storaged  /etc/fdfs/storage.conf start[root@storage ~]# netstat -atnp | grep 23000tcp        0      0 0.0.0.0:23000           0.0.0.0:*               LISTEN      40430/fdfs_storaged#设置开机自启[root@storage ~]# vim  /etc/rc.local#末行添加fdfs_storaged   /etc/fdfs/storage.conf start [root@storage ~]# systemctl stop firewalld[root@storage ~]# setenforce 0检查是否与tracker监控端关联成功fdfs_monitor /etc/fdfs/storage.conf

安装nginx服务(storage:192.168.45.132)

这里为了减少虚拟机开启的数量,就在storage端进行nginx的安装

cd /mnt/fastDFS/[root@storage fastDFS]# tar zxvf nginx-1.12.0.tar.gz -C /opt tar zxvf fastdfs-nginx-module-1.20.tar.gz -C /opt# 修改/opt/fastdfs-nginx-module-1.20/src/config文件 [root@storage fastDFS]# vim /opt/fastdfs-nginx-module-1.20/src/configngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"#编译安装cd /opt/nginx-1.12.0/[root@storage nginx-1.12.0]# ./configure \--prefix=/usr/local/nginx \--add-module=/opt/fastdfs-nginx-module-1.20/src/make && make installcd /opt/fastdfs-nginx-module-1.20/srccp mod_fastdfs.conf /etc/fdfs/ #修改fastdfs-nginx-module模块配置文件mod-fasts.conf[root@storage nginx-1.12.0]# cd /etc/fdfs[root@storage fdfs]# vim mod_fastdfs.conf#检查一下配置base_path=/opt/fastdfs         //存放数据文件、日志的路径tracker_server=192.168.45.135/:22122    //tracker端的地址(重点!!!)url_have_group_name = true  //url是否包含group名称storage_server_port=23000           //需要和storage配置的相同store_path_count=1              //存储路径个数,需要和store_path个数匹配store_path0=/opt/fastdfs               //62行文件存储的位置#修改nginx配置文件[root@storage fdfs]# vim /usr/local/nginx/conf/nginx.conf#server中空行处添加location ~/M00 {                root /opt/fastdfs/data;                ngx_fastdfs_module;}#创建软链接[root@localhost ~]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/#检车nginx配置文件[root@localhost ~]# nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful#启动nginx[root@localhost ~]# nginx#拷贝fastdfs解压目录中的http.conf和mime.types不做这步可能会导致报错[root@storage fdfs]# cd /opt/fastdfs-5.11/conf/[root@storage conf]# cp mime.types http.conf /etc/fdfs/
修改storage端
#修改配置文件[root@storage ~]# vim /etc/fdfs/client.conf#检查以下配置base_path=/opt/fastdfs     //tracker服务器文件路径tracker_server=192.168.45.135:22122            //tracker服务器IP地址和端口号http.tracker_server_port=8080                  // tracker服务器的http端口号,必须和

上传测试文件命令:

/usr/bin/fdfs_upload_file <config_file> <local_filename>

命令演示:

[root@localhost mnt]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf 1.jpggroup1/M00/00/00/wKgthF4AKVmAY9WYABIrwU4wXNs537.jpg

下载文件命令:
/usr/bin/fdfs_download_file <config_file> <file_id> [local_filename]

示例

/usr/bin/fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKiOTV354W2AIf7GAAAAEh4TEws726.jpg test2.jpg**
删除文件命令:
/usr/bin/fdfs_delete_file <config_file> <file_id>

实例:

fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKiOTV354W2AIf7GAAAAEh4TEws726.jpg
0