1. Client询问Tracker server可以下载指定文件的Storage server,参数为文件ID(包含组名和文件名);
2. Tracker server返回一台可用的Storage server;
3. Client直接和该Storage server建立连接,完成文件下载。 基础环境
VMware虚拟机 中 CentOS 6.5 32位 最小化安装
# yum install gcc-c gcc-c++ perl下载FastDFS
FastDFS5.03下载地址:http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS Server Source Code/FastDFS Server with PHP Extension Source Code V5.03 安装FastDFS
# tar zxvf FastDFS_v5.03.tar.gz
# mv FastDFS /usr/local/
# cd /usr/local/FastDFS/
# vi make.sh
修改如下:
TARGET_PREFIX=/usr/local/FastDFS
TARGET_CONF_PATH=/etc/fdfs
WITH_LINUX_SERVICE=1
# ./make.sh
# ./make.sh install 本台服务器作为TrackerA来配置 配置TrackerA
本机IP:192.168.3.75
# cd /etc/fdfs/
# ls
client.conf http.conf mime.types storage.conf tracker.conf
# vi tracker.conf
bind_addr=192.168.3.75
base_path=/home/data/fastdfs
# mkdir -p /home/data/fastdfs
启动Tracker进程:
# /usr/local/FastDFS/tracker/fdfs_trackerd /etc/fdfs/tracker.conf
查看Tracker进程:
# netstat -ntpl|grep fdfs
tcp 0 0 192.168.3.75:22122 0.0.0.0:* LISTEN 1668/fdfs_trackerd开启防火墙端口:
# vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT
# service iptables restart配置TrackerA上的nginx + ngx_fastdfs_module
# tar zxvf fastdfs-nginx-module_v1.16.tar.gz
# mv fastdfs-nginx-module /usr/local/
# cp /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
配置mod_fastdfs.conf:
# vi /etc/fdfs/mod_fastdfs.conf
tracker_server=192.168.3.75:22122
tracker_server=192.168.3.74:22122
url_have_group_name = true
group_count = 2
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/home/data/fastdfs
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/home/data/fastdfs
安装nginx:
# vi /usr/local/fastdfs-nginx-module/src/config
ngx_addon_name=ngx_http_fastdfs_module
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/local/FastDFS/include/fastdfs /usr/local/FastDFS/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/local/FastDFS/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
# yum install pcre-devel zlib-devel
# tar zxvf nginx-1.6.1.tar.gz
# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module/src/
# make
# make install
修改nginx配置:
# vi /usr/local/nginx/conf/nginx.conf
listen 8080;
location ~ /group([0-9])/M00 {
ngx_fastdfs_module;
}
# ln -s /usr/local/FastDFS/lib/libfdfsclient.so /usr/lib/libfdfsclient.so
# ln -s /usr/local/FastDFS/lib/libfastcommon.so /usr/lib/libfastcommon.so
# vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
# service iptables restart 至此完成了FastDSF TrackerA服务器的配置
将虚拟机再复制三份
分别为TrackerB(192.168.3.74)、StorageA(192.168.3.77)、StorageB(192.168.3.76) 配置TrackerB
# cd /etc/fdfs/
# ls
client.conf http.conf mime.types storage.conf tracker.conf
# vi tracker.conf
bind_addr=192.168.3.74
# /usr/local/FastDFS/tracker/fdfs_trackerd /etc/fdfs/tracker.conf
# netstat -ntpl|grep fdfs
tcp 0 0 192.168.3.74:22122 0.0.0.0:* LISTEN 1440/fdfs_trackerd配置StorageA
# cd /etc/fdfs/
# ls
client.conf http.conf mime.types storage.conf tracker.conf
# vi storage.conf
group_name=group1
bind_addr=192.168.3.77
base_path=/home/data/fastdfs
store_path0=/home/data/fastdfs
tracker_server=192.168.3.75:22122
tracker_server=192.168.3.74:22122
# /usr/local/FastDFS/storage/fdfs_storaged /etc/fdfs/storage.conf
# netstat -ntpl|grep fdfs
tcp 0 0 192.168.3.77:23000 0.0.0.0:* LISTEN 1595/fdfs_storaged开启防火墙
# vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT
# service iptables restart配置StorageB
# cd /etc/fdfs/
# ls
client.conf http.conf mime.types storage.conf tracker.conf
# vi storage.conf
group_name=group2
bind_addr=192.168.3.76
base_path=/home/data/fastdfs
store_path0=/home/data/fastdfs
tracker_server=192.168.3.75:22122
tracker_server=192.168.3.74:22122
# /usr/local/FastDFS/storage/fdfs_storaged /etc/fdfs/storage.conf
# netstat -ntpl|grep fdfs
tcp 0 0 192.168.3.76:23000 0.0.0.0:* LISTEN 1558/fdfs_storaged开启防火墙
# vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT
# service iptables restart 到此4台服务器配置完成 测试文件上传及下载
四台服务器启动nginx进程:
/usr/local/nginx/nginx
以在TrackerA服务器上传为例。
修改client.conf配置
# vi /etc/fdfs/client.conf
base_path=/home/data/fastdfs
tracker_server=192.168.3.75:22122
http.tracker_server_port=8080 TrackerA上第一次上传:
# /usr/local/FastDFS/client/fdfs_test /etc/fdfs/client.conf upload /home/abel/upload/nginx-1.6.1.tar.gz
This is FastDFS client test program v5.03
Copyright (C) 2008, Happy Fish / YuQing
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.
[2014-09-05 19:32:44] DEBUG - base_path=/home/data/fastdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=192.168.3.76, port=23000
group_name=group2, ip_addr=192.168.3.76, port=23000
storage_upload_by_filename
group_name=group2, remote_filename=M00/00/00/wKgDTFQJn1uACkjfAAxB5Q0Pr6s.tar.gz
source ip address: 192.168.3.76
file timestamp=2014-09-05 19:32:43
file size=803301
file crc32=219131819
example file url: http://192.168.3.76:8080/group2/M00/00/00/wKgDTFQJn1uACkjfAAxB5Q0Pr6s.tar.gz
storage_upload_slave_by_filename
group_name=group2, remote_filename=M00/00/00/wKgDTFQJn1uACkjfAAxB5Q0Pr6s_big.tar.gz
source ip address: 192.168.3.76
file timestamp=2014-09-05 19:32:44
file size=803301
file crc32=219131819
example file url: http://192.168.3.76:8080/group2/M00/00/00/wKgDTFQJn1uACkjfAAxB5Q0Pr6s_big.tar.gz
在浏览器中打开以下网址均可下载刚上传的文件:
http://192.168.3.74:8080/group2/M00/00/00/wKgDTFQJn1uACkjfAAxB5Q0Pr6s_big.tar.gz
http://192.168.3.75:8080/group2/M00/00/00/wKgDTFQJn1uACkjfAAxB5Q0Pr6s_big.tar.gz
http://192.168.3.76:8080/group2/M00/00/00/wKgDTFQJn1uACkjfAAxB5Q0Pr6s_big.tar.gz
http://192.168.3.77:8080/group2/M00/00/00/wKgDTFQJn1uACkjfAAxB5Q0Pr6s_big.tar.gz 过一会儿TrackerA上第二次:
# /usr/local/FastDFS/client/fdfs_test /etc/fdfs/client.conf upload /home/abel/upload/nginx-1.6.1.tar.gz
This is FastDFS client test program v5.03
Copyright (C) 2008, Happy Fish / YuQing
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.
[2014-09-05 19:36:15] DEBUG - base_path=/home/data/fastdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=192.168.3.77, port=23000
group_name=group1, ip_addr=192.168.3.77, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgDTVQJoC6AcaHrAAxB5Q0Pr6s.tar.gz
source ip address: 192.168.3.77
file timestamp=2014-09-05 19:36:14
file size=803301
file crc32=219131819
example file url: http://192.168.3.77:8080/group1/M00/00/00/wKgDTVQJoC6AcaHrAAxB5Q0Pr6s.tar.gz
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgDTVQJoC6AcaHrAAxB5Q0Pr6s_big.tar.gz
source ip address: 192.168.3.77
file timestamp=2014-09-05 19:36:14
file size=803301
file crc32=219131819
example file url: http://192.168.3.77:8080/group1/M00/00/00/wKgDTVQJoC6AcaHrAAxB5Q0Pr6s_big.tar.gz
在浏览器中打开以下网址均可下载刚上传的文件:
http://192.168.3.74:8080/group1/M00/00/00/wKgDTVQJoC6AcaHrAAxB5Q0Pr6s_big.tar.gz
http://192.168.3.75:8080/group1/M00/00/00/wKgDTVQJoC6AcaHrAAxB5Q0Pr6s_big.tar.gz
http://192.168.3.76:8080/group1/M00/00/00/wKgDTVQJoC6AcaHrAAxB5Q0Pr6s_big.tar.gz
http://192.168.3.77:8080/group1/M00/00/00/wKgDTVQJoC6AcaHrAAxB5Q0Pr6s_big.tar.gz