赞
踩
FastDFS是一个用C语言编写的开源的轻量级分布式文件系统,支持文件上传和下载功能,它由3部分以下组成(FastDFS服务器端有两个角色:跟踪器(tracker)和存储节点(storage)):
使用Docker安装FastDFS服务器段的tracker和storage
1、获取dastdfs镜像
2、创建tracker容器
sudo docker run -itd --network=host --name=tracker -v /var/fdfs/tracker:/var/fdfs delron/fstdfs tracker
解释: 将delron/fastdfs目录映射到/var/fdfs/目录中,并创建名字为tracker的容器
3、运行tracker
sudo docker container start tracker
4、创建storage容器 (我虚拟机的IP:192.168.31.198)
sudo docker run -dti --network=host --name=storage -e TRACKER_SERVER=192.168.31.198:22122 -v /var/fdfs/storage:/var/fdfs delron/fastdfs storage
注意点: 22122:是tracker的端口 8888:是storage的端口
5、在python虚拟环境中安装第3方库作为客户端
pip3 install py3Fdfs
6、修改client.conf配置文件,主要根据自己的环境情况修改图中圈的两个地方
client.conf配置文件所有内容如下图:
- # connect timeout in seconds
- # default value is 30s
- connect_timeout=30
-
- # network timeout in seconds
- # default value is 30s
- network_timeout=120
-
- # the base path to store log files
- base_path=C:/Users/86183/Desktop
-
- # 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.198: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
- # since V4.05
- use_connection_pool = false
-
- # connections whose the idle time exceeds this time will be closed
- # unit: second
- # default value is 3600
- # since V4.05
- connection_pool_max_idle_time = 3600
-
- # if load FastDFS parameters from tracker server
- # since V4.05
- # 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
- # since V4.05
- 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
- # since V4.05
- storage_ids_filename = storage_ids.conf
-
-
- #HTTP settings
- http.tracker_server_port=80
-
- #use "#include" directive to include HTTP other settiongs
- ##include http.conf
7、上传文件代码如下
- from fdfs_client import client
-
- tracker=client.get_tracker_conf(r'D:\day01\meiduo17\meiduo_mall\meiduo_mall\utils\fdfs\client.conf')
- client=client.Fdfs_client(tracker) result=client.upload_by_filename(r'C:\Users\86183\Desktop\shu.jpg')
-
- print(result)
- #输出内容,代表上传成功
- {'Group name': b'group1', 'Remote file_id': b'group1/M00/00/00/wKgfxmLTt7SAaNlKAALYUDObmaQ485.jpg', 'Status': 'Upload successed.', 'Local file name': 'C:\ \Users\\86183\\Desktop\\shu.jpg', 'Uploaded size': '182.08KB', 'Storage IP': b'192.168.31.198'}
8、通过在浏览器端访问192.168.31.198:8888/group1/M00/00/00/wKgfxmLTt7SAaNlKAALYUDObmaQ485.jpg来判断文件有没有上传成功,点击enter之后出现了你上传的图片,说明上传成功
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。