共计 4504 个字符,预计需要花费 12 分钟才能阅读完成。
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 的完整安装和配置步骤 http://www.linuxidc.com/Linux/2012-12/75989.htm
FastDFS 在 Ubuntu 下的安装,PHP 客户端 http://www.linuxidc.com/Linux/2012-09/71459.htm
FastDFS 分布式文件服务器安装,及配置,测试 http://www.linuxidc.com/Linux/2012-09/71458.htm
FastDFS 整合 Nginx 问题整理 http://www.linuxidc.com/Linux/2012-09/71232.htm
CentOS 下搭建 FastDFS http://www.linuxidc.com/Linux/2012-09/70995.htm
Ubuntu 安装 FastDFS 全程记录 http://www.linuxidc.com/Linux/2012-03/56377.htm
FastDFS 的详细介绍 :请点这里
FastDFS 的下载地址 :请点这里
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2015-08/121382.htm