IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]fastdfs 新添加一个项目的图片目录 实现独立的上传下载功能

    mchdba发表于 2016-06-18 13:33:57
    love 0

     

    1,功能需求

    Fastdfs已经安装完成,部署过程见:http://blog.csdn.net/mchdba/article/details/50933405,fastdfs安装启动后,默认只有一个group1,只能适合用于一个项目;那么如果有新项目过来了,是否需要再准备新的linux服务器重新安装一套fastdfs呢?答案是否定的

     

    这里已经实现了group1/group2/group3,现在有新的项目过来,不想重新搭建安装fastdfs环境,想直接在这上面再添加一个项目图片目录group4,存储位置要分开,实现正常上传下载访问功能。我们可以在原来的fastdfs上新添加一个group4来实现这个新的项目的图片目录的功能,这省了服务器资源也节省了部署时间。

     

    操作思路是:在mod_fastdfs.conf上添加新的group组,然后准备新的storage_group4.conf文件,再启动一个fdfs_storaged进程。

     

    2,配置mod_fastdfs.conf文件

     

    # 创建新的group文件夹

    mkdir /file/fastdfs_group4

    chown –R

     

    vim /etc/fdfs/mod_fastdfs.conf

    # runing for haisheng,在这里添加一个新的group                      

    [group4]

    group_name=group4

    storage_server_port=23004

    store_path_count=1

    store_path0=/file/fastdfs_group4

     

    3,在nginx配置group4

            # for wenhaisheng on 20160617                                               

            location /group4/M00 {

                root   /file/fastdfs_group4/data;

                include gzip.conf;

                ngx_fastdfs_module;

                client_max_body_size 100m;

                expires 12h;

            }

     

     

     

    4,启动新的fastdfs服务

    启动命令比较方便,加上新的group4配置文件即可:

    # 开始启动

    [root@test_dev_fastdfs_32 ~]# /usr/local/bin/fdfs_storaged /etc/fdfs/storage_group4.conf

    [root@test_dev_fastdfs_32 ~]#

     

    # 查看fdfs进程,已经有了group4的storaged进程

    [root@test_dev_fastdfs_32 ~]# ps -eaf|grep fastdfs |grep conf

    fastdfs   3023     1  0 Jun17 ?        00:00:05 /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf

    fastdfs  10851     1  0 Jun08 ?        00:00:42 /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf

    fastdfs  10867     1  0 Jun08 ?        00:00:37 /usr/local/bin/fdfs_storaged /etc/fdfs/storage_group2.conf      

    fastdfs  10891     1  0 Jun08 ?        00:00:36 /usr/local/bin/fdfs_storaged /etc/fdfs/storage_group3.conf

    fastdfs  31820     1  0 Jun17 ?        00:00:03 /usr/local/bin/fdfs_storaged /etc/fdfs/storage_group4.conf         

    [root@test_dev_fastdfs_32 ~]#

     

     

    5,测试功能

    使用fdfs_test命令上传文件:

    [fastdfs@test_dev_fastdfs_32 fdfs]$ /usr/local/bin/fdfs_test /etc/fdfs/client.conf upload /tmp/xg.png

    This is FastDFS client test program v4.06

     

    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.

     

    [2016-06-17 16:03:53] DEBUG - base_path=/file/fastdfs_group4, 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.121.32, port=23001

     

    group_name=group1, ip_addr=192.168.121.32, port=23001

    storage_upload_by_filename

    group_name=group1, remote_filename=M00/00/23/wKh5IFdjrumAc879AASrW0_jx78607.png

    source ip address: 192.168.121.32

    file timestamp=2016-06-17 16:03:53

    file size=306011

    file crc32=1340327871

    file url: http://192.168.121.32/group1/M00/00/23/wKh5IFdjrumAc879AASrW0_jx78607.png

    storage_upload_slave_by_filename

    group_name=group4, remote_filename=M00/00/23/wKh5IFdjrumAc879AASrW0_jx78607_big.png

    source ip address: 192.168.121.32

    file timestamp=2016-06-17 16:03:53

    file size=306011

    file crc32=1340327871

    file url: http://192.168.121.32/group1/M00/00/23/wKh5IFdjrumAc879AASrW0_jx78607_big.png

    [fastdfs@test_dev_fastdfs_32 fdfs]$ vim /etc/fdfs/client.conf

    [fastdfs@test_dev_fastdfs_32 fdfs]$

    [fastdfs@test_dev_fastdfs_32 fdfs]$

     

     

    这里fdfs_test组件默认是上传到group1上面去,那如何测试group4的功能,可以将/group1/M00/00/23/wKh5IFdjrumAc879AASrW0_jx78607_big.png copy到group4里面的对应目录去,然后把网址中的group1换成group4,新网址变成:

    http://192.168.121.32/group4/M00/00/23/wKh5IFdjrumAc879AASrW0_jx78607_big.png


     

    这样先证明了这个fastdfs的group4新目录里面的图片是可以被访问的,然后再让开发人员在调用组件上传突破的时候,将调用url里面的group1变成group4即可。

     

     



沪ICP备19023445号-2号
友情链接