Total Pageviews

Sunday 14 October 2012

FastDFS分布式文件系统的安装及配置


分布式文件系统(Distributed File System)是指文件系统管理的物理存储资源不一定直接连接在本地节点上,而是通过计算机网络与节点相连。分布式文件系统的设计基于客户机/服务器模式。一个典型的网络可能包括多个供多用户访问的服务器。另外,对等特性允许一些系统扮演客户机和服务器的双重角色。
FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务,如相册网站、视频网站等等。
一:安装FastDFS
1、首先安装libevent。
wget http://monkey.org/~provos/libevent-2.0.11-stable.tar.gz
tar -zxvf libevent-2.0.11-stable.tar.gz
cd libevent-2.0.11-stable
./configure --prefix=/usr
make clean
make
make install
2、安装FastDFS的步骤
wget http://fastdfs.googlecode.com/files/FastDFS_v3.03.tar.gz
tar -zxvf FastDFS_v3.03.tar.gz
cd FastDFS
vim make.sh 将#WITH_HTTPD=1 修改成WITH_HTTPD=1 以支持 http
./make.sh
./make.sh install

二:FastDFS的配置
1、配置及启动Tracker Server
mkdir /home/fastdfs
vi /etc/fdfs/tracker.conf
base_path=/home/yuqing/fastdfs -> base_path=/home/fastdfs
http.server_port=8080 -> http.server_port=9090
##include http.conf -> #include http.conf
reserved_storage_space = 4GB -> reserved_storage_space = 1GB
cd /usr/local/bin
fdfs_trackerd /etc/fdfs/tracker.conf

检查tracker是否启动成功,可以查看如下文件/home/fastdfs/logs/trackerd.log

    [2011-10-21 14:29:44] INFO - FastDFS v3.03, base_path=/home/fastdfs, run_by_group=, run_by_user=, connect_timeout=30s, network_timeout=60s, port=22122, bind_addr=, max_connections=256, work_threads=4, store_lookup=2, store_group=, store_server=0, store_path=0, reserved_storage_space=1024MB, download_server=0, allow_ip_count=-1, sync_log_buff_interval=10s, check_active_interval=120s, thread_stack_size=64 KB, storage_ip_changed_auto_adjust=1, storage_sync_file_max_delay=86400s, storage_sync_file_max_time=300s, use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64 MB
    [2011-10-21 14:29:44] INFO - HTTP supported: server_port=9090, default_content_type=application/octet-stream, anti_steal_token=0, token_ttl=0s, anti_steal_secret_key length=0, token_check_fail content_type=, token_check_fail buff length=0, check_active_interval=30, check_active_type=tcp, check_active_uri=/status.html

2、配置及启动Storage Server
mkdir /home/fastdfs/fdfs_storage
cd /etc/fdfs
vi storage.conf
base_path=/home/yuqing/fastdfs -> /home/fastdfs/fdfs_storage
store_path0=/home/yuqing/fastdfs -> store_path0=/home/fastdfs/fdfs_storage
group_name=group1
tracker_server=192.168.209.121:22122 -> tracker_server=173.252.200.228:22122
##include http.conf ->#include http.conf
接下来会出现很多mkdir data path,这是系统在创建数据目录。

    [2011-10-21 14:49:20] INFO - FastDFS v3.03, base_path=/home/fastdfs/fdfs_storage, store_path_count=1, subdir_count_per_path=256, group_name=group1, run_by_group=, run_by_user=, connect_timeout=30s, network_timeout=60s, port=23000, bind_addr=, client_bind=1, max_connections=256, work_threads=4, disk_rw_separated=1, disk_reader_threads=1, disk_writer_threads=1, disk_rw_direct=0, buff_size=256KB, heart_beat_interval=30s, stat_report_interval=60s, tracker_server_count=1, sync_wait_msec=50ms, sync_interval=0ms, sync_start_time=00:00, sync_end_time=23:59, write_mark_file_freq=500, allow_ip_count=-1, file_distribute_path_mode=0, file_distribute_rotate_count=100, fsync_after_written_bytes=0, sync_log_buff_interval=10s, sync_binlog_buff_interval=10s, sync_stat_file_interval=300s, thread_stack_size=512 KB, upload_priority=10, if_alias_prefix=, check_file_duplicate=0, FDHT group count=0, FDHT server count=0, FDHT key_namespace=, FDHT keep_alive=0, HTTP server port=8888, domain name=
    [2011-10-21 14:49:20] INFO - HTTP supported: server_port=8888, http_trunk_size=262144, default_content_type=application/octet-stream, anti_steal_token=0, token_ttl=0s, anti_steal_secret_key length=0, token_check_fail content_type=, token_check_fail buff length=0
    [2011-10-21 14:49:42] INFO - file: storage_param_getter.c, line: 97, storage_ip_changed_auto_adjust=1, store_path=0, reserved_storage_space=1024 MB, use_trunk_file=0, slot_min_size=0, slot_max_size=16 MB, trunk_file_size=64 MB
    [2011-10-21 14:49:44] INFO - file: tracker_client_thread.c, line: 304, successfully connect to tracker server 173.252.200.228:22122, as a tracker client, my ip is 173.252.200.228
    [2011-10-21 14:50:14] INFO - file: tracker_client_thread.c, line: 1100, tracker server 173.252.200.228:22122, set tracker leader: 173.252.200.228:22122

三:测试及使用FastDFS
1、FastDFS之配置client
vi /etc/fdfs/client.conf
base_path=/home/yuqing/fastdfs-> base_path=/home/fastdfs
tracker_server=192.168.209.121:22122 -> tracker_server=173.252.200.228:22122
http.tracker_server_port=8080 ->http.tracker_server_port=9090
##include http.conf ->#include http.conf
2、测试上传文件
cd ~
fdfs_test /etc/fdfs/client.conf upload FastDFS_v3.03.tar.gz
执行成功后会出现如下提示:

    This is FastDFS client test program v3.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.

    [2011-10-21 15:14:59] INFO - base_path=/home/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=173.252.200.228, port=23000

    group_name=group1, ip_addr=173.252.200.228, port=23000
    storage_upload_by_filename
    group_name=group1, remote_filename=M00/00/00/rfzI5E6hG_O5wNKxAAVAc72y1Jc.tar.gz
    source ip address: 173.252.200.228
    file timestamp=2011-10-21 15:14:59
    file size=344179
    file crc32=3182613655
    file url: http://173.252.200.228:9090/group1/M00/00/00/rfzI5E6hG_O5wNKxAAVAc72y1Jc.tar.gz
    storage_upload_slave_by_filename
    group_name=group1, remote_filename=M00/00/00/rfzI5E6hG_O5wNKxAAVAc72y1Jc_big.tar.gz
    source ip address: 173.252.200.228
    file timestamp=2011-10-21 15:14:59
    file size=344179
    file crc32=3182613655
    file url: http://173.252.200.228:9090/group1/M00/00/00/rfzI5E6hG_O5wNKxAAVAc72y1Jc_big.tar.gz

3、测试下载文件
在浏览器中,输入上图中的url地址, tracker server会自动重定向到存储文件的storage server,文件下载成功。至此,已经成功搭建了FastDFS,编写你自己的client来进行访问吧。
----------------------------------
 FastDFS-分布式文件系统的安装及配置

FastDFS是一个开源的分布式文件系统,它对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务,如相册网站、视频网站等等。
FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage)。跟踪器主要做调度工作,在访问上起负载均衡的作用。
存储节点存储文件,完成文件管理的所有功能:存储、同步和提供存取接口,FastDFS同时对文件的meta data进行管理。所谓文件的meta data就是文件的相关属性,以键值对(key value pair)方式表示,如:width=1024,其中的key为width,value为1024。文件meta data是文件属性列表,可以包含多个键值对。

跟踪器和存储节点都可以由一台多台服务器构成。跟踪器和存储节点中的服务器均可以随时增加或下线而不会影响线上服务。其中跟踪器中的所有服务器都是对等的,可以根据服务器的压力情况随时增加或减少。
为了支持大容量,存储节点(服务器)采用了分卷(或分组)的组织方式。存储系统由一个或多个卷组成,卷与卷之间的文件是相互独立的,所有卷 的文件容量累加就是整个存储系统中的文件容量。一个卷可以由一台或多台存储服务器组成,一个卷下的存储服务器中的文件都是相同的,卷中的多台存储服务器起 到了冗余备份和负载均衡的作用。
在卷中增加服务器时,同步已有的文件由系统自动完成,同步完成后,系统自动将新增服务器切换到线上提供服务。
当存储空间不足或即将耗尽时,可以动态添加卷。只需要增加一台或多台服务器,并将它们配置为一个新的卷,这样就扩大了存储系统的容量。
FastDFS中的文件标识分为两个部分:卷名和文件名,二者缺一不可。

上传文件交互过程:
1. client询问tracker上传到的storage,不需要附加参数;
2. tracker返回一台可用的storage;
3. client直接和storage通讯完成文件上传。

下载文件交互过程:
1. client询问tracker下载文件的storage,参数为文件标识(卷名和文件名);
2. tracker返回一台可用的storage;
3. client直接和storage通讯完成文件下载。
需要说明的是,client为使用FastDFS服务的调用方,client也应该是一台服务器,它对tracker和storage的调用均为服务器间的调用。
一:安装FastDFS
1、首先安装libevent。
1
2
3
4
5
6
7
wget http://monkey.org/~provos/libevent-2.0.11-stable.tar.gz
tar -zxvf libevent-2.0.11-stable.tar.gz
cd libevent-2.0.11-stable
./configure --prefix=/usr
make clean
make
make install
2、安装FastDFS的步骤
1
2
3
4
5
6
wget http://fastdfs.googlecode.com/files/FastDFS_v3.03.tar.gz
tar -zxvf FastDFS_v3.03.tar.gz
cd FastDFS
vim make.sh 将#WITH_HTTPD=1 修改成WITH_HTTPD=1 以支持 http
./make.sh
./make.sh install
二:FastDFS的配置
1、配置及启动Tracker Server
1
2
3
4
5
6
mkdir /var/www/fastdfs
vi /etc/fdfs/tracker.conf
base_path=/home/yuqing/fastdfs -> base_path=/var/www/fastdfs
http.server_port=8080 -> http.server_port=9090
##include http.conf -> #include http.conf
reserved_storage_space = 4GB -> reserved_storage_space = 1GB
1
2
cd /usr/local/bin
fdfs_trackerd /etc/fdfs/tracker.conf
检查tracker是否启动成功,可以查看如下文件/var/www/fastdfs/logs/trackerd.log
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[2011-10-21 14:29:44] INFO – FastDFS v3.03, base_path=/home/fastdfs,
run_by_group=, run_by_user=, connect_timeout=30s, network_timeout=60s,
port=22122, bind_addr=, max_connections=256, work_threads=4, store_lookup=2,
store_group=, store_server=0, store_path=0, reserved_storage_space=1024MB,
download_server=0, allow_ip_count=-1, sync_log_buff_interval=10s,
check_active_interval=120s, thread_stack_size=64 KB,
storage_ip_changed_auto_adjust=1, storage_sync_file_max_delay=86400s,
storage_sync_file_max_time=300s, use_trunk_file=0, slot_min_size=256,
slot_max_size=16 MB, trunk_file_size=64 MB
[2011-10-21 14:29:44] INFO – HTTP supported: server_port=9090,
default_content_type=application/octet-stream, anti_steal_token=0,
token_ttl=0s, anti_steal_secret_key length=0, token_check_fail
content_type=, token_check_fail buff length=0, check_active_interval=30,
check_active_type=tcp, check_active_uri=/status.html
2、配置及启动Storage Server
1
2
3
4
5
6
7
8
mkdir /var/www/fastdfs/fdfs_storage
cd /etc/fdfs
vi storage.conf
base_path=/home/yuqing/fastdfs -> /var/www/fastdfs/fdfs_storage
store_path0=/home/yuqing/fastdfs -> store_path0=/var/www/fastdfs/fdfs_storage
group_name=group2
tracker_server=192.168.209.121:22122 -> tracker_server=10.0.2.15:22122
##include http.conf ->#include http.conf
1
2
cd /usr/local/bin
fdfs_storaged /etc/fdfs/storage.conf
接下来会出现很多mkdir data path,这是系统在创建数据目录。
三:测试及使用FastDFS
1、FastDFS之配置client
1
2
3
4
5
vi /etc/fdfs/client.conf
base_path=/home/yuqing/fastdfs-> base_path=/var/www/fastdfs
tracker_server=192.168.209.121:22122 -> tracker_server=10.0.2.15:22122
http.tracker_server_port=8080 ->http.tracker_server_port=9090
##include http.conf ->#include http.conf
2、测试上传文件
1
2
3
cd /usr/local/bin
touch aa.php
fdfs_test /etc/fdfs/client.conf upload aa.php
执行成功后会出现如下提示:
3、测试下载文件
在浏览器中,输入上图中的url地址, tracker server会自动重定向到存储文件的storage server,文件下载成功。至此,已经成功搭建了FastDFS,编写你自己的client来进行访问吧:
1
http://10.0.2.15:9090/group1/M00/00/00/CgACD0-NYt_VkxRqAAAAEIG-AGI255_big.php
4、常规命令
1
2
3
4
5
6
#重启tracker
fdfs_trackerd /etc/fdfs/tracker.conf
#重启storaged
fdfs_storaged /etc/fdfs/storage.conf
#监控dfs
fdfs_monitor /etc/fdfs/storage.conf
四:PHP扩展
1.安装PHP扩展
1
2
3
4
5
cd php_client
apt-get install php5-dev
phpize
./configure
make && make install
2.配置PHP扩展
1
2
3
4
5
vi  fastdfs_client.ini
extension = fastdfs_client.so
fastdfs_client.tracker_group_count = 2
fastdfs_client.tracker_group0 = /etc/fdfs/client.conf
fastdfs_client.tracker_group1 = /etc/fdfs/client.conf
3.测试
1
php fastdfs_test.php
4.PHP用例test.php
1
2
3
4
5
6
7
8
9
10
< ?php
//所上传的文件
$filename = "aa.php";
//调用FastDFS类
$fdfs = new FastDFS();
//上传文件 $filename 是所上传的文件,html是上传后的更名后缀名为.html
$file_info = $fdfs->storage_upload_by_filename($filename,html);
//输出上传文件目录和文件名
echo $file_info['filename'];
?>
五:centos下安装PHP扩展
1.安装PHP扩展
1
2
3
4
cd php_client
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-fastdfs_client
make && make install
2.配置PHP扩展
1
2
3
4
5
6
7
8
9
10
11
vi  php.ini
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
extension = fastdfs_client.so
fastdfs_client.base_path = /var/www/fastdfs
fastdfs_client.connect_timeout = 2
fastdfs_client.network_timeout = 60
fastdfs_client.log_level = info
fastdfs_client.log_filename =
fastdfs_client.http.anti_steal_secret_key =
fastdfs_client.tracker_group_count = 1
fastdfs_client.tracker_group0 = /etc/fdfs/client.conf

-----------------------------------------------
最近在研究负载均衡和集群,其中涉及到一个主要问题是,
如何让集群中的real server共享一套文件系统。
在网上查到FastDFS,国人(happy fish,感谢他的开源精神)开发的一套轻量级分布式文件系统。
实际搭建了一下,感觉还不错,小巧易用,支持http下载。
虽然FastDFS官方网站 上已经有比较详细的按照使用手册,
但在实际搭建过程中,还是遇到了很多问题,
希望我的记录可以让后来的同学们少走一些弯路:)
下面进入正题.

FastDFS安装使用实战(安装篇)

Keywords:FastDFS、分布式文件系统、Ubuntu
Author:soartju
转载请注明出处:http://soartju.iteye.com/blog/803477

目前FastDFS支持类Unix系统 ,在Linux和FreeBSD下测试过,
本文使用的是Ubuntu10.4,建议安装之前先简单了解一下FastDFS的原理
这对后继的配置部分会有很好的理解。

一、准备工作-安装libevent

FastDFS 内部绑定了 libevent 作为 http 服务器 ,在V2.X版本必须安装 libevent ,
本文安装的是V2.2版本,因此必须安装libevent。(官方也推荐使用 http 方式下载 文件

如果已经安装了 libevent,请确认安装路径是 /usr , 因为 FastDFS 在编译源程序时,
需要到此目录下查找一些依赖文件,否则编译 FastDFS 会出错 。
如果不是,建议首先卸载 libevent ,然后安装到 /usr 下。
Ubuntu10.4默认是安装了libevent,可以到软件中心卸载掉然后按照下面介绍的方式安装。

本文安装的是 libevent1.4.14b-stable ,下载地址:
http://monkey.org/~provos/libevent/

安装步骤:
解压 libevent ,然后进入解压后的目录分别执行:
Shell代码  收藏代码
  1. ./configure --prefix=/usr  
  2. make clean;  
  3. make  
  4. make install  
 安装libevent完成。

二、安装 FastDFS

1、下载 FastDFS 源程序,下载地址 http://code.google.com/p/fastdfs/downloads/list
这里下载的是 FastDFS_v2.02.tar.gz (建议安装V2.02版本,比V1.X版本更加稳定且性能提升明显)

2、在 FastDFS_v2.02.tar.gz 所在文件夹下执行:
Shell代码  收藏代码
  1. sudo tar vxzf FastDFS_v2.02.tar.gz /home/soar/FastDFS  
     注: /home/soar/FastDFS 也可以是其他目录,记住这是解压目录,
以后用 %FastDFS% 表示)

3、由于要使用内置的 http 服务,因此编辑 %FastDFS%/make.sh 文件,找到
#WITH_HTTPD=1
修改成
WITH_HTTPD=1
以支持 http

4、进入 %FastDFS% 目录,执行:
Shell代码  收藏代码
  1. sudo ./make.sh  
  5、在 %FastDFS% 目录下,执行:
Shell代码  收藏代码
  1. sudo ./make.sh install  

如果运行如上命令后,在命令行信息最后看到类似
Shell代码  收藏代码
  1. #ln -fs /usr/local/lib/libfastcommon.so.1 /usr/local/lib/libfastcommon.so  
  2. #ln -fs /usr/local/lib/libfdfsclient.so.1 /usr/local/lib/libfdfsclient.so  
  3. sh ./fdfs_link_library.sh  
  恭喜你,已经安装成功了!

FastDFS安装使用实战二(配置篇)

Keywords:FastDFS、分布式文件系统、Ubuntu
Author:soartju
转载请注明出处:http://soartju.iteye.com/blog/803524


FastDFS的配置文件在%FastDFS%/conf目录下,其中包括
Client.conf    客户端上传配置文件
Storage.conf    文件存储服务器配置文件
Tracker.conf    负责均衡调度服务器配置文件
http.conf        http服务器配置文件

配置文件需要根据服务器环境的不同,进行不同的配置,
具体可以参考FastDFS官方的安装配置文档
http://code.google.com/p /fastdfs/wiki/Setup,
以及FastDFS原理介绍文档http://code.google.com/p/fastdfs/wiki /Overview

在本例中,Tracker Server,Storage Server都安装在一台服务器上,IP:10.0.2.15

1、配置及启动Tracker Server

A、修改%FastDFS%/conf/tracker.conf文件,修改如下
#可以自己指定目录位置,但目录必须存在,用于存储日志及storage server等信息,
否则tracker server无法启动.
Txt代码  收藏代码
  1. base_path=/home/yuqing/fastdfs -> base_path=/home/soar/fastdfs_tracker   
 #改成你想要的http端口,将来http下载文件的端口就是他了
Txt代码  收藏代码
  1. http.server_port=8080 -> http.server_port=8090   
 #http支持
Txt代码  收藏代码
  1. ##include http.conf -> #include http.conf   
 #默认4GB,如果空间不足,建议调小,否则会报no free space的异常,无法正常启动
Txt代码  收藏代码
  1. reserved_storage_space = 4GB -> reserved_storage_space = 1GB    
 #tracker server对storage server供服务的端口,使用默认的即可,也可以自定义
Txt代码  收藏代码
  1. port=22122  
  B、将http.conf文件拷贝到/etc/fdfs目录下,执行
Shell代码  收藏代码
  1. sudo cp %FastDFS%/conf/http.conf /etc/fdfs/  
 注:为了支持http,必须将这个文件拷贝到此目录,否则无法启动,
报param http.XXX not exist or is empty类似的错误

C、进入/usr/local/bin/目录,启动tracker服务器,执行
Shell代码  收藏代码
  1. sudo fdfs_trackerd %FastDFS%/conf/tracker.conf  

D、进入/home/soar/fastdfs_tracker/logs/trackerd.log查看tracker的启动日志,如果看到类似
Shell代码  收藏代码
  1. [2010-11-04 16:21:25] INFO - FastDFS v2.02, base_path=/home/soar/fastdfs_tracker, connect_timeout=30s, network_timeout=60s, port=22122, bind_addr=, max_connections=256, work_threads=4, store_lookup=2, store_group=, store_server=0, store_path=0, reserved_storage_space=4MB, download_server=0, allow_ip_count=-1, sync_log_buff_interval=10s, check_active_interval=120s, thread_stack_size=64 KB, storage_ip_changed_auto_adjust=1, storage_sync_file_max_delay=86400s, storage_sync_file_max_time=300s  
  2. [2010-11-04 16:21:25] INFO - HTTP supported: server_port=8090, default_content_type=application/octet-stream, anti_steal_token=0, token_ttl=0s, anti_steal_secret_key length=0, token_check_fail content_type=, token_check_fail buff length=0, check_active_interval=30, check_active_type=tcp, check_active_uri=/status.html  

恭喜你,tracker server已经启动成功!

2、配置及启动Storage Server

A、修改%FastDFS%/conf/storage.conf文件,修改如下:
#可以自定义,但必须存在此目录,用于存储storage相关的log、group内的相关信息
Txt代码  收藏代码
  1. base_path=/home/yuqing/fastdfs -> /home/soar/fastdfs_storge  
#文件的存储位置,在一台storage server上可以指定多个存储位置
Txt代码  收藏代码
  1. store_path0=/home/yuqing/fastdfs -> store_path0=/home/soar/fastdfs_storge   
 #必须指定
Txt代码  收藏代码
  1. group_name=group1   
 #修改成tracker server的IP和端口信息
Txt代码  收藏代码
  1. tracker_server=192.168.209.121:22122 -> tracker_server=10.0.2.15:22122  
 #http支持
Txt代码  收藏代码
  1. ##include http.conf ->#include http.conf   
  B、进入/usr/local/bin/目录,启动storage服务器,执行
Shell代码  
  1. sudo fdfs_storaged %FastDFS%/conf/storage.conf  
  C、进入/home/soar/fastdfs_tracker/logs/storage.log查看storage服务器启动日志,
如果看到类似
Shell代码  
  1. [2010-11-04 16:37:16] INFO - FastDFS v2.02, base_path=/home/soar/fastdfs_storge, store_path_count=1, subdir_count_per_path=256, group_name=group1, connect_timeout=30s, network_timeout=60s, port=23000, bind_addr=, client_bind=1, max_connections=256, work_threads=4, disk_rw_separated=1, disk_reader_threads=1, disk_writer_threads=1, buff_size=256KB, heart_beat_interval=30s, stat_report_interval=60s, tracker_server_count=1, sync_wait_msec=200ms, sync_interval=0ms, sync_start_time=00:00, sync_end_time=23:59, write_mark_file_freq=500, allow_ip_count=-1, file_distribute_path_mode=0, file_distribute_rotate_count=100, fsync_after_written_bytes=0, sync_log_buff_interval=10s, sync_binlog_buff_interval=60s, sync_stat_file_interval=300s, thread_stack_size=512 KB, upload_priority=10, if_alias_prefix=, check_file_duplicate=0, FDHT group count=0, FDHT server count=0, FDHT key_namespace=, FDHT keep_alive=0, HTTP server port=8888, domain name=  
  2. [2010-11-04 16:37:16] INFO - HTTP supported: server_port=8888, http_trunk_size=262144, default_content_type=application/octet-stream, anti_steal_token=0, token_ttl=0s, anti_steal_secret_key length=0, token_check_fail content_type=, token_check_fail buff length=0  
  3. [2010-11-04 16:37:16] INFO - file: storage_param_getter.c, line: 48, storage_ip_changed_auto_adjust=1  
  4. [2010-11-04 16:37:19] INFO - file: tracker_client_thread.c, line: 274, successfully connect to tracker server 10.0.2.15:22122, as a tracker client, my ip is 10.0.2.15  
  恭喜你,storage server已经启动成功!

FastDFS安装使用实战三(使用篇)

Keywords:FastDFS、分布式文件系统、Ubuntu
Author:soartju
转载请注明出处:http://soartju.iteye.com/blog/803548


经过前面的安装、配置、启动,马上就可以看到FastDFS的效果了,
我们先上传一个文件,然后再通过http下载。

一、上传文件

FastDFS安装包中,自带了客户端程序,通过程序可以进行文件上传。
]在使用这个客户端程序之前,首先需要配置client.conf,然后再进行文件上传及下载。

1、修改%FastDFS%/conf/client.conf文件,修改如下:
#可自定义,但此目录必须存在,用于存放文件上传log
Txt代码  收藏代码
  1. base_path=/home/yuqing/fastdfs-> base_path=/home/soar/fastdfs_tracker  
Txt代码  收藏代码
  1. tracker_server=192.168.209.121:22122 -> tracker_server=10.0.2.15:22122  
Txt代码  收藏代码
  1. http.tracker_server_port=8080 ->http.tracker_server_port=8090  
 #支持http
Txt代码  收藏代码
  1. ##include http.conf ->#include http.conf   
  2、进入/usr/local/bin/目录,上传文件,执行
Txt代码  收藏代码
  1. sudo fdfs_test %FastDFS%/conf/client.conf upload a.txt   
注:a.txt可以在/usr/local/bin/目录下自己创建一个

如果命令行反馈类似如下:

则说明上传文件成功。

二、下载文件

在浏览器中,输入上图中的url地址, tracker server会自动重定向到存储文件的storage server,文件下载成功。
至此,已经成功搭建了FastDFS,编写你自己的client来进行访问吧:)
----------------------------

Ubuntu下部署FastDFS 5.05

  很早前得知这样一个开源分布式的文件存储方案,一直没有正式的使用过,正好这次相册升级可以试试了,
起初以为fastdfs也是通过block来优化小文件存储的,实际上也是文件形式管理,可以预见大量的小文件还是会有问题,
可能更好的解决方案是淘宝TFS。不过fastdfs已远远满足我的需求了。而且及其轻量,这货在google code上早已停止更新,
最新的版本可以在这里获取,目前下载的最新版本是5.05,更新于2014-12-02。在这里可以找到更多的说明。
  下载好后,server端分为两个部分,一个是tracker,一个是storage。顾名思义,前者调度管理,负载均衡,
后者则是实际的存储节点。两个都能做成集群,以防止单点故障。以前的4.x版本依赖libevent,现在不需要了,
只需要libfastcommon。安装方法如下:
1. 下载安装libfastcommon
git clone https://github.com/happyfish100/libfastcommon.git
cd libfastcommon/
./make.sh
./make.sh install
确认make没有错误后,执行安装,64位系统默认会复制到/usr/lib64下。
这时候需要设置环境变量或者创建软链接
export LD_LIBRARY_PATH=/usr/lib64/
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
2. 下载安装fastdfs
tar xzf FastDFS.tar.gz
cd FastDFS/
./make.sh
./make.sh install
确认make没有错误后,执行安装,默认会安装到/usr/bin中,并在/etc/fdfs中添加三个配置文件。
3. 修改配置文件
首先将三个文件的名字去掉sample,暂时只修改以下几点,先让fastdfs跑起来,其余参数调优的时候再考虑。
tracker.conf 中修改
base_path=/usr/fastdfs #用于存放日志。
storage.conf 中修改
base_path=/usr/fastdfs-storaged #用于存放日志。
store_path0=/usr/fastdfs0 #存放数据,若不设置默认为前面那个。
tracker_server=192.168.29.132:22122 #指定tracker服务器地址。
client.conf 中同样要修改
base_path=/usr/fastdfs #用于存放日志。
tracker_server=192.168.29.132:22122 #指定tracker服务器地址。
4. 启动tracker和storage
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
5. 检查进程
root@ubuntu:~# ps -ef |grep fdfs
root       7819      1  0 15:24 ?        00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root       8046      1  0 15:36 ?        00:00:01 fdfs_storaged /etc/fdfs/storage.conf start
表示启动ok了,若有错误,可以在/usr/fastdfs目录下检查日志。
6. 上传/删除测试
使用自带的fdfs_test来测试,使用格式如下:
root@ubuntu:~# fdfs_test /etc/fdfs/client.conf upload /home/steven/01.jpg
...
group_name=group1, ip_addr=192.168.29.132, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgdhFTV0ZmAP3AZAPk-Io7D4w8580.jpg
...
example file url: http://192.168.29.132/group1/M00/00/00/wKgdhFTV0ZmAP3AZAPk-Io7D4w8580.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgdhFTV0ZmAP3AZAPk-Io7D4w8580_big.jpg
...
example file url: http://192.168.29.132/group1/M00/00/00/wKgdhFTV0ZmAP3AZAPk-Io7D4w8580_big.jpg
使用fdfs_delete_file来删除文件,格式如下:
fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgdhFTV11uAXgKWAPk-Io7D4w8667.jpg
可以看到,上传ok了,这里会生成两个文件,这是fastdfs的主/从文件特性,以后再介绍。example file url是不能在浏览器中直接打开的,
除非配合nginx使用,这里我不需要了。删除文件需要完整的group_name和remote_filename。