码迷,mamicode.com
首页 > Web开发 > 详细

FastDFS分布式文件系统(主要用作图片上传)

时间:2019-06-01 11:24:50      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:spec   col   命令   tor   track   false   stand   文件   font   

1、安装FastDFS

 

# 安装tracker
docker run -dti --network=host --name tracker -v /var/fdfs/tracker:/var/fdfs youkou1/fastdfs tracker

# 安装storage
docker run -dti --network=host --name storage -e TRACKER_SERVER=10.0.2.15:22122 -v /var/fdfs/storage:/var/fdfs youkou1/fastdfs storage

 

2、测试是否安装成功

创建utils/fastdfs/client.conf配置文件

# connect timeout in seconds
# default value is 30s
connect_timeout=30

# network timeout in seconds
# default value is 30s
network_timeout=60

# the base path to store log files
# base_path=utils/fastdfs/logs

# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
tracker_server=10.0.2.15:22122

#standard log level as syslog, case insensitive, value list:
### emerg for emergency
### alert
### crit for critical
### error
### warn for warning
### notice
### info
### debug
log_level=info

# if use connection pool
# default value is false
use_connection_pool = false

# connections whose the idle time exceeds this time will be closed
# unit: second
# default value is 3600
connection_pool_max_idle_time = 3600

# if load FastDFS parameters from tracker server
# default value is false
load_fdfs_parameters_from_tracker=false

# if use storage ID instead of IP address
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# default value is false
use_storage_id = false

# specify storage ids filename, can use relative or absolute path
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
storage_ids_filename = storage_ids.conf


#HTTP settings
http.tracker_server_port=80

安装相关包

# 安装相关包
# fdfs_client.zip文件从百度云中下载
pip install fdfs_client.zip
pip install mutagen
pip install requests
# 通过 python manage.py shell 进入命令行, 在命令行中测试:

>>> from fdfs_client.client import Fdfs_client
>>> FDFS_Client = Fdfs_client(utils/fastdfs/client.conf)
>>> ret = FDFS_Client.upload_by_filename(media/2018.png)
getting connection
<fdfs_client.connection.Connection object at 0x7f7f7f8e50b8>
<fdfs_client.fdfs_protol.Tracker_header object at 0x7f7f7f8e5080>
>>> ret
{Group name: group1, Remote file_id: group1/M00/00/00/CgACD1zWZtSAARmbAAfh_rrm7jw681.png, Status: Upload successed., Local file name: media/2018.png, Uploaded size: 504.00KB, Storage IP: 10.0.2.15}
>>> 



# 在浏览器中访问:http://127.0.0.1:8888/group1/M00/00/00/CgACD1zWZtSAARmbAAfh_rrm7jw681.png

 

2、实例

views视图

技术图片

 

 

 FDFS_Client模块

技术图片

 

FastDFS分布式文件系统(主要用作图片上传)

标签:spec   col   命令   tor   track   false   stand   文件   font   

原文地址:https://www.cnblogs.com/jun-1024/p/10958854.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!