企业项目管理、ORK、研发管理与敏捷开发工具平台

网站首页 > 精选文章 正文

FastDFS 安装步骤(Linux 环境)

wudianyun 2025-05-23 20:40:46 精选文章 4 ℃


1. 安装依赖库

# Ubuntu/Debian
sudo apt update
sudo apt install -y gcc make libevent-dev

# CentOS/RHEL
sudo yum install -y gcc make libevent-devel

2. 下载并安装 libfastcommon

# 下载源码
wget https://github.com/happyfish100/libfastcommon/archive/refs/tags/V1.0.72.tar.gz
tar -zxvf V1.0.72.tar.gz
cd libfastcommon-1.0.72/

# 编译安装
./make.sh
sudo ./make.sh install

3. 下载并安装 FastDFS

# 下载源码
wget https://github.com/happyfish100/fastdfs/archive/refs/tags/V6.11.0.tar.gz
tar -zxvf V6.11.0.tar.gz
cd fastdfs-6.11.0/

# 编译安装
./make.sh
sudo ./make.sh install

4. 配置 FastDFS

  • Tracker 配置
    复制默认配置文件并修改:
sudo cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
sudo vi /etc/fdfs/tracker.conf

修改关键参数:

base_path=/opt/fastdfs/tracker  # Tracker 数据存储路径
port=22122                      # Tracker 服务端口

Storage 配置
复制默认配置文件并修改:

sudo cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
sudo vi /etc/fdfs/storage.conf

修改关键参数:

base_path=/opt/fastdfs/storage          # Storage 数据存储路径
store_path0=/opt/fastdfs/storage/files  # 文件存储路径
tracker_server=your_tracker_ip:22122    # Tracker 服务器地址
port=23000                             # Storage 服务端口

5. 启动服务

# 启动 Tracker
sudo /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start

# 启动 Storage
sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start

6. 测试上传文件

# 配置客户端
sudo cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
sudo vi /etc/fdfs/client.conf

修改关键参数:

base_path=/opt/fastdfs/client
tracker_server=your_tracker_ip:22122

测试上传

echo "Hello FastDFS" > test.txt
fdfs_upload_file /etc/fdfs/client.conf test.txt
成功后会返回文件存储路径(如 `group1/M00/00/00/xxx.txt`)。

---

### **常见问题排查**
1. **依赖缺失**  
   确保已安装 `gcc`, `make`, `libevent-dev`。

2. **权限问题**  
   创建数据存储目录并赋予权限:
   ```bash
   sudo mkdir -p /opt/fastdfs/{tracker,storage,client}
   sudo chmod -R 755 /opt/fastdfs
   

3.服务启动失败
检查日志文件:

tail -f /opt/fastdfs/tracker/logs/trackerd.log
tail -f /opt/fastdfs/storage/logs/storaged.log

4.防火墙端口
开放 Tracker 和 Storage 的端口:

sudo ufw allow 22122/tcp
sudo ufw allow 23000/tcp

附加组件(可选)

  • Nginx + FastDFS 模块
    实现 HTTP 访问文件:
# 安装 Nginx 插件
git clone https://github.com/happyfish100/fastdfs-nginx-module.git
# 编译 Nginx 时添加模块 --add-module=fastdfs-nginx-module/src
最近发表
标签列表