• FastDFS搭建及整合Nginx实现文件上传


    一、准备环境

            FastDFS需要两个服务,一个tracker跟踪器,一个storage存储节点,tracker做调度配置,storage完成文件存储上传等功能。

            这里我们使用两台虚拟机服务器(centos 7)来部署,有条件的同学建议直接上云资源,区别就是云端服务器更安全,需要开放一下对应端口

    二、下载所需资源包:

    https://codeload.github.com/happyfish100/libfastcommon/tar.gz/V1.0.42
    https://codeload.github.com/happyfish100/fastdfs/tar.gz/V6.04
    https://codeload.github.com/happyfish100/fastdfs-nginx-module/tar.gz/V1.22

    下载好的资源上传到服务器,这里我放在/home/software/FastDFS里

     

     因为FastDFS是C语言开发,所以需要安装之前构建服务器的C环境,执行命令:

    yum -y install gcc-c++

    yum -y install libevent

     三、安装libfastcommon和fastdfs服务

    1.解压

    tar -zxvf libfastcommon-1.0.42.tar.gz

    tar -zxvf fastdfs_.6.04.tar.gz

    2.然后进到目录里,有一个make.sh文件,执行编译安装,两个都执行此步骤

    ./make.sh    编译

    ./make.sh install   安装

    3.在安装fastdfs时,安装完成后会生成目录  /etc/fdfs ,里面会生成sample文件,我们需要将安装完成后的配置文件copy一份到目录下

    cd /home/software/FastDFS/fastdfs-6.04/conf

    cp * /etc/fdfs

            以上步骤,需要在两台服务器上同步执行,同样的安装和复制配置文件,区别是在1主机上,作为tracker服务,修改tracker的配置文件,2主机修改storage文件的配置文件

    四、修改配置文件,启动服务

    1.安装完成并copy配置文件到指定目录后,修改tracker的配置文件,这里port是tracker服务的端口,base_path是要存储数据的目录,可以自定义

    1. # bind an address of this host
    2. # empty for bind all addresses of this host
    3. bind_addr=
    4. # the tracker server port
    5. port=22122
    6. # connect timeout in seconds
    7. # default value is 30
    8. # Note: in the intranet network (LAN), 2 seconds is enough.
    9. connect_timeout=10
    10. # network timeout in seconds for send and recv
    11. # default value is 30
    12. network_timeout=60
    13. # the base path to store data and log files
    14. base_path=/usr/local/fastdfs/tracker

    2.启动服务试一下,使用/etc/fdfs/下的tracker.conf配置文件启动

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

    3.查一下服务状态

    ps -ef | grep tracker

    4.tracker启动后,我们配置一下storage

    1. # the storage server port
    2. port=23000
    3. # the base path to store data and log files
    4. # NOTE: the binlog files maybe are large, make sure
    5. # the base path has enough disk space
    6. base_path=/usr/local/fastdfs/storage
    7. # store_path#, based on 0, to configure the store paths to store file
    8. # if store_path0 not exists, it's value is base_path (NOT recommended)
    9. # the paths must be exist
    10. #
    11. # IMPORTANT NOTE:
    12. # the store paths' order is very important, don't mess up!!!
    13. # the base_path should be independent (different) of the store paths
    14. store_path0=/usr/local/fastdfs/storage
    15. #store_path1=/home/yuqing/fastdfs2
    16. # tracker_server can ocur more than once for multi tracker servers.
    17. # the value format of tracker_server is "HOST:PORT",
    18. # the HOST can be hostname or ip address,
    19. # and the HOST can be dual IPs or hostnames seperated by comma,
    20. # the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
    21. # or two different types of inner (intranet) IPs.
    22. # for example: 192.168.2.100,122.244.141.46:22122
    23. # another eg.: 192.168.1.10,172.17.4.21:22122
    24. tracker_server=192.168.98.131:22122
    25. # tracker_server=192.168.209.122:22122

    port:服务端口,云服务器的同学需要开通一下23000的端口

    base_path:storage的存储路径,自定义

    store_path0:建议同base_path配置成相同路径

    tracker_server:关联调度中心,也就是tracker的服务ip和端口

    5.然后保存,启动一下

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

    6.查一下服务状态

    ps -ef | grep storage

     五、测试文件上传

            调度和执行器都完成后,我们来测试一下,fastdfs提供了一个客户端client,在服务器上可以直接使用client测试文件上传

    1. 修改执行器storage上的 client.conf ,base_path 依旧自定义,tracker_server关联调度中心

    1. base_path=/usr/local/fastdfs/client
    2. # tracker_server can ocur more than once for multi tracker servers.
    3. # the value format of tracker_server is "HOST:PORT",
    4. # the HOST can be hostname or ip address,
    5. # and the HOST can be dual IPs or hostnames seperated by comma,
    6. # the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
    7. # or two different types of inner (intranet) IPs.
    8. # for example: 192.168.2.100,122.244.141.46:22122
    9. # another eg.: 192.168.1.10,172.17.4.21:22122
    10. tracker_server=192.168.98.131:22122
    11. # tracker_server=192.168.0.197:22122

    2.我们进到 /usr/bin 下找到服务自带的fdfs_test应用程序,使用刚刚修改的client.conf 配置上传,这里我找了服务器上一个图片做测试

    cd /usr/bin/
    ls fdfs*
    ./fdfs_test /etc/fdfs/client.conf upload /home/2bpp63hc1.jpg

    上传结果:

    1. [root@hrs-node2 bin]# ./fdfs_test /etc/fdfs/client.conf upload /home/2bpp63hc1.jpg
    2. This is FastDFS client test program v6.04
    3. Copyright (C) 2008, Happy Fish / YuQing
    4. FastDFS may be copied only under the terms of the GNU General
    5. Public License V3, which may be found in the FastDFS source kit.
    6. Please visit the FastDFS Home Page http://www.fastken.com/
    7. for more detail.
    8. [2022-12-05 18:17:08] DEBUG - base_path=/usr/local/fastdfs/client, connect_timeout=10, 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
    9. tracker_query_storage_store_list_without_group:
    10. server 1. group_name=, ip_addr=192.168.98.133, port=23000
    11. group_name=imooc, ip_addr=192.168.98.133, port=23000
    12. storage_upload_by_filename
    13. group_name=imooc, remote_filename=M00/00/00/wKhihWOOpiSAKQhHAAPkOnemQdM599.jpg
    14. source ip address: 192.168.98.133
    15. file timestamp=2022-12-05 18:17:08
    16. file size=255034
    17. file crc32=2007384531
    18. example file url: http://192.168.98.133/imooc/M00/00/00/wKhihWOOpiSAKQhHAAPkOnemQdM599.jpg
    19. storage_upload_slave_by_filename
    20. group_name=imooc, remote_filename=M00/00/00/wKhihWOOpiSAKQhHAAPkOnemQdM599_big.jpg
    21. source ip address: 192.168.98.133
    22. file timestamp=2022-12-05 18:17:08
    23. file size=255034
    24. file crc32=2007384531
    25. example file url: http://192.168.98.133/imooc/M00/00/00/wKhihWOOpiSAKQhHAAPkOnemQdM599_big.jpg

    访问地址:

    example file url: http://192.168.98.133/imooc/M00/00/00/wKhihWOOpiSAKQhHAAPkOnemQdM599_big.jpg

    Ng 待更新

  • 相关阅读:
    基于Javaee的影视创作论坛的设计与实现(源码开放)
    SpringSecurity系列一:05 SpringSecurity 自定义表单登录和注销登录认证
    Debian Linux安装minikube&kubectl
    UI组件Kendo UI for Angular R3 2022亮点——让应用程序体验更酷炫
    图像噪声,ISP,ISO与analog gain
    【基础】JDK新特性
    Qt5.9.8在linux银河麒麟下关闭系统带的最大化最小化和关闭按键
    记一次Mysql数据库宕机This could be because you hit a bug.
    4-7再谈方法之方法参数的值传递(练习)
    Python3-excel文档操作(六):利用openpyxl库处理excel表格:Excel可视化,折线图
  • 原文地址:https://blog.csdn.net/Zxiaobinggan/article/details/128196657