fastDFS搭建

1.1.1  FastDFS安装环境

   FastDFS是C语言开发,建议在linux上运行,本教程使用Centos6.5作为安装环境。

   安装FastDFS需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:yum install gcc-c++

1.1.2  安装libevent

FastDFS依赖libevent库,需要安装:

yum -y install libevent

1.1.3  安装libfastcommon

         libfastcommon是FastDFS官方提供的,libfastcommon包含了FastDFS运行所需要的一些基础库。

将libfastcommonV1.0.7.tar.gz拷贝至/usr/local/下

cd /usr/local

tar -zxvf libfastcommonV1.0.7.tar.gz

cd libfastcommon-1.0.7

./make.sh

./make.sh install

 

注意:libfastcommon安装好后会自动将库文件拷贝至/usr/lib64下,由于FastDFS程序引用usr/lib目录所以需要将/usr/lib64下的库文件拷贝至/usr/lib下。

要拷贝的文件如下:

132406_ni2C_3213673.png

1.1.4  tracker编译安装

将FastDFS_v5.05.tar.gz拷贝至/usr/local/下

tar -zxvf FastDFS_v5.05.tar.gz

 

cd FastDFS

 

./make.sh

./make.sh install

 

安装成功将安装目录下的conf下的文件拷贝到/etc/fdfs/下。

132425_GsTU_3213673.png

2.1.1  配置

安装成功后进入/etc/fdfs目录:

132442_bjzL_3213673.png

 

拷贝一份新的tracker配置文件:

cp tracker.conf.sample tracker.conf

 

修改tracker.conf

vi tracker.conf

base_path=/home/yuqing/FastDFS  

改为:

base_path=/home/FastDFS

配置http端口:

http.server_port=80

 

2.1.2  启动

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

启动的日志显示先停止5619进程(实际环境不是5619)再启动,如下图:

132508_yqBN_3213673.png

注意:如果没有显示上图要注意是否正常停止原有进程。

 

2.1    FastDFS--storage安装

分别在192.168.101.5、192.168.101.6、192.168.101.7、192.168.101.8上安装storage。

 

注:初次安装可只安装一台storage方便调试。安装步骤是一样的

 

3.1.1  配置

安装成功后进入/etc/fdfs目录:

132632_76uO_3213673.png

拷贝一份新的storage配置文件:

cp storage.conf.sample storage.conf

 

修改storage.conf

vi storage.conf

group_name=group1

base_path=/home/yuqing/FastDFS改为:base_path=/home/FastDFS

store_path0=/home/yuqing/FastDFS改为:store_path0=/home/FastDFS/fdfs_storage

#如果有多个挂载磁盘则定义多个store_path,如下

#store_path1=.....

#store_path2=......
tracker_server=192.168.101.3:22122   #配置tracker服务器:IP

#如果有多个则配置多个tracker

tracker_server=192.168.101.4:22122

 

#配置http端口

http.server_port=80

 

3.1.2  启动

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

启动的日志显示先停止8931进程(实际环境不是8931)再启动,如下图:

132702_S6dL_3213673.png

注意:如果没有显示上图要注意是否正常停止原有进程。

 

4.1    上传图片测试

4.1.1  通过fdfs_test程序

astDFS安装成功可通过/usr/bin/fdfs_test测试上传、下载等操作。

 

修改/etc/fdfs/client.conf

 

base_path=/home/fastdfs

tracker_server=192.168.101.3:22122

tracker_server=192.168.101.4:22122

 

使用格式:

/usr/bin/fdfs_test 客户端配置文件地址  upload  上传文件

 

比如将/home下的图片上传到FastDFS中:

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/tomcat.png

 

打印如下日志:

This is FastDFS client test program v5.05

 

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.

 

[2015-05-18 02:07:10] DEBUG - base_path=/home/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.101.5, port=23000

         server 2. group_name=, ip_addr=192.168.101.6, port=23000

 

group_name=group1, ip_addr=192.168.101.5, port=23000

storage_upload_by_filename

group_name=group1, remote_filename=M00/00/00/wKhlBVVY2M-AM_9DAAAT7-0xdqM485.png

source ip address: 192.168.101.5

file timestamp=2015-05-18 02:07:11

file size=5103

file crc32=3979441827

example file url: http://192.168.101.5/group1/M00/00/00/wKhlBVVY2M-AM_9DAAAT7-0xdqM485.png

storage_upload_slave_by_filename

group_name=group1, remote_filename=M00/00/00/wKhlBVVY2M-AM_9DAAAT7-0xdqM485_big.png

source ip address: 192.168.101.5

file timestamp=2015-05-18 02:07:11

file size=5103

file crc32=3979441827

example file url: http://192.168.101.5/group1/M00/00/00/wKhlBVVY2M-AM_9DAAAT7-0xdqM485_big.png

 

 

http://192.168.101.5/group1/M00/00/00/wKhlBVVY2M-AM_9DAAAT7-0xdqM485_big.png就是文件的下载路径。

对应storage服务器上的

/home/fastdfs/fdfs_storage/data/00/00/wKhlBVVY2M-AM_9DAAAT7-0xdqM485_big.png文件。

 

由于现在还没有和nginx整合无法使用http下载。

 

4.1.2  通过java Client API

完整的测试方法参考测试源代码。

public class FastdfsClientTest {

   

    //客户端配置文件

    public String conf_filename = "F:\\workspace_indigo\\fastdfsClient\\src\\cn\\itcast\\fastdfs\\cliennt\\fdfs_client.conf";

    //本地文件,要上传的文件

    public String local_filename = "F:\\develop\\upload\\linshiyaopinxinxi_20140423193847.xlsx";

 

//上传文件

    @Test

    public void testUpload() {

       

        for(int i=0;i<100;i++){

 

        try {

            ClientGlobal.init(conf_filename);

 

            TrackerClient tracker = new TrackerClient();

            TrackerServer trackerServer = tracker.getConnection();

            StorageServer storageServer = null;

 

            StorageClient storageClient = new StorageClient(trackerServer,

                    storageServer);

            NameValuePair nvp [] = new NameValuePair[]{

                    new NameValuePair("item_id", "100010"),

                    new NameValuePair("width", "80"),

                    new NameValuePair("height", "90")

            };

            String fileIds[] = storageClient.upload_file(local_filename, null,

                    nvp);

 

            System.out.println(fileIds.length);

            System.out.println("组名:" + fileIds[0]);

            System.out.println("路径: " + fileIds[1]);

 

        } catch (FileNotFoundException e) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();

        } catch (Exception e) {

           e.printStackTrace();

       }

        }

    }

 

}

 

 

转载于:https://my.oschina.net/u/3213673/blog/1577843

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值