pythondjango框架中如何使用FastDFS分布式文件系统-创新互联

这篇文章主要为大家展示了“python django框架中如何使用FastDFS分布式文件系统”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“python django框架中如何使用FastDFS分布式文件系统”这篇文章吧。

成都创新互联公司-专业网站定制、快速模板网站建设、高性价比汝阳网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式汝阳网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖汝阳地区。费用合理售后完善,十余年实体公司更值得信赖。

一、安装FastDFS

1-1:执行docker命令安装

# 安装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=IP地址:22122 -v /var/fdfs/storage:/var/fdfs youkou1/fastdfs storage

python django框架中如何使用FastDFS分布式文件系统

1-2 测试是否安装成功:执行命令 docker ps -a

python django框架中如何使用FastDFS分布式文件系统

TRACKER_SERVER:IP地址说明不要使用lo 和docker下的IP地址因为在安装镜像中配的是enp3s0下面的IP地址。

python django框架中如何使用FastDFS分布式文件系统

1-3、在项目中创建客户端配置文件  fastdfs/client.conf

python django框架中如何使用FastDFS分布式文件系统

client.conf配置文件内容:注意tracker_serverIP地址。

# 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=192.168.31.170: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

1-4:在xhell中进入项目的虚拟环境安装python相关包 (在虚拟环境中)

# 安装相关包 
pip install fdfs_client.zip
pip install mutagen
pip install requests

1-5:如果pip install fdfs_client.zip 安装报错

python django框架中如何使用FastDFS分布式文件系统

请执行如下命令

sudo apt-get install python3 python-dev python3-dev build-essential libssl-dev libffi-dev libxml2-dev libxslt1-dev zlib1g-dev python-pip

python django框架中如何使用FastDFS分布式文件系统

然后在执行安装命令:

python django框架中如何使用FastDFS分布式文件系统

查看所安装的包:

python django框架中如何使用FastDFS分布式文件系统

测试代码:

from fdfs_client.client import Fdfs_client
FDFS_Client = Fdfs_client('/common/fastdfs/client.conf')
ret = FDFS_Client.upload_by_filename('/media/2018.png')
print(ret)

  如果执行不报错,返回结果如下说明就成功了:

python django框架中如何使用FastDFS分布式文件系统

1-6 如果进行测试 以下报的是语法错误,这个明显是python2的语法,我现在用的是python3,进过查询相关资料,决定换一个不用 pip install fdfs_client.zip

python django框架中如何使用FastDFS分布式文件系统

删除   fdfs_client.zip  执行命令

pip uninstall fdfs_client-py

使用pip install py3Fdfs

 python django框架中如何使用FastDFS分布式文件系统

再次测试:

python django框架中如何使用FastDFS分布式文件系统

 在浏览器中查看:

http://192.168.31.170:8888/group1/M00/00/00/wKgfqlz5yYyAHe5nAAfh_rrm7jw601.png

注意:这里的端口8888也是在上面安装环境中配好的。

以上是“python django框架中如何使用FastDFS分布式文件系统”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联成都网站设计公司行业资讯频道!

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文名称:pythondjango框架中如何使用FastDFS分布式文件系统-创新互联
网站网址:http://myzitong.com/article/cosgcs.html