FastDFS distributed file system (mainly used for image upload)

1, the installation FastDFS

 

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

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

 

2, to test whether the installation is successful

Creating utils / fastdfs / client.conf profile

# 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

Related to the installation package

# Install the relevant package 
# fdfs_client.zip file downloaded from the Baidu cloud 
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 ' : ' . Successed the Upload ' , ' Local File name ' : ' Media / 2018.png ' , ' Uploaded size ' : ' 504.00KB ' , ' Storage IP ' : ' 10.0.2.15 ' }
 >>> # access in your browser: http: //127.0.0.1: 8888 / group1 / M00 / 00/00 / CgACD1zWZtSAARmbAAfh_rrm7jw681.png



 

2, examples

views view

 

 

 FDFS_Client module

 

Guess you like

Origin www.cnblogs.com/jun-1024/p/10958854.html