fastdfs安装+python客户端

摘要:
功能包括:字符串,记录器,链,哈希,套接字,ini文件阅读器,base64编码/解码,url编码/解码,快速计时器,跳过列表,对象池等。详细信息请参阅c头文件。

fastdfs安装+python客户端

1.环境:

  • Centos7.6

2.安装:

  • 根据版本下载

    https://github.com/happyfish100/fastdfs/releases

  • gcc安装

    yum install gcc-c++
    
  • libevent安装

    yum -y install libevent
    
  • 安装libfastcommon

    • libfastcommon从开源项目FastDFS中提取的常用函数库。这个库非常简单和稳定。功能包括:字符串,记录器,链,哈希,套接字,ini文件阅读器,base64编码/解码,url编码/解码,快速计时器,跳过列表,对象池等。详细信息请参阅c头文件。

    下载地址:https://github.com/happyfish100/libfastcommon/releases

    • 安装

      //解压文件
      tar -zxvf libfastcommon-1.0.39.tar.gz
      cd libfastcommon-1.0.39
      //编译文件
      ./make.sh
      //安装依赖
      ./make.sh install
      
    • 安装出错:

      // 安装所需依赖
      yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget 
      
  • Tracker编译安装

    //解压FastDFS文件
    tar -zxvf fastdfs-5.11.tar.gz
    cd fastdfs-5.11
    //编译源码
    ./make.sh
    //安装Tracker
    ./make.sh install
    
    • 安装成功将安装目录下的conf下的文件拷贝到/etc/fdfs/下。

      //复制配置文件
      cp -r conf/* /etc/fdfs/
      
    • 配置Tracker

      mkdir /home/FastDFS
      
      //拷贝一份新的配置文件
      cp tracker.conf.sample  tracker.conf
      //修改tracker.conf
      vi tracker.conf  
       
      //配置基本路径
      base_path=/home/yuqing/FastDFS    
      //改为 
      //没有此目录需要创建此目录,个人一般使用FastDFS作为存放数据的基本目录
      base_path=/home/FastDFS   
       
      //配置http端口
      http.server_port=80 
      
    • 启动Tracker

      /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start 启动
      /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart 重启
      /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf stop  停止
      
  • Storage安装

    • 安装Tracker已经安装过Storage,直接配置Storage就好

      //重命名storage配置文件
      cp storage.conf.sample storage.conf
       
      //修改storage.conf
      vim storage.conf
       
       
      //配置base_path
      base_path=/home/fastdfs
      //配置store_path0
      store_path0=/home/fastdfs/fdfs_storage
      //配置Tracker_Server
      tracker_server=你的ip:22122
       
      //配置http端口
      http.server_port=8888
      
    • 启动Storage

      mkdir /home/fastdfs
      mkdir /home/fastdfs/fdfs_storage
      
      
      /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart 启动Storage
      /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart 重启
      /usr/bin/fdfs_storaged /etc/fdfs/storage.conf stop 关闭
       
       
      //正常启动过程
      [root@localhost home]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
      waiting for pid [23896] exit ...
      starting ...
      [root@localhost home]#
      
  • 文件上传测试

    • 客户端配置

      mkdir /home/fastdfsi
      
      //在/etc/fdfs下配置client.conf文件
      cp client.conf.sample client.conf
      vim client.conf
       
      //根据自己虚拟机的IP配置,目录没有必须手动创建
      base_path=/home/fastdfsi
      tracker_server=你的ip:22122
      //如果在同一台虚拟机不能和TrackerServer使用相同的端口
      http.tracker_server_port=8080
      
    • 上传文件

      //个人测试如下
      /usr/bin/fdfs_test /etc/fdfs/client.conf upload /opt/mp3/阿刁.mp3
       //上传格式
      /usr/bin/fdfs_test /etc/fdfs/client.conf  upload  上传文件 
      
    • 上传日志正常打印

      This is FastDFS client test program v5.11
      
      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.
      
      [2021-01-17 21:57:42] DEBUG - base_path=/home/fastdfsi, 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=10.0.0.134, port=23000
      
      group_name=group1, ip_addr=10.0.0.134, port=23000
      storage_upload_by_filename
      group_name=group1, remote_filename=M00/00/00/CgAAhmAEQlaAC7dJAMLF83jkALE177.mp3
      source ip address: 10.0.0.134
      file timestamp=2021-01-17 21:57:42
      file size=12764659
      file crc32=2028208305
      example file url: http://10.0.0.134:8080/group1/M00/00/00/CgAAhmAEQlaAC7dJAMLF83jkALE177.mp3
      storage_upload_slave_by_filename
      group_name=group1, remote_filename=M00/00/00/CgAAhmAEQlaAC7dJAMLF83jkALE177_big.mp3
      source ip address: 10.0.0.134
      file timestamp=2021-01-17 21:57:42
      file size=12764659
      file crc32=2028208305
      example file url: http://10.0.0.134:8080/group1/M00/00/00/CgAAhmAEQlaAC7dJAMLF83jkALE177_big.mp3
      
      

3.FastDFS和Nginx

tar -zxvf fastdfs-nginx-module-1.20.tar.gz

//修改config文件
vim fastdfs-nginx-module-1.20/src/config
 
ngx_module_incs="/usr/local/include"
修改为:
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
 
CORE_INCS="$CORE_INCS /usr/local/include"
修改为:
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
  • 拷贝mod_fastdfs.conf并进行配置
cp /opt/xjk_fastdfs/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs/
//修改配置文件
vim /etc/fdfs/mod_fastdfs.conf
 
base_path=/home/fastdfs  //基本路径
tracker_server=192.168.168.138:22122  //Tracker的服务IP,根据个人配置
url_have_group_name = true   //是否含有组名
store_path0=/home/fastdfs/fdfs_storage  //存储目录
//解压Nginx
tar -zxvf nginx-1.16.1.tar.gz
//配置安装路径
cd nginx-1.16.1

//定义nginx的安装目录 和fastdfs第三方模块
./configure --prefix=/usr/soft/nginx --add-module=/opt/xjk_fastdfs/fastdfs-nginx-module-1.20/src

//编译安装Nginx
make && make install
  • 配置nginx
//编辑nginx配置文件
vim /usr/soft/nginx/conf/nginx.conf

# FastDFS配置
location /group1/M00/ {
	root /home/fastdfs/fdfs_storage/data;
	ngx_fastdfs_module;
}

  • 启动nginx
/usr/soft/nginx/sbin/nginx
  • 重新加载
/usr/soft/nginx/sbin/nginx -s reload
  • 访问:
http://10.0.0.134/group1/M00/00/00/CgAAhmAESjuAHX0GAAHkf3qQ_Y8975_big.jpg
http://10.0.0.134/group1/M00/00/00/CgAAhmAEQlaAC7dJAMLF83jkALE177_big.mp3

4.python使用fastdfs客户端

  • 下载

    https://github.com/JaceHo/fdfs_client-py

  • windows修改:

    1. fdfs_client-py-master.zip 中setup.py
    	33,34注释掉
    	# 'ext_modules': [Extension('fdfs_client.sendfile',   
        #                           sources=['fdfs_client/sendfilemodule.c'])],
    2、fdfs_client 目录下的storage_client.py
        注释掉12行
        # from fdfs_client.sendfile import *
    
  • 重新打回zip包

  • 安装依赖

    pip install mutagen
    pip install requests
    
  • 安装包

H:envScriptspython3.exe -m pip install J:fdfs_client-py-master.zip
  • 将服务client.conf复制本地文件夹
  • 配置client.conf
tracker_server=10.0.0.134:22122
base_path=/home/fastdfsi
  • 上传代码演示:
from fdfs_client.client import Fdfs_client
# 加载配置文件
client = Fdfs_client('./client.conf')
ret = client.upload_by_filename(r"G:a.txt")
print(ret)
# {'Group name': 'group1', 'Remote file_id': 'group1\M00/00/00/CgAAhmAEVpiAZf3wAAAAQSbW53M734.txt', 'Status': 'Upload successed.', 'Local file name': 'G:\a.txt', 'Uploaded size': '65B', 'Storage IP': '10.0.0.134'}
  • 常见报错
1、ModuleNotFoundError: No module named 'mutagen._compat'
# 根据报错找到utils.py
将from mutagen._compat import StringIO改成from mutagen._senf._compat import StringIO
2、fdfs_client.exceptions.DataError: [-] Error: 22, Invalid argument
上传文件写入绝对路径

免责声明:文章转载自《fastdfs安装+python客户端》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Unity面试题汇总(第一部分)Mybatis拦截器介绍下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

登录时提示出错

升级system后,登录时提示出错,注释掉/etc/login.defs里对应的行就行了。 gentoo /etc/login.defs You have updated your Gentoo system but you did not fix the cfg-file as you should. Either you know how to fix...

关于arm板上ifup eth0出现问题的解决方法

最近在荔枝派zero板上做一个小项目,需要配置以太网。 驱动部分配置完成后,在终端命令下输入"ifup eth0",出现 Ignoring unknown interface eth0 搜索网上的一些解决方法: 1.在荔枝派终端下打开/etc/network/下的interfaces vi /etc/network/interfaces 2.添加这两行到i...

nginx实战

nginx介绍 http://nginx.org/ nginx安装(yum)  https://coding.net/u/aminglinux/p/nginx/git/blob/master/2z/nginx.repo 1.安装最新稳定版本,可以安装epel-release扩展源,但是用epel安装的这个版本比较老,我们这里用yum nignx源安装,...

那一定都是你的错!- 一次FastDFS并发问题的排查经历

前一段时间,业务部门同事反馈在一次生产服务器升级之后,POS消费上传小票业务偶现异常,上传小票业务有重试机制,有些重试三次也不会成功,他们排查了一下没有找到原因,希望架构部帮忙解决。 公司使用的是FastDFS来做的图片服务器,生产使用了六台服务器外加一个存储,集群采用的是:2个tracker+4个storage,storage分为两个group,使用独...

(转)CentOS系统启动流程图文详解

CentOS系统启动流程图文详解. 原文:http://www.linuxidc.com/Linux/2017-03/141966.htm 熟悉系统启动流程对于我们学习Linux系统是非常有帮助的,虽然基础,但能帮助我们更加理解Linux系统的工作机制。以下将以CentOS发行版为例来介绍Linux系统的启动流程,因为在CentOS 5、CentOS 6以...

VMWare Esxi 6.5(实际为5.x,6.x)时区问题

Esxi不支持修改时区,但是可以使用ESX或者Centos 6/7的localtime文件进行替换以实现时区修改,问题是,重启后文件会被还原。 详细的纠结过程就不说了,终级解决方案如下(给公司写的,现分享出来): 大概思路是:将centos 6中/usr/share/zoneinfo/Asia/Shanghai文件(如果是它国时区,请自行替换base64内...