• FastDFS学习总结


    引用博客:
    https://www.cnblogs.com/chiangchou/p/fastdfs.html#_labelTop
    https://www.jianshu.com/p/1c71ae024e5e

    FastDFS是什么

    开源的高性能分布式文件系统(DFS)
    项目地址:
    https://github.com/happyfish100
    https://gitee.com/fastdfs100

    FastDFS的优点

    1. 开源免费
    2. 高性能
    3. 结构简单

    FastDFS的安装(安装在docker容器中)

    安装Docker

    (略,见Docker学习总结:https://www.cnblogs.com/hutianyao/p/11395445.html)

    下载Centos镜像

    docker pull centos:7
    

    运行Centos容器

    docker run -dit -p 30001:30001 -p 30002:30002 -p 30003:30003 --name=FastDFS centos:7
    

    进入Centos容器

    docker exec -it 63 /bin/bash
    

    创建相关目录

    • 应用目录
      /apps/FastDFS/app
    • 数据目录
      /apps/FastDFS/data
      • tracker
        /apps/FastDFS/data/tracker
      • storage
        /apps/FastDFS/data/storage
      • file
        /apps/FastDFS/data/file
      • client
        /apps/FastDFS/data/client
    • 安装包目录
      /apps/FastDFS/installationPackage

    安装所需环境

    # wget
    yum -y install wget
    # make
    yum -y install gcc automake autoconf libtool make
    # vim
    yum -y install vim
    # netstat
    yum -y install net-tools
    

    安装libfastcommon

    1. 下载安装包
    wget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz
    
    1. 解压安装包
    tar -zxvf V1.0.43.tar.gz
    
    1. 编译安装
    cd libfastcommon-1.0.43/
    ./make.sh
    ./make.sh install
    

    安装FastDFS

    1. 下载安装包
    wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz
    
    1. 解压安装包
    tar -zxvf V6.06.tar.gz
    
    1. 编译安装
    ./make.sh
    ./make.sh install
    

    配置Tracker

    1. 创建配置文件
    cd /etc/fdfs
    cp tracker.conf.sample tracker.conf
    vim tracker.conf
    
    1. 配置
    # 配置文件是否不生效,false 为生效
    disabled=false
    
    # 提供服务的端口(默认22122)
    port=30001
    
    # Tracker 数据和日志目录地址(根目录必须存在,子目录会自动创建)
    base_path=/apps/FastDFS/data/tracker
    
    # HTTP 服务端口(默认8080)
    http.server_port=30003
    
    1. 启动
    cd /usr/bin
    fdfs_trackerd /etc/fdfs/tracker.conf restart
    
    1. 检查是否启动成功
    netstat -unltp|grep fdfs
    

    正常启动结果

    tcp        0      0 0.0.0.0:30001           0.0.0.0:*               LISTEN      744/fdfs_trackerd
    

    配置storage

    1. 创建配置文件
    cd /etc/fdfs
    cp storage.conf.sample storage.conf
    vim storage.conf
    
    1. 配置
    # 配置文件是否不生效,false 为生效
    disabled=false 
    
    # 指定此 storage server 所在 组(卷)
    group_name=group1
    
    # storage server 服务端口(默认23000)
    port=30002
    
    # 心跳间隔时间,单位为秒 (这里是指主动向 tracker server 发送心跳)
    heart_beat_interval=30
    
    # Storage 数据和日志目录地址(根目录必须存在,子目录会自动生成)
    base_path=/apps/FastDFS/data/storage
    
    # 存放文件时 storage server 支持多个路径。这里配置存放文件的基路径数目,通常只配一个目录。
    store_path_count=1
    
    # 逐一配置 store_path_count 个路径,索引号基于 0。
    # 如果不配置 store_path0,那它就和 base_path 对应的路径一样。
    store_path0=/apps/FastDFS/data/file
    
    # FastDFS 存储文件时,采用了两级目录。这里配置存放文件的目录个数。 
    # 如果本参数只为 N(如: 256),那么 storage server 在初次运行时,会在 store_path 下自动创建 N * N 个存放文件的子目录。
    subdir_count_per_path=256
    
    # tracker_server 的列表 ,会主动连接 tracker_server
    # 有多个 tracker server 时,每个 tracker server 写一行
    tracker_server=120.55.101.177:30001
    
    # 允许系统同步的时间段 (默认是全天) 。一般用于避免高峰同步产生一些问题而设定。
    sync_start_time=00:00
    sync_end_time=23:59
    # 访问端口(默认8888)
    http.server_port=30002
    
    1. 启动
    cd /usr/bin
    ./fdfs_storaged  /etc/fdfs/storage.conf restart
    
    1. 检查是否启动成功
    netstat -unltp|grep fdfs
    

    正常启动结果

    tcp        0      0 0.0.0.0:30002           0.0.0.0:*               LISTEN      755/./fdfs_storaged 
    tcp        0      0 0.0.0.0:30001           0.0.0.0:*               LISTEN      744/fdfs_trackerd 
    

    测试上传

    1. 创建客户端配置文件
    cd /etc/fdfs
    cp client.conf.sample client.conf
    vim client.conf
    
    1. 修改客户端配置文件
    # Client 的数据和日志目录
    base_path=/apps/FastDFS/data/client
    
    # Tracker端口
    tracker_server=120.55.101.177:30001
    
    1. 创建测试文件
    cd /apps
    touch test.txt
    
    1. 上传文件
    /usr/bin/fdfs_upload_file /etc/fdfs/client.conf test.txt
    

    成功返回:

    group1/M00/00/00/eDdlsV7k1TKALIuqAAAAAAAAAAA648.txt
    

    安装Nginx(支持访问文件)

    1. 安装Nginx所需环境
    ① gcc 安装
    
    # yum install gcc-c++
    ② PCRE pcre-devel 安装
    
    # yum install -y pcre pcre-devel
    ③ zlib 安装
    
    # yum install -y zlib zlib-devel
    ④ OpenSSL 安装
    
    # yum install -y openssl openssl-devel
    
    1. 下载Nginx安装包
    wget http://nginx.org/download/nginx-1.19.0.tar.gz
    
    1. 解压Nginx
    tar -zxvf nginx-1.19.0.tar.gz
    cd nginx-1.19.0
    
    1. 安装Nginx
    ./configure --prefix=/apps/Nginx/nginx
    make
    make install
    
    1. 启动Nginx
    cd /apps/Nginx/nginx/sbin
    ./nginx
    
    # nginx命令
    ./nginx -s stop
    ./nginx -s quit
    ./nginx -s reload
    
    1. 修改Nginx配置文件
      修改配置文件:/apps/Nginx/nginx/conf/nginx.conf,修改或新增如下配置
    listen       30003;
    
    location /group1/M00 {
        alias /apps/FastDFS/data/file/data;
    }
    
    1. 重启Nginx
    cd /apps/Nginx/nginx/sbin
    ./nginx -s reload
    
    1. 访问文件
      http://120.55.101.177:30003/group1/M00/00/00/eDdlsV7k1TKALIuqAAAAAAAAAAA648.txt

    FastDFS 配置 Nginx 模块

    1. 安装配置Nginx模块:fastdfs-nginx-module

      1. 下载安装包
      wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz
      
      1. 解压安装包
      tar zxvf V1.22.tar.gz
      
    2. 重新配置Nginx

      1. 停止Nginx
      cd /apps/Nginx/nginx/sbin
      ./nginx -s stop
      
      1. 重新配置Nginx
      ./configure --prefix=/apps/Nginx/nginx --add-module=/apps/FastDFS/app/fastdfs-nginx-module/fastdfs-nginx-module-1.22/src
      make
      make install
      
      1. 查看Nginx
      cd /apps/Nginx/nginx/sbin
      ./nginx -V
      

      出现结果:

      nginx version: nginx/1.19.0
      built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
      configure arguments: --prefix=/apps/Nginx/nginx --add-module=/apps/FastDFS/app/fastdfs-nginx-module/fastdfs-nginx-module-1.22/src
      
    3. 修改配置文件

      1. 创建配置文件
      cd /apps/FastDFS/app/fastdfs-nginx-module/fastdfs-nginx-module-1.22/src
      cp mod_fastdfs.conf /etc/fdfs/
      
      1. 修改配置文件
      cd /etc/fdfs/
      vim mod_fastdfs.conf
      
      # 连接超时时间connect_timeout=10
      
      # Tracker Server(默认22122)
      tracker_server=120.55.101.177:30001
      
      # Storage Server 端口(默认23000)
      storage_server_port=30002
      
      # 如果文件ID的uri中包含/group**,则要设置为true
      url_have_group_name = true
      
      # Storage 配置的store_path0路径,必须和storage.conf中的一致
      store_path0=/apps/FastDFS/data/file
      
    4. 复制 FastDFS 的部分配置文件到/etc/fdfs 目录

    cd /apps/FastDFS/app/fastdfs/fastdfs-6.06/conf/
    cp anti-steal.jpg http.conf mime.types /etc/fdfs/
    
    1. 配置nginx
    cd /apps/Nginx/nginx/conf/
    vim nginx.conf
    

    location /group1/M00 {
         alias /apps/FastDFS/data/file/data;
    }
    

    修改为

    location ~/group([0-9])/M00 {
         ngx_fastdfs_module;
    }
    
    1. 在文件存储目录下创建软连接,将其链接到实际存放数据的目录(这一步可以省略)
    ln -s /ljzsg/fastdfs/file/data/ /ljzsg/fastdfs/file/data/M00
    
    1. 启动Nginx
    cd /apps/Nginx/nginx/sbin/
    ./nginx
    
    1. 测试访问
      http://120.55.101.177:30003/group1/M00/00/00/eDdlsV7k1TKALIuqAAAAAAAAAAA648.txt

    打包成镜像

    docker commit -a "hutianyao" -m "fastdfs" -p 6352f82ed1b8 fastdfs:0.1
    
  • 相关阅读:
    C#对ListView控件的几个操作技巧
    C#用代码创建控件,以及它的鼠标事件
    C#使用ListView控件对数据进行频繁更新时,出现闪烁问题的解决办法
    C#判断某个键值是否存在于字典中
    FreeMASTER 2.0的安装与使用
    C和C++中获取二维数组的行列数
    Python中类的定义和使用
    Python创建字典和添加键值
    C#用鼠标滚轮控制控件大小,实现滚轮缩放效果
    C#中对Excel文件执行写数据操作
  • 原文地址:https://www.cnblogs.com/hutianyao/p/13122271.html
Copyright © 2020-2023  润新知