FastDFS安装部署文档

FastDFS安装部署文档

      

FastDFS简介

FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。非常适合用来存储用户图片、视频、文档等文件。对于互联网应用,和其他分布式文件系统相比,优势非常明显。FastDFS没有对文件做分块存储,因此不太适合分布式计算场景。

FastDFS服务端有两个角色:跟踪器(tracker)和存储节点storage)。跟踪器主要做调度工作,在访问上起负载均衡的作用。

存储节点存储文件,完成文件管理的所有功能:存储、同步和提供存取接口,FastDFS同时对文件的meta data进行管理。所谓文件的meta data就是文件的相关属性,以键值对(key value pair)方式表示,如:width=1024,其中的keywidthvalue1024。文件meta data是文件属性列表,可以包含多个键值对。

为了支持大容量,存储节点(服务器)采用了分卷(或分组)的组织方式。存储系统由一个或多个卷组成,卷与卷之间的文件是相互独立的,所有卷的文件容量累加就是整个存储系统中的文件容量。一个卷可以由一台或多台存储服务器组成,一个卷下的存储服务器中的文件都是相同的,卷中的多台存储服务器起到了冗余备份和负载均衡的作用。

在卷中增加服务器时,同步已有的文件由系统自动完成,同步完成后,系统自动将新增服务器切换到线上提供服务。

存储空间不足或即将耗尽时,可以动态添加卷。只需要增加一台或多台服务器,并将它们配置为一个新的卷,这样就扩大了存储系统的容量。

FastDFS中的文件标识分为两个部分:卷名和文件名,二者缺一不可。

二、FastDFS系统结构图



 

                              FastDFS系统结构图

上传文件交互过程:

      1. client询问tracker上传到的storage,不需要附加参数;

      2. tracker返回一台可用的storage

      3. client直接和storage通讯完成文件上传。

下载文件交互过程:

      1. client询问tracker下载文件的storage,参数为文件标识(卷名和文件名);

      2. tracker返回一台可用的storage

      3. client直接和storage通讯完成文件下载。

三、   FastDFS安装部署

准备环境

Ø 操作系统: CentOS 6.5  [Server-1& Server-2]

Ø  安装包:

1FastDFS_v5.05.tar.gz 下载地址:http://sourceforge.net/projects/fastdfs/files 依次打开“FastDFS Server Source Code->FastDFS Server with PHP Extension Source Code V5.05->FastDFS_v5.05.tar.gz”。

2libfastcommon-master.zip下载地址:

https://github.com/happyfish100/libfastcommon/archive/master.zip

2.      安装步骤

Ø  FastDFS_v5.05.tar.gzlibfastcommon-master.zip放到一个tools文件夹下,将文件夹上传到/opt/目录下面。[Server-1& Server-2]

Ø 关闭防火墙[Server-1& Server-2]

    service iptables stop

Ø安装libfastcommon,执行下列命令:[Server-1& Server-2]

 cd /opt/tools/

 unzip libfastcommon-master.zip

 cd libfastcommon-master

 ./make.sh

 ./make.sh install

Ø安装FastDFS,执行下列命令:[Server-1& Server-2]

 cd /opt/tools/

 tar -xzvf FastDFS_v5.05.tar.gz

 cd FastDFS

 vi make.sh

       TARGET_PREFIX=$DESTDIR/usr改成                                                        TARGET_PREFIX=$DESTDIR/usr/local

 ./make.sh

     ./make.sh install

Ødfs_trackerd服务配置[Server-1]

mkdir -p /home/fastdfs/tracker

cd /etc/fdfs/

cp tracker.conf.sample tracker.conf

    vi tracker.conf

                base_path=/home/yuqing/fastdfs改成                                    base_path=/home/fastdfs/tracker

Øfdfs_storaged服务配置[Server-2]

mkdir -p /home/fastdfs/storage

mkdir /home/fastdfs/data

cd /etc/fdfs/

cp storage.conf.sample storage.conf

    vi storage.conf

                 base_path=/home/yuqing/fastdfs改成                          base_path=/home/fastdfs/storage 

               store_path0=/home/yuqing/fastdfs改成                     

               store_path0=/home/fastdfs/data

             tracker_server=192.168.209.121:22122改成                         tracker_server=192.168.26.128:22122  

Øclient服务配置[Server-1]

mkdir -p /home/fastdfs/client

cd /etc/fdfs/

cp client.conf.sample client.conf

    vi client.conf

                                base_path=/home/yuqing/fastdfs改成      

                base_path=/home/fastdfs/client

             tracker_server=192.168.0.197:22122改成

                tracker_server=192.168.26.128:22122

3.      启动和关闭服务

 启动fdfs_trackerd服务:

     /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf

 停止fdfs_trackerd服务:

    sh /opt/tools/FastDFS/stop.sh /usr/local/bin/fdfs_trackerd

 启动fdfs_storaged服务:

     /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf

 停止fdfs_storaged服务:

     sh /opt/tools/FastDFS/stop.sh /usr/local/bin/fdfs_storaged

注:先启动fdfs_trackerd服务再启动fdfs_storaged服务。

       可以通过service fdfs_trackerd(storaged) start/stop/restart/status

   这种方式来管理服务了。如果不行就将安装包里面提供的/init.d   

   fdfs_trackerd(storaged) 拷贝到/etc/init.d里面再执行上面操作。

如:cp /opt/tools/FastDFS/init.d/fdfs_trackerd /etc/init.d/

    chkconfig --add fdfs_trackerd

    chkconfig fdfs_trackerd on (设置开机自启动)

4.    测试文件上传

手动上传文件szp.png[Server-1]/tmp目录下面;

fdfs_upload_file /etc/fdfs/client.conf /tmp/szp.png

上传成功后返回:group1/M00/00/00/wKgagFUWXQWAeygxAABWNEgjnSE328.png

可以到/home/fastdfs/data/data/00/00/目录下面查看文件是否存在。

5.    测试文件删除

fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/

wKgagFUWXQWAeygxAABWNEgjnSE328.png

可以到/home/fastdfs/data/data/00/00/目录下面查看文件是否存在。

6.    java客户端支持

     目前最新

         TrackerClient tracker = new TrackerClient();

  TrackerServer trackerServer = tracker.getConnection();

   StorageServer storageServer = null;

StorageClient client = new StorageClient(trackerServer, storageServer);

//上传

client.upload_file();

//下载

client.download_file();

//删除

client.download_file();

 

猜你喜欢

转载自see-you-again.iteye.com/blog/2287438