请联系我 有广告合作意向的 请联系我

FastDFS配置及Nginx的FastDFS模块安装

FastDFS是一个开源的分布式文件系统,她对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务,如相册网站、视频网站等等。
FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage)。跟踪器主要做调度工作,在访问上起负载均衡的作用。
关于设计理念、架构及交互过程查看链接:http://bbs.chinaunix.net/thread-3674148-1-4.html
关于NGINX与FastDFS及模块资源

http://code.google.com/p/fastdfs/downloads/list   
http://nginx.org/download/nginx-1.2.5.tar.gz   
http://fastdfs.googlecode.com/files/FastDFS_v4.03.tar.gz   
http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.13.tar.gz  

部署环境

storage服务器:42.121.79.15  mail.01314.cn  CentOS 6.2 x86_64   
tracker服务器:42.121.79.38  bbs.01314.cn  CentOS 5.7 x86_64   

1、安装FastDFS_v4.03

[root@mail FastDFS]# yum install -y libevent-devel   
[root@mail FastDFS]# tar zxf FastDFS_v4.03.tar.gz    
[root@mail FastDFS]# cd FastDFS   
#安装httpd和fdfs_trackerd/fdfs_storaged服务,用的nginx可以不用安装httpd   
#WITH_HTTPD=1  
#WITH_LINUX_SERVICE=1  
[root@mail FastDFS]# ./make.sh   
[root@mail FastDFS]# ./make.sh install   
mkdir -p /usr/local/bin   
mkdir -p /etc/fdfs   
cp -f fdfs_trackerd  /usr/local/bin   
if [ ! -f /etc/fdfs/tracker.conf ]; then cp -f ../conf/tracker.conf ../conf/mime.types ../conf/http.conf /etc/fdfs; fi   
mkdir -p /usr/local/bin   
mkdir -p /etc/fdfs   
cp -f fdfs_storaged  /usr/local/bin   
if [ ! -f /etc/fdfs/storage.conf ]; then cp -f ../conf/storage.conf ../conf/mime.types ../conf/http.conf /etc/fdfs; fi   
mkdir -p /usr/local/bin   
mkdir -p /etc/fdfs   
mkdir -p /usr/local/lib   
cp -f fdfs_monitor fdfs_test fdfs_test1 fdfs_crc32 fdfs_upload_file fdfs_download_file fdfs_delete_file fdfs_file_info fdfs_appender_test fdfs_appender_test1    
  
fdfs_append_file fdfs_upload_appender /usr/local/bin   
if [ 0 -eq 1 ]; then cp -f libfastcommon.a libfdfsclient.a /usr/local/lib; fi   
if [ 1 -eq 1 ]; then cp -f libfastcommon.so.1 libfdfsclient.so.1 /usr/local/lib; fi   
if [ 1 -eq 1 ]; then ln -fs /usr/local/lib/libfastcommon.so.1 /usr/local/lib/libfastcommon.so; fi   
if [ 1 -eq 1 ]; then ln -fs /usr/local/lib/libfdfsclient.so.1 /usr/local/lib/libfdfsclient.so; fi   
if [ ! -f /etc/fdfs/client.conf ]; then cp -f ../conf/client.conf ../conf/http.conf /etc/fdfs; fi   
mkdir -p /usr/local/include   
mkdir -p /usr/local/include/fastcommon   
mkdir -p /usr/local/include/fastdfs   
cp -f ../common/common_define.h ../common/hash.h ../common/chain.h ../common/logger.h ../common/base64.h ../common/shared_func.h ../common/pthread_func.h    
  
../common/ini_file_reader.h ../common/sockopt.h ../common/sched_thread.h ../common/http_func.h ../common/md5.h ../common/_os_bits.h ../common/local_ip_func.h    
  
../common/avl_tree.h /usr/local/include/fastcommon   
cp -f ../common/fdfs_define.h ../common/fdfs_global.h ../common/mime_file_parser.h ../common/fdfs_http_shared.h ../tracker/tracker_types.h ../tracker/tracker_proto.h    
  
../tracker/fdfs_shared_func.h ../storage/trunk_mgr/trunk_shared.h tracker_client.h storage_client.h storage_client1.h client_func.h client_global.h fdfs_client.h    
  
/usr/local/include/fastdfs   
if [ 1 -eq 1 -a /usr/local/lib = "/usr/local/lib" ]; then sh ./fdfs_link_library.sh; fi   
  
[root@mail FastDFS]# ls /etc/fdfs/   
client.conf  http.conf  mime.types  storage.conf  tracker.conf 


2、tracker配置

[root@bbs ~]# sed '/^#/d;/^$/d' /etc/fdfs/tracker.conf       
disabled=false      
bind_addr=42.121.79.38      
port=22122      
connect_timeout=30      
network_timeout=60      
base_path=/data/fastdfs      
max_connections=256      
work_threads=2      
store_lookup=2      
store_group=group2      
store_server=0      
store_path=0      
download_server=0      
reserved_storage_space = 10%      
log_level=info      
run_by_group=      
run_by_user=      
allow_hosts=*      
sync_log_buff_interval = 10      
check_active_interval = 120      
thread_stack_size = 64KB      
storage_ip_changed_auto_adjust = true      
storage_sync_file_max_delay = 86400      
storage_sync_file_max_time = 300      
use_trunk_file = false       
slot_min_size = 256      
slot_max_size = 16MB      
trunk_file_size = 64MB      
trunk_create_file_advance = false      
trunk_create_file_time_base = 02:00      
trunk_create_file_interval = 86400      
trunk_create_file_space_threshold = 20G      
trunk_init_check_occupying = false      
trunk_init_reload_from_binlog = false      
use_storage_id = false      
storage_idsstorage_ids_filename = storage_ids.conf      
id_type_in_filename = ip      
store_slave_file_use_link = false      
rotate_error_log = false      
error_log_rotate_time=00:00      
rotate_error_log_size = 0      
http.disabled=false      
http.server_port=8080      
http.check_alive_interval=30      
http.check_alive_type=tcp      
http.check_alive_uri=/status.html      
http.need_find_content_type=true 


启动服务

[root@bbs ~]# /etc/init.d/fdfs_trackerd start   
[root@bbs ~]# netstat -tnlp |grep fdfs   
tcp  0  0  42.121.79.38:22122  0.0.0.0:*  LISTEN  29034/fdfs_trackerd  

3、storage配置

[root@mail M00]# sed '/^$/d;/#.*/d' /etc/fdfs/storage.conf       
disabled=false      
group_name=group1      
bind_addr=42.121.79.15      
client_bind=true      
port=23000      
connect_timeout=30      
network_timeout=60      
heart_beat_interval=30      
stat_report_interval=60      
base_path=/data/fastdfs      
max_connections=256      
buff_size = 256KB      
work_threads=2      
disk_rw_separated = true      
disk_reader_threads = 1      
disk_writer_threads = 1      
sync_wait_msec=50      
sync_interval=0      
sync_start_time=00:00      
sync_end_time=23:59      
write_mark_file_freq=500      
store_path_count=1      
store_path0=/data/fastdfs      
subdir_count_per_path=256      
tracker_server=42.121.79.38:22122      
log_level=info      
run_by_group=      
run_by_user=      
allow_hosts=*      
file_distribute_path_mode=0      
file_distribute_rotate_count=100      
fsync_after_written_bytes=0      
sync_log_buff_interval=10      
sync_binlog_buff_interval=10      
sync_stat_file_interval=300      
thread_stack_size=512KB      
upload_priority=10      
if_alias_prefix=      
check_file_duplicate=0      
file_signature_method=hash      
key_namespace=FastDFS      
keep_alive=0      
use_access_log = false      
rotate_access_log = false      
access_log_rotate_time=00:00      
rotate_error_log = false      
error_log_rotate_time=00:00      
rotate_access_log_size = 0      
rotate_error_log_size = 0      
file_sync_skip_invalid_record=false      
http.disabled=false      
httphttp.domain_name=      
http.server_port=8080      
http.trunk_size=256KB      
http.need_find_content_type=true 


启动服务

[root@mail M00]# /etc/init.d/fdfs_storaged start   
[root@mail ~]# netstat -tnlp |grep fdfs   
tcp  0  0  42.121.79.15:23000  0.0.0.0:*  LISTEN  18964/fdfs_storaged  

4、安装配置NGINX及FastDFS模块

[root@mail nginx-1.2.5]# yum install -y pcre-devel zlib-devel
[root@mail nginx-1.2.5]# tar zxf fastdfs-nginx-module_v1.13.tar.gz
[root@mail nginx-1.2.5]# tar zxf nginx-1.2.5.tar.gz
[root@mail nginx-1.2.5]# cd nginx-1.2.5
[root@mail nginx-1.2.5]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --add-module=/root/fastdfs-nginx-module/src
[root@mail nginx-1.2.5]# make && make install
[root@mail nginx-1.2.5]# cp /root/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

在nginx的server配置段中增加M00的location

location /group1/M00 {
root /data/fastdfs/data;
ngx_fastdfs_module;
}

这里的M00是FastDFS在生成文件名时的提供的。FastDFS可以设置多块硬盘的配置,所以这个M00主要用于标识具体是哪个存储路径。默认只有一个,所以建立一个M00的软连接即可。

ln -s /data/fastdfs/data /data/fastdfs/data/M00

重新加载NGINX配置,这里需要注意fdfs_trackerd/fdfs_storaged两服务的防火墙过滤,如果端口未开放可能会报如下错误

ERROR - file: tracker_proto.c, line: 459, connect to 42.121.79.15:23000 fail, errno: 113, error info: No route to host  

5、客户端上传文件测试 修改client.conf文件

[root@bbs ~]# sed '/^#/d;/^$/d' /etc/fdfs/client.conf
connect_timeout=30
network_timeout=60
base_path=/data/fastdfs
tracker_server=42.121.79.38:22122
log_level=info
http.tracker_server_port=8080

#上传测试

[root@bbs ~]# /usr/local/bin/fdfs_test /etc/fdfs/client.conf upload 1295091_212619002817_2.jpg
This is FastDFS client test program v4.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.
[2012-12-02 15:15:20] DEBUG - base_path=/data/fastdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key
length=0
tracker_query_storage_store_list_without_group:
server 1. group_name=group1, ip_addr=42.121.79.15, port=23000
group_name=group1, ip_addr=42.121.79.15, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/KnlPD1C7AAmAT5eDAAG2V4eHYDs315.jpg
source ip address: 42.121.79.15
file timestamp=2012-12-02 15:15:21
file size=112215
file crc32=2273796155
file url: http://42.121.79.38:8080/group1/M00/00/00/KnlPD1C7AAmAT5eDAAG2V4eHYDs315.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/KnlPD1C7AAmAT5eDAAG2V4eHYDs315_big.jpg
source ip address: 42.121.79.15
file timestamp=2012-12-02 15:15:22
file size=112215
file crc32=2273796155
file url: http://42.121.79.38:8080/group1/M00/00/00/KnlPD1C7AAmAT5eDAAG2V4eHYDs315_big.jpg

浏览上传图片:

One Comment

Add a Comment

电子邮件地址不会被公开。 必填项已用*标注