前言:
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
![](file:///C:/Users/bj0204/Documents/My%20Knowledge/temp/2b6d24e2-51b2-4dd4-a63c-96000cf15c88/128/index_files/a9571d41-e798-40b8-9e33-f7d6215f7831.png)
![](https://img2018.cnblogs.com/blog/1289780/201901/1289780-20190114135743884-1824843124.png)
5.测试是否安装成功
创建utils/fastdfs/logs日志文件夹,用于存放日志信息
![](file:///C:/Users/bj0204/Documents/My%20Knowledge/temp/2b6d24e2-51b2-4dd4-a63c-96000cf15c88/128/index_files/df0087a8-e3c0-4b95-91ec-7c279dfb43e4.png)
![](https://img2018.cnblogs.com/blog/1289780/201901/1289780-20190114135810274-1204343200.png)
# 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端口
![](file:///C:/Users/bj0204/Documents/My%20Knowledge/temp/2b6d24e2-51b2-4dd4-a63c-96000cf15c88/128/index_files/41a50c04-9778-4826-8861-6bdfa3b219a1.png)
![](https://img2018.cnblogs.com/blog/1289780/201901/1289780-20190114135924781-91116612.png)
linux查看
命令:
cd /var/fdfs/
netstat -ltunp | grep 8888
![](https://img2018.cnblogs.com/blog/1289780/201901/1289780-20190114135945096-244619128.png)
![](file:///C:/Users/bj0204/Documents/My%20Knowledge/temp/2b6d24e2-51b2-4dd4-a63c-96000cf15c88/128/index_files/c2a82d7f-990b-4a1e-bee6-526ef86cddc9.png)
调试:
python manage.py shell
![](https://img2018.cnblogs.com/blog/1289780/201901/1289780-20190114135957430-1742959939.png)
![](file:///C:/Users/bj0204/Documents/My%20Knowledge/temp/2b6d24e2-51b2-4dd4-a63c-96000cf15c88/128/index_files/4c85ba7c-3e96-4621-b404-adaaa71ab249.png)
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
阿里云转换成:
结果如下:
![](file:///C:/Users/bj0204/Documents/My%20Knowledge/temp/2b6d24e2-51b2-4dd4-a63c-96000cf15c88/128/index_files/31a86973-c18e-4224-b347-daa64fe290b5.jpg)
![](https://img2018.cnblogs.com/blog/1289780/201901/1289780-20190114140033008-1482247546.png)
ps:执行中出现的问题
1、执行python manage.py shell报错
![](https://img2018.cnblogs.com/blog/1289780/201901/1289780-20190114140109880-2126970794.png)
![](file:///C:/Users/bj0204/Documents/My%20Knowledge/temp/2b6d24e2-51b2-4dd4-a63c-96000cf15c88/128/index_files/53cb1b86-c276-4926-ae76-3af2d1845006.jpg)
直接提权就好:
![](file:///C:/Users/bj0204/Documents/My%20Knowledge/temp/2b6d24e2-51b2-4dd4-a63c-96000cf15c88/128/index_files/b4438b71-c80a-42f7-b2e4-5288e0998a77.png)
作者:含笑半步颠√
博客链接:https://www.cnblogs.com/lixy-88428977
声明:本文为博主学习感悟总结,水平有限,如果不当,欢迎指正。如果您认为还不错,欢迎转载。转载与引用请注明作者及出处。