在 CentOS 7.1 上部署 FastDFS(分布式文件系统)主要包括安装 FastDFS 核心组件、配置 Tracker 和 Storage 服务,并可以结合 Nginx 扩展模块实现 HTTP 访问,以下是详细步骤:
环境准备
# 更新系统 yum update -y # 安装依赖 yum install -y gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel wget git # 创建安装目录 mkdir /opt/fastdfs cd /opt/fastdfs
安装 libfastcommon(FastDFS 基础库)
# 下载源码 git clone https://github.com/happyfish100/libfastcommon.git cd libfastcommon # 编译安装 ./make.sh ./make.sh install # 创建软链接(解决库文件路径问题) ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
安装 FastDFS 核心
# 返回上级目录 cd /opt/fastdfs # 下载 FastDFS 源码 git clone https://github.com/happyfish100/fastdfs.git cd fastdfs # 编译安装 ./make.sh ./make.sh install # 配置文件目录 cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf cp /opt/fastdfs/fastdfs/conf/http.conf /etc/fdfs/ cp /opt/fastdfs/fastdfs/conf/mime.types /etc/fdfs/
配置 Tracker Server
# 编辑 Tracker 配置 vim /etc/fdfs/tracker.conf # 修改以下关键配置: base_path=/data/fastdfs/tracker # Tracker 数据目录 bind_addr=0.0.0.0 # 监听地址(默认) port=22122 # 端口(默认) http.server_port=8080 # HTTP 服务端口(可选) # 创建目录并启动 mkdir -p /data/fastdfs/tracker systemctl start fdfs_trackerd systemctl enable fdfs_trackerd # 检查运行状态 netstat -tunlp | grep fdfs
配置 Storage Server
# 编辑 Storage 配置 vim /etc/fdfs/storage.conf # 修改以下配置: group_name=group1 # 组名(默认) base_path=/data/fastdfs/storage # Storage 数据目录 store_path0=/data/fastdfs/storage/files # 文件存储路径 tracker_server=<Tracker_IP>:22122 # 填写 Tracker 服务器 IP port=23000 # Storage 端口(默认) http.server_port=8888 # HTTP 服务端口 # 创建目录并启动 mkdir -p /data/fastdfs/storage/files systemctl start fdfs_storaged systemctl enable fdfs_storaged # 检查 Tracker 连接 /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
安装 Nginx + FastDFS 模块(HTTP 访问)
# 下载 fastdfs-nginx-module
cd /opt/fastdfs
git clone https://github.com/happyfish100/fastdfs-nginx-module.git
# 下载并编译 Nginx
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -zxvf nginx-1.20.1.tar.gz
cd nginx-1.20.1
# 配置编译参数
./configure \
--prefix=/usr/local/nginx \
--add-module=/opt/fastdfs/fastdfs-nginx-module/src \
--with-http_stub_status_module \
--with-http_ssl_module
# 编译安装
make && make install
# 复制模块配置文件
cp /opt/fastdfs/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
# 编辑模块配置
vim /etc/fdfs/mod_fastdfs.conf
# 修改以下配置:
tracker_server=<Tracker_IP>:22122
url_have_group_name=true
store_path0=/data/fastdfs/storage/files
# 配置 Nginx
vim /usr/local/nginx/conf/nginx.conf
# 在 server 块中添加:
location /group1/M00 {
root /data/fastdfs/storage/files;
ngx_fastdfs_module;
}
# 启动 Nginx
/usr/local/nginx/sbin/nginx 测试上传
# 编辑客户端配置 vim /etc/fdfs/client.conf base_path=/data/fastdfs/client tracker_server=<Tracker_IP>:22122 # 创建测试文件 echo "Hello FastDFS" > test.txt # 上传文件 /usr/bin/fdfs_upload_file /etc/fdfs/client.conf test.txt # 返回示例:group1/M00/00/00/wKgABmHqRfSAXJ3zAAAB5K-7pXc.txt # 通过 HTTP 访问文件 # 格式:http://<Storage_IP>:8888/group1/M00/00/00/wKgABmHqRfSAXJ3zAAAB5K-7pXc.txt
防火墙配置
# 开放端口 firewall-cmd --permanent --add-port=22122/tcp # Tracker firewall-cmd --permanent --add-port=23000/tcp # Storage firewall-cmd --permanent --add-port=8888/tcp # HTTP firewall-cmd --reload
常见问题
启动失败


- 检查
/etc/fdfs/*.conf中的路径权限。 - 查看日志:
tail -f /data/fastdfs/tracker/logs/trackerd.log
- 检查
文件上传成功但 HTTP 无法访问
- 确认 Nginx 配置中路径与
store_path0一致。 - 检查防火墙/安全组规则。
- 确认 Nginx 配置中路径与
Storage 无法连接 Tracker

- 确认
tracker_server配置的 IP 和端口正确。 - 使用
telnet <Tracker_IP> 22122测试连通性。
- 确认
如果需要集群部署,可以配置多个 Tracker 和 Storage 节点,并在 tracker_server 和 storage.conf 中指定多个节点地址。
