Centos7 安装 FastDFS

共计 4889 个字符,预计需要花费 13 分钟才能阅读完成。

提醒:本文最后更新于2026-09-10 11:26,文中所关联的信息可能已发生改变,请知悉!

#准备安装包:
###下载:fastdfs-nginx-module,libfastcommon,fastdfs,nginx
##如:fastdfs-6.0.3   fastdfs-nginx-module-1.22  libfastcommon-1.0.41  nginx-1.17.6

这里我把安装包放在/root目录下

#进入root目录

cd /root

#安装 wget 下载工具和 unzip 解压工具

yum -y install wget

#安装编译工具及库文件(必须,否则后面编译会失败)

yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

#下载安装包(国外用这个)
wget https://github.com/happyfish100/fastdfs/archive/V6.04.zip
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.zip
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.41.zip
wget http://nginx.org/download/nginx-1.17.6.tar.gz

#下载安装包(国内优化)
https://git.支援者.网址/
wget https://git.支援者.网址/https://github.com/happyfish100/fastdfs/archive/V6.04.zip
wget https://git.支援者.网址/https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.zip
wget https://git.支援者.网址/https://github.com/happyfish100/libfastcommon/archive/V1.0.41.zip
wget https://git.支援者.网址/http://nginx.org/download/nginx-1.17.6.tar.gz

#解压
unzip V6.04.zip
unzip V1.22.zip
unzip V1.0.41.zip
tar -zxvf nginx-1.17.6.tar.gz

#移动解压后的文件夹到 /usr/local 目录下(文件夹名称以解压后的文件夹名为准)

mv fastdfs-6.03 fastdfs-nginx-module-1.22 libfastcommon-1.0.41 nginx-1.17.6 /usr/local
 1.编译并安装:libfastcommon-1.0.41
#进入libfastcommon目录下
cd /root/libfastcommon-1.0.41

#编译并安装
./make.sh && ./make.sh install

编译完毕后在可在/usr/lib目录下查看是否安装成功

cd /usr/lib

ls | grep libfastcommon.so
 2.编译并安装 FastDFS v6.03
#进入fastdfs目录
cd /root/fastdfs-6.03

#编译并安装
./make.sh && ./make.sh install

#进入/usr/bin目录下,并列出fdfs的所有脚本
cd /usr/bin && ls |grep fdfs
3.修改fastdfs的配置文件
#进入/etc/fdfs/目录

cd /etc/fdfs/ 

##拷贝并重命名

cp storage.conf.sample storage.conf

cp client.conf.sample client.conf

cp tracker.conf.sample tracker.conf

 编辑tracker.conf

#创建/fastdfs/tracker 目录

mkdir -p /fastdfs/tracker

#编辑tracker.conf

vim /etc/fdfs/tracker.conf

#暂时就只修改tracker.conf中base_path内容

base_path=/fastdfs/tracker
4.关闭防火墙/开放端口号
#开放80端口
firewall-cmd –zone=public –add-port=80/tcp –permanent

返回success为成功
######################################################################################

命令解释: 

–zone #作用域 

–add-port=80/tcp #添加80端口,tcp协议 

–permanent #永久生效

######################################################################################

systemctl restart firewalld.service  #重启防火墙

#或直接关闭防火墙(如是在虚拟机中本地使用直接关闭防火墙,如是在服务器中使用不推荐关闭防火墙,请放行端口使用)

systemctl stop firewalld.service #关闭防火墙

5.启动tracker 服务
#启动tracker命令
/etc/init.d/fdfs_trackerd start

如需停止服务请使用:

#停止tracker命令
/etc/init.d/fdfs_trackerd stop

启动后反馈绿色的确定为执行成功

可使用命令 ps -ef | grep fdfs 查看:

6.修改storage.conf文件:
#修改storage.conf文件
vim /etc/fdfs/storage.conf

#修改内容:
base_path=/fastdfs/storage
store_path0=/fastdfs/storage

#改成自己的虚拟机IP地址或公网ip地址(在6.0.3版本发现这里有两个tracker_server,注掉一个,可能是集群搭建才需要)
tracker_server=192.168.1.2:22122
#tracker_server=192.168.1.2:22122

#修改端口号
http.server_port=80

#创建storage.conf中的base_path、store_path0路径
mkdir -p /fastdfs/storage
7.启动storage 服务
#启动storage
/etc/init.d/fdfs_storaged start

#进入/fastdfs/storage/data/,并查看
cd /fastdfs/storage/data/ && ls

8.设置开机启动
#打开rc.local 文件
vim /etc/rc.d/rc.local

在文件中:
/etc/init.d/fdfs_trackerd start
/etc/init.d/fdfs_storaged start

如:

输入法英文状态下 按住 Shift 键 + : 键后 输入 wq 保存

9.编辑client.conf文件 :
#编辑client.conf文件
vi /etc/fdfs/client.conf
######################################################################################
修改内容:
base_path=/fastdfs/tracker
#有两个tracker_server,注释一个 ip地址为虚拟机ip或公网地址
tracker_server=192.168.1.2:22122
#tracker_server=192.168.1.2:22122

10.测试上传文件

如:将/root/1.jpg文件上传到fastdfs系统当中:

#如执行后反馈路径则上传成功

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /root/1.jpg

#进入目录查看是否有文件

cd /fastdfs/storage/data/00/00

ls
11.安装nginx及fastdfs-nginx-module
#安装pcre
yum -y install pcre pcre-devel

#进入nginx-1.17.6
cd /usr/local/nginx-1.17.6

#添加http_stub_status_module模块

./configure –prefix=/usr/local/nginx –with-http_stub_status_module

#进入/usr/local/fastdfs-nginx-module-1.22/src目录

cd /usr/local/fastdfs-nginx-module-1.22/src

#编辑配置文件config

vi config

#将config文件中的/usr/local替换成/usr
:%s+/usr/local+/usr

#添加fastdfs-nginx-module
./configure –add-module=/usr/local/fastdfs-nginx-module-1.22/src/

#编译并安装
make && make install

复制并修改fastdfs-ngin-module中的配置文件

#复制fastdfs-ngin-module中的配置文件,到/etc/fdfs目录中

cp /usr/local/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/

#打开mod_fastdfs.conf 文件

vi /etc/fdfs/mod_fastdfs.conf

修改内容:如连接超时时间、跟踪器路径配置、url的group配置、
connect_timeout=10
tracker_server=192.168.1.2:22122
url_have_group_name = true
store_path0=/fastdfs/storage

创建软连接:

#进入/usr/local/fastdfs-6.03/conf目录
cd /usr/local/fastdfs-6.03/conf

#将http.conf,mime.types两个文件拷贝到/etc/fdfs/目录下

cp http.conf mime.types /etc/fdfs/

#进入/fastdfs/storage目录下

cd /fastdfs/storage

“`html
#修改nginx配置文件

vi /usr/local/nginx/conf/nginx.conf

#修改内容:
server {
listen 80;
server_name 192.168.87.132;

location ~/group([0-9])/M00 {
root /fastdfs/storage/data;
ngx_fastdfs_module;
}
“`

#创建一个软连接不配置软连接,无妨访问图片

ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00

12、最终测试

(1)检查fastdfs的tracker及storage和nginx是否启动

(2)将10步骤上传fastdfs返回的路径group1/M00/00/00/wKhXhF3c1muAPt6QAACHFs_2bF666.jpg,将其用ip地址拼接起来:如:http://192.168.1.2/group1/M00/00/00/wKhXhF3c1muAPt6QAACHFs_2bF666.jpg;

用浏览器访问能打开就成功搭建完成了;
![Centos7 安装 FastDFS-支援鑫-Blog][1]

[1]: https://ae01.alicdn.com/kf/Ua860850ac2574853839b5dfc4858c941p.jpg

正文完
 0