前言:
FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务,如相册网站、视频网站等等。
FastDFS为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用、高性能等指标,使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。
1.简介
开源
冗余备份、负载均衡、线性扩容
2.架构
-
-
Storage server(存储服务器):负载文件存储
# 从docker hub中拉取fastdfs镜像 docker pull fastdfs # 查看镜像是否拉取成功 docker images # 安装tracker docker run -dti --network=host --name tracker -v /var/fdfs/tracker:/var/fdfs fastdfs tracker # 安装storage docker run -dti --network=host --name storage -e TRACKER_SERVER=10.0.1.15:22122 -v /var/fdfs/storage:/var/fdfs fastdfs storage # 查看容器是否启动成功,如果为Up状态则启动成功 docker container ls -a
10.0.0.15 ip地址需要替换
linux 命令: ip a
5.测试是否安装成功
创建utils/fastdfs/logs日志文件夹,用于存放日志信息
# 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=172.17.248.213: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
阿里云 安全组放通 8888端口
linux查看
命令:
cd /var/fdfs/
netstat -ltunp | grep 8888
调试:
python manage.py shell
from fdfs_client.client import Fdfs_client # 指定fdfs客户端配置文件所在路径 FDFS_Client = Fdfs_client('utils/fastdfs/client.conf') if __name__ == '__main__': try: ret = FDFS_Client.upload_by_filename('media/linux.jpg') except Exception as e: print("fdfs测试异常:{}".format(e)) else: print(ret)
拼接URL
阿里云转换成:
结果如下:
ps:执行中出现的问题
1、执行python manage.py shell报错
直接提权就好:
作者:含笑半步颠√
博客链接:https://www.cnblogs.com/lixy-88428977
声明:本文为博主学习感悟总结,水平有限,如果不当,欢迎指正。如果您认为还不错,欢迎转载。转载与引用请注明作者及出处。