Operations 25 min read

FastDFS Overview, Architecture, and Deployment Guide

FastDFS is an open‑source lightweight distributed file system written in C, designed for high‑availability file storage and load balancing; this article explains its differences from Hadoop, details its Tracker and Storage architecture, outlines file upload/download workflows, and provides step‑by‑step instructions for installing and configuring FastDFS, Nginx, and related components.

Architecture Digest
Architecture Digest
Architecture Digest
FastDFS Overview, Architecture, and Deployment Guide

FastDFS is an open‑source lightweight distributed file system written in C, providing file storage, synchronization, and access, suitable for online services such as photo albums and video sites.

Difference with Hadoop

Hadoop also offers a distributed file system but focuses on big‑data processing, whereas FastDFS is optimized for storing and serving files (typically 4KB < file_size < 500MB), making it ideal for image and media storage.

FastDFS Architecture

The system consists of Tracker servers and Storage servers. Clients first contact a Tracker to obtain the address of an appropriate Storage node; the Tracker performs load‑balancing and dispatches the request. Storage servers store files using the underlying OS file system and report heartbeats to the Tracker, which maintains a lightweight in‑memory mapping of groups to storage nodes.

Storage servers are organized into groups (volumes). Each group may contain multiple storage nodes that provide redundancy and load‑balancing; the effective capacity of a group is limited by the smallest node in the group.

File Upload Process

The client queries the Tracker for a storage node, receives the IP and port, and then uploads the file directly to that Storage server. After storing the file, the Storage server returns a file ID (including group name, virtual path, directory levels, and generated filename) to the client.

Group name: the storage group returned after upload. Virtual disk path: corresponds to store_path* configuration (e.g., M00, M01). Data two‑level directory: directories created under the virtual path for storing data files. File name: generated by the storage server and includes source IP, timestamp, size, random number, and extension.

File Download Process

The client asks the Tracker for a storage node that holds the requested file (identified by group name and file name). The Tracker returns an available storage node, and the client downloads the file directly from that node.

Installation Overview

Components to install: nginx + FastDFS + fastdfs‑nginx‑module .

Firewall Configuration

Open Tracker port (default 22122) and Storage port (default 23000) in /etc/sysconfig/iptables :

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT

Restart the firewall with service iptables restart .

Install libevent

yum -y install libevent

Install libfastcommon

Upload fastdfs‑master.zip and libfastcommon‑master.zip to /opt on all servers, then:

unzip libfastcommon-master.zip cd libfastcommon-master ./make.sh ./make.sh install cp /usr/lib64/libfastcommon.so /usr/lib/

Install Tracker Service

unzip fastdfs-master.zip cd fastdfs-master ./make.sh ./make.sh install

Copy configuration files:

cp -r /opt/fastdfs-master/conf/* /etc/fdfs

Create directories:

mkdir -p /data/fastdfs/tracker mkdir -p /data/fastdfs/storage mkdir -p /data/fastdfs/client

Configure Tracker

Edit /etc/fdfs/conf/tracker.conf (key settings shown):

port=22122 base_path=/data/fastdfs/tracker

Configure Storage

Edit /etc/fdfs/conf/storage.conf on each storage node:

group_name=group1 port=23000 base_path=/data/fastdfs/storage store_path0=/data/fastdfs/storage tracker_server=192.168.80.32:22122

Configure Client

vim /etc/fdfs/client.conf
base_path=/data/fastdfs/client tracker_server=192.168.80.32:22122

Start Services

Tracker:

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart chkconfig fdfs_trakcerd on

Storage:

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart /etc/init.d/fdfs_storaged stop chkconfig fdfs_storaged on

Test upload:

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /etc/fdfs/anti-steal.jpg

Integrate Nginx with FastDFS

Compile Nginx with the fastdfs‑nginx‑module :

yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel ./configure \ --prefix=/opt/nginx \ --add-module=/opt/fastdfs-nginx-module/src make && make install

Configure Nginx ( /opt/nginx/conf/nginx.conf ) to handle FastDFS URLs:

server { listen 8888; server_name 192.168.80.32; location /group1/M00/ { ngx_fastdfs_module; } }

Adjust the location regex if multiple groups exist:

location ~/group([0-9])/M00 { ngx_fastdfs_module; }

fastdfs‑nginx‑module Configuration

Copy and edit mod_fastdfs.conf :

cp mod_fastdfs.conf /etc/fdfs/ vim /etc/fdfs/mod_fastdfs.conf base_path=/tmp tracker_server=192.168.80.32:22122 storage_server_port=23000 url_have_group_name = true store_path0=/data/fastdfs/storage group_name=group1

Open Nginx Port

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8888 -j ACCEPT

Restart firewall: service iptables restart

Auto‑Start on Boot

Add to /etc/rc.local :

/opt/nginx/sbin/nginx

Make it executable: chmod 755 /etc/rc.local

Test Access

After uploading a file, access it via:

http://192.168.80.32:8888/group1/M00/00/00/wKhQIFoKF3KAfw8wAABdrZgsqUU551_big.jpg

Warning: Do not kill FastDFS processes with kill -9 as it may cause binlog loss.

Configuration Details

Key Tracker configuration parameters include port=22122 , base_path , heartbeat intervals, and load‑balancing settings. Storage configuration covers group_name , port=23000 , store_path0 , heartbeat and sync intervals, and optional HTTP settings.

For full parameter reference, see the original article.

NginxstorageInstallationdistributed file systemfastdfs
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.