Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

CentOS 7/8 部署 FastDFS 分散式檔案系統完整實戰指南

編輯:關於伺服器

FastDFS 是一款開源的輕量級分散式檔案系統,專為海量小檔案(圖片、短影片、文件)存儲設計,提供檔案上傳、下載、同步、存儲節點自動發現等功能,完美解決大容量存儲與負載均衡問題。本文記錄在 CentOS 7/8 環境下,從零開始部署 Tracker + Storage + Nginx + fastdfs-nginx-module 完整叢集的標準化流程,供生產環境參考部署。

架構規劃

角色IP 範例核心服務
Tracker Server10.0.0.11fdfs_trackerd (調度/中繼)
Storage Server 110.0.0.21fdfs_storaged + Nginx + fastdfs-nginx-module
Storage Server 210.0.0.22fdfs_storaged + Nginx + fastdfs-nginx-module
Client / App10.0.0.100應用伺服器 (SDK/CLI 上傳)

前置準備(所有節點通用)

# 關閉 SELinux / 設為 Permissive
setenforce 0
sed -i 's/^SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config

# 安裝編譯工具鏈與依賴
yum -y groupinstall "Development Tools"
yum -y install libevent libevent-devel perl pcre pcre-devel zlib zlib-devel openssl openssl-devel gcc-c++

# 建立統一工作目錄
mkdir -p /opt/fastdfs/{src,conf,data,log}
cd /opt/fastdfs/src

1. 安裝 libevent(Tracker/Storage 皆需)

wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz
tar -zxf libevent-2.1.12-stable.tar.gz
cd libevent-2.1.12-stable
./configure --prefix=/usr/local/libevent
make && make install
echo '/usr/local/libevent/lib' > /etc/ld.so.conf.d/libevent.conf
ldconfig

2. 編譯安裝 FastDFS (v5.05+ 建議)

wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz -O fastdfs-5.05.tar.gz
tar -zxf fastdfs-5.05.tar.gz
cd fastdfs-5.05
./make.sh
./make.sh install
# 預設安裝至 /usr/bin、/etc/fdfs、/usr/lib64

3. 配置 Tracker Server (10.0.0.11)

cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
vim /etc/fdfs/tracker.conf
# 關鍵參數:
# base_path=/opt/fastdfs/data/tracker
# http.server_port=8080  # 內建 HTTP 管理介面(可選)
mkdir -p /opt/fastdfs/data/tracker
systemctl start fdfs_trackerd   # 或 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
systemctl enable fdfs_trackerd

4. 配置 Storage Server (10.0.0.21 / 10.0.0.22)

cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
vim /etc/fdfs/storage.conf
# 關鍵參數:
# base_path=/opt/fastdfs/data/storage
# store_path0=/opt/fastdfs/data/storage
# tracker_server=10.0.0.11:22122
# http.server_port=8888
mkdir -p /opt/fastdfs/data/storage
systemctl start fdfs_storaged
systemctl enable fdfs_storaged

5. 安裝 Nginx + fastdfs-nginx-module (Storage 節點)

# Nginx 1.20+
wget https://nginx.org/download/nginx-1.20.1.tar.gz
tar -zxf nginx-1.20.1.tar.gz

# fastdfs-nginx-module
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz -O fastdfs-nginx-module-1.22.tar.gz
tar -zxf fastdfs-nginx-module-1.22.tar.gz

cd nginx-1.20.1
./configure --prefix=/usr/local/nginx \
            --add-module=../fastdfs-nginx-module-1.22/src \
            --with-http_ssl_module \
            --with-http_stub_status_module \
            --with-http_gzip_static_module
make && make install

6. 配置 Nginx 整合 FastDFS

cp ../fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf
# 關鍵參數:
# tracker_server=10.0.0.11:22122
# storage_server_port=8888
# url_have_group_name=true
# store_path0=/opt/fastdfs/data/storage

# 修改 nginx.conf
vim /usr/local/nginx/conf/nginx.conf
# 在 server 區塊新增:
location /group1/M00 {
    alias /opt/fastdfs/data/storage/data;
    ngx_fastdfs_module;
}
# 若有多群組,依序新增 group2/M00 等

/usr/local/nginx/sbin/nginx -t && /usr/local/nginx/sbin/nginx

7. 客戶端測試上傳

cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vim /etc/fdfs/client.conf
# base_path=/opt/fastdfs/client
# tracker_server=10.0.0.11:22122

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /path/to/test.jpg
# 成功回傳:group1/M00/00/00/wKgBzF...jpg
# 瀏覽器訪問:https://10.0.0.21/group1/M00/00/00/wKgBzF...jpg
# Tracker 會 302 重導向至實際 Storage 節點下載

生產環境加固建議

  • 高可用 Tracker: 部署 2+ Tracker 互為備援,client.conf 列出所有 tracker_server。
  • Storage 分群組: 不同業務/機房分群組,避免單點故障波及全系統。
  • 監控告警: 監控 Tracker/Storage 進程存活、磁碟使用率、同步延遲、Nginx 狀態。
  • 防火牆: 僅開放 Tracker 22122、Storage 23000/8888、Nginx 80/443 給必要來源。
  • 備份策略: 定期備份 /etc/fdfs 配置、Nginx 配置;資料層依賴多節點複製,無需傳統備份。

FastDFS 架構簡單、效能優異、擴容靈活,是中小型海量檔案存儲的首選方案。遵循標準化部署流程、建立完善監控與應急預案,即可穩定支撐千萬級檔案存儲業務。

Copyright © Windows教程網 All Rights Reserved