Build a Local FastDFS Cluster with Nginx and cpolar for Remote File Access
This guide walks through installing FastDFS on a Linux server, configuring its tracker and storage nodes, integrating the FastDFS Nginx module, and exposing the service to the internet using cpolar, providing a complete end‑to‑end solution for distributed file storage and remote access.
Introduction
FastDFS is an open‑source lightweight distributed file system that manages file storage, synchronization, and access, making it ideal for file‑centric online services such as photo albums and video sites. By deploying FastDFS locally and exposing it via Nginx and cpolar, you can avoid the cost of a public server while still providing internet‑accessible file services.
1. Install FastDFS Locally
1.1 Environment Installation
FastDFS is written in C, so you need the GCC compiler and libevent library.
yum -y install gcc-c++ yum -y install libevent1.2 Install libfastcommon
libfastcommon provides essential libraries for FastDFS. cd /usr/local Download the release from GitHub:
https://github.com/happyfish100/libfastcommon/releases/tag/V1.0.7
Upload the tarball to /usr/local, then extract and compile:
tar -zxvf libfastcommonV1.0.7.tar.gz
cd libfastcommon-1.0.7/
./make.sh
./make.sh installCopy the generated library to /usr/lib (FastDFS expects it there):
cp /usr/lib64/libfastcommon.so /usr/lib/1.3 Install FastDFS
Download FastDFS source (e.g., version 5.05) from SourceForge, upload it to /usr/local, then extract and compile:
tar -zxvf FastDFS_v5.05.tar.gz
cd FastDFS
./make.sh
./make.sh installCopy the configuration files to /etc/fdfs:
cd conf
cp * /etc/fdfs/1.4 Configure Tracker
Edit /etc/fdfs/tracker.conf and set the base path: vim /etc/fdfs/tracker.conf Change base_path=/home/yuqing/fastdfs to base_path=/home/fastdfs, then create the directory: mkdir /home/fastdfs Start the tracker and enable it at boot:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart vim /etc/rc.d/rc.local # add the above command1.5 Configure Storage
Edit /etc/fdfs/storage.conf: vim /etc/fdfs/storage.conf Set base_path=/home/fastdfs and store_path0=/home/fastdfs/fdfs_storage, then specify the tracker server address (e.g., 192.168.59.133:22122). mkdir /home/fastdfs/fdfs_storage Start the storage daemon and enable it at boot:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart vim /etc/rc.d/rc.local # add the above command1.6 Test Upload/Download
Modify /etc/fdfs/client.conf to match the tracker address and base path:
base_path=/home/fastdfs
tracker_server=192.168.59.133:22122Upload a test file:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/local/test23.pngThe command returns a file URL, confirming successful upload.
1.7 Integrate FastDFS with Nginx
Download the FastDFS Nginx module source:
https://sourceforge.net/projects/fastdfs/files/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz/download
Extract the module and adjust its config file to use /usr/ instead of /usr/local/:
cd /usr/local
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
cd fastdfs-nginx-module/src
vim config # edit pathsCopy the generated mod_fastdfs.conf to /etc/fdfs and edit it:
vim /etc/fdfs/mod_fastdfs.conf base_path=/home/fastdfs
tracker_server=192.168.59.133:22122
url_have_group_name=true
store_path0=/home/fastdfs/fdfs_storageCopy the client library for Nginx:
cp /usr/lib64/libfdfsclient.so /usr/lib/1.8 Install Nginx
Install dependencies:
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-develDownload Nginx source (e.g., 1.16.1) and compile with the FastDFS module:
tar -zxvf nginx-1.16.1.tar.gz && cd nginx-1.16.1
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--add-module=/usr/local/fastdfs-nginx-module/src
make
make install1.9 Configure Nginx
Edit /usr/local/nginx/conf/nginx.conf and add a server block to handle FastDFS requests:
server {
listen 8089; # use a non‑standard port to avoid conflict with port 80
server_name 192.168.59.133;
location /group1/M00/ {
ngx_fastdfs_module;
}
}Start Nginx and enable it at boot:
/usr/local/nginx/sbin/nginx
vim /etc/rc.d/rc.local # add the above commandIf Nginx fails because the PID file directory is missing, create it: mkdir /var/run/nginx Disable the firewall to allow external access:
service iptables stop
chkconfig iptables off2. Test LAN Access
Use the FastDFS test client to upload a file and then open the returned URL in a browser. The image should be displayed, confirming that FastDFS and Nginx are working together.
3. Install cpolar (Internet Tunnel)
Install cpolar with a one‑line script:
curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bashAuthenticate with your token: cpolar authtoken YOUR_TOKEN Enable and start the cpolar service:
sudo systemctl enable cpolar
sudo systemctl start cpolar4. Configure Public Access via cpolar
Log in to the cpolar web UI, create an HTTP tunnel that forwards to the Nginx port 8089, and obtain a public URL. Visiting this URL in a browser will reach the FastDFS‑served file.
5. Reserve a Fixed Sub‑Domain
Upgrade to a paid cpolar plan, reserve a second‑level sub‑domain (e.g., fasttest), and bind it to the tunnel. After updating the tunnel configuration, the public address becomes fasttest.cpolar.io (or similar) and remains stable.
6. Verify Fixed Sub‑Domain Access
Open the fixed sub‑domain URL in a browser and confirm that the uploaded image loads, demonstrating permanent remote access without needing a public IP or router configuration.
By following these steps you obtain a fully functional, cost‑effective distributed file storage service that can be accessed from anywhere.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
