Linux下搭建 FastDFS + Nginx


Linux下搭建 FastDFS + Nginx

FastDfs 依赖 libevent。

先决条件:

1.测试环境目录为: /home/users/wangyanpei/

2.libevent 版本: 2.0.21-stable

3.Fastdfs 版本: FastDFS_v4.06.tar.gz

4.Nginx 版本: 1.6.0

5.fastdfs-nginx-module版本: fastdfs-nginx-module_v1.15.tar.gz

安装路径:

  nginx: /home/users/wangyanpei/nginx

  fastdfs : /home/users/wangyanpei/FastDFS

  tracker路径: /home/users/wangyanpei/tracker/

  storage路径: /home/users/wangyanpei/storage/

  libevent 路径:/home/users/wangyanpei/libevent-2.0.21

第一步:安装libevent:

    wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz 放到 /home/users/wangyanpei/setup/

    tar zxvf libevent-2.0.21-stable.tar.gz

    cd libevent-2.0.21-stable

    ./configure --prefix=/home/users/wangyanpei/libevent-2.0.21

    make & make install 

  第二部:安装FastDFS

  wget http://fastdfs.googlecode.com/files/FastDFS_v4.06.tar.gz 到 /home/users/wangyanpei/setup/

  tar zxvf FastDFS_v4.06.tar.gz

  cd FastDFS

  vim make.sh【配置安装路径】

      TARGET_PREFIX=/home/users/miaolinjie/FastDFS  ---安装路径

      TARGET_CONF_PATH=/home/users/miaolinjie/FastDFS/conf  ---配置文件路径

      WITH_LINUX_SERVICE=1  ---是否为linux服务

  ./make.sh C_INCLUDE_PATH=/home/users/wangyanpei/libevent-2.0.21/include LIBRARY_PATH=/home/users/miaolinjie/libevent-2.0.21/lib/

  ./make install

  第三步:安装Nginx 和 fastdfs-nginx-module

    wget http://nginx.org/download/nginx-1.6.0.tar.gz

    wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz

    到 /home/users/wangyanpei/setup下

    解压

    cd fastdfs-nginx-module/src/

    vim config[修改依赖lib和include文件路径]

          CORE_INCS="$CORE_INCS /home/users/wangyanpei/FastDFS/include/fastdfs /home/users/wangyanpei/FastDFS/include/fastcommon/"

          CORE_LIBS="$CORE_LIBS -L/home/users/wangyanpei/FastDFS/include/lib -lfastcommon -lfdfsclient"

          CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -                DFDFS_MOD_CONF_FILENAME='\"/home/users/wangyanpei/FastDFS/conf/mod_fastdfs.conf\"'"

    将fastdfs-nginx-module的mod_fastdfs.conf 拷贝到config中指定的路径下:       

    cp /home/users/wangyanpei/setup/fastdfs-nginx-module/src/mod_fastdfs.conf /home/users/miaolinjie/FastDFS/conf

      安装Nginx:

      cd Nginx_1.6.0

      ./configure --prefix=/home/users/wangyanpei/nginx --conf-path=/home/users/wangyanpei/nginx/conf/nginx.conf --add-module=/home/users/wangyanpei/setup/fastdfs-nginx-module/src/

      make && make install

    启动nginx, 如果启动不了 将fastdfs的目录拷贝到对应目录下就可以。

      ./sbin/nginx -c conf/nginx.conf     

第四步: 配置tracker server

      vim conf/tracker.conf

      bind_addr=本机ip

      base_path=/home/users/wangyanpei/tracker/【该目录保存tracker知道的信息和log】

      启动:

      ./bin/fdfs_trackerd ./conf/tracker.conf

第五步: 配置storage server

      vim conf/storage.conf

      group_name=group1  隶属于哪个group

      bind_addr

      base_path=/home/users/wangyanpei/storage

      store_path0=/home/users/wangyanpei/storage

      tracker_server=ip:port

      http.server_port=8090

      启动

      ./bin/fdfs_storaged ./conf/storage.conf

第六步: 修改 mod_fastdfs.conf 

      base_path=/home/users/wangyanpei/storage

      group_name=group1

      store_path0=/home/users/wangyanpei/storage

      tracker_server=ip:port

      url_have_group_name=true

 第七步: 修改client.conf

    base_path=/home/users/wangyanpei/storage

    tracker_server=ip:port

    http.tracker_server_port=8090

第八步: 修改nginx.conf

    location /group1/M00 {

        root /home/users/wangyanpei/storage/data;

          ngx_fastdfs_module; 

  }

重启nginx

第九步:测试

  ./bin/fdfs_test ./conf/client.conf upload /etc/passwd

结果:

tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=182.92.128.99, port=23001

group_name=group1, ip_addr=182.92.128.99, port=23001
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/tlyAY1WJEWqAKulyAAAGPHfAkyI2479341
source ip address: 182.92.128.99
file timestamp=2015-06-23 15:57:30
file size=1596
file crc32=2009109282
file url: http://182.92.128.99:8090/group1/M00/00/00/tlyAY1WJEWqAKulyAAAGPHfAkyI2479341
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/tlyAY1WJEWqAKulyAAAGPHfAkyI2479341_big
source ip address: 182.92.128.99
file timestamp=2015-06-23 15:57:30
file size=1596
file crc32=2009109282
file url: http://182.92.128.99:8090/group1/M00/00/00/tlyAY1WJEWqAKulyAAAGPHfAkyI2479341_big

浏览器中打开http://182.92.128.99:8090/group1/M00/00/00/tlyAY1WJEWqAKulyAAAGPHfAkyI2479341_big可以访问到上传文件。

CentOS 6.2下fastDFS的完整安装和配置步骤

FastDFS在Ubuntu下的安装,PHP客户端

FastDFS分布式文件服务器安装,及配置,测试

FastDFS 整合Nginx问题整理

CentOS下搭建FastDFS

Ubuntu安装FastDFS全程记录

FastDFS 的详细介绍:请点这里
FastDFS 的下载地址:请点这里

本文永久更新链接地址

相关内容