插件窝 干货文章 FastDFS怎么安装和配置整合Nginx-1.13.3

FastDFS怎么安装和配置整合Nginx-1.13.3

FastDFS Nginx tracker bash 167    来源:    2025-04-24

FastDFS 安装与配置整合 Nginx-1.13.3 指南

一、FastDFS 安装

1. 安装依赖

yum install -y gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel

2. 下载并安装 libfastcommon

wget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz
tar -zxvf V1.0.43.tar.gz
cd libfastcommon-1.0.43
./make.sh
./make.sh install

3. 下载并安装 FastDFS

wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz
tar -zxvf V6.06.tar.gz
cd fastdfs-6.06
./make.sh
./make.sh install

4. 配置 FastDFS

配置 tracker

cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
mkdir -p /data/fastdfs/tracker

编辑 /etc/fdfs/tracker.conf:

port=22122
base_path=/data/fastdfs/tracker

配置 storage

cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
mkdir -p /data/fastdfs/storage

编辑 /etc/fdfs/storage.conf:

group_name=group1
port=23000
base_path=/data/fastdfs/storage
store_path0=/data/fastdfs/storage
tracker_server=your_tracker_server_ip:22122
http.server_port=8888

配置 client

cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf

编辑 /etc/fdfs/client.conf:

base_path=/data/fastdfs/client
tracker_server=your_tracker_server_ip:22122

5. 启动服务

# 启动 tracker
/etc/init.d/fdfs_trackerd start

# 启动 storage
/etc/init.d/fdfs_storaged start

二、Nginx-1.13.3 安装与整合

1. 下载并安装 Nginx

wget http://nginx.org/download/nginx-1.13.3.tar.gz
tar -zxvf nginx-1.13.3.tar.gz
cd nginx-1.13.3
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install

2. 安装 fastdfs-nginx-module

wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz
tar -zxvf V1.22.tar.gz
cd fastdfs-nginx-module-1.22/src

修改 config 文件,将 CORE_INCS 改为:

CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"

3. 重新编译 Nginx

cd nginx-1.13.3
./configure --prefix=/usr/local/nginx --add-module=/path/to/fastdfs-nginx-module/src
make
make install

4. 配置 fastdfs-nginx-module

cp /path/to/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

编辑 /etc/fdfs/mod_fastdfs.conf:

connect_timeout=10
tracker_server=your_tracker_server_ip:22122
url_have_group_name=true
store_path0=/data/fastdfs/storage

5. 配置 Nginx

编辑 /usr/local/nginx/conf/nginx.conf:

server {
    listen       80;
    server_name  localhost;

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

    location / {
        root   html;
        index  index.html index.htm;
    }
}

6. 启动 Nginx

/usr/local/nginx/sbin/nginx

三、验证安装

  1. 上传测试文件:
fdfs_test /etc/fdfs/client.conf upload /path/to/testfile
  1. 通过浏览器访问上传的文件:
http://your_server_ip/group1/M00/00/00/xxx.jpg

四、常见问题解决

  1. Nginx 报错找不到 libfastcommon.so
echo "/usr/lib64" >> /etc/ld.so.conf
ldconfig
  1. 权限问题: 确保 /data/fastdfs 目录有正确的权限:
chown -R nobody:nobody /data/fastdfs
  1. 防火墙设置
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=22122/tcp
firewall-cmd --permanent --add-port=23000/tcp
firewall-cmd --reload

通过以上步骤,您应该已经成功安装并配置了 FastDFS 与 Nginx-1.13.3 的整合。