docker 安装 fastdfs
1:安装与配置
#搜索 [root@xpq ~]# docker search fastdfs ^[[ANAME DESCRIPTION STARS OFFICIAL season/fastdfs FastDFS 67 luhuiguo/fastdfs FastDFS is an open source high performance d… 25 ygqygq2/fastdfs-nginx 整合了nginx的fastdfs 20 morunchang/fastdfs A FastDFS image 19 delron/fastdfs 12 moocu/fastdfs fastdfs5.11 9 qbanxiaoli/fastdfs FastDFS+FastDHT单机版 8 ecarpo/fastdfs-storage 4 ecarpo/fastdfs 3 lionheart/fastdfs-tracker just have a try on autobuilded -_-# 3 imlzw/fastdfs-tracker fastdfs的tracker服务 3 imlzw/fastdfs-storage-dht fastdfs的storage服务,并且集成了fastdht的服务… 2 manuku/fastdfs-fastdht fastdfs fastdht 2 leaon/fastdfs fastdfs 1 manuku/fastdfs-tracker fastdfs tracker 1 lionheart/fastdfs_tracker fastdfs file system‘s tracker node 1 basemall/fastdfs-nginx fastdfs with nginx 1 appcrash/fastdfs_nginx fastdfs with nginx 1 evan1120/fastdfs_tracker The fastdfs tracker docker image, only conta… 1 evan1120/fastdfs_storage The fastdfs storage image 1 manuku/fastdfs-storage-dht fastdfs storage dht 0 tsl0922/fastdfs FastDFS is an open source high performance d… 0 lovetutu/fastdfs_fastdht fastdfs_fastdht_docker 0 mypjb/fastdfs this is a fastdfs docker project 0 manuku/fastdfs-storage-proxy fastdfs storage proxy 0 #下载 [root@xpq ~]# docker pull delron/fastdfs Using default tag: latest latest: Pulling from delron/fastdfs 469cfcc7a4b3: Pull complete 4b4f08bd0171: Pull complete 95eef9978b96: Pull complete aff83d00c747: Pull complete 1e95dffa1075: Pull complete f114184ac28c: Pull complete 649b2ad6afe2: Pull complete 8ab2127a38c5: Pull complete 4d12f9bd27c7: Pull complete bfc05d82f0a6: Pull complete 76f2a6d84a19: Pull complete 89bd9c4e6fea: Pull complete 6c06548e40ac: Pull complete 11186700b494: Pull complete Digest: sha256:9583cb80170c153bc12615fd077fe364a8fd5a95194b7cf9a8a32d2c11f8a49d Status: Downloaded newer image for delron/fastdfs:latest docker.io/delron/fastdfs:latest #查看 [root@xpq ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE delron/fastdfs latest 8487e86fc6ee 2 years ago 464MB delron/elasticsearch-ik 2.4.6-1.0 095b6487fb77 2 years ago 689MB #运行 2.开启tracker容器
#我们将 tracker 运行目录映射到宿主机的 /home/python/fastdfs/目录中。 tracker 默认端口是88888 [root@xpq ~]# docker run -dit --name tracker --network=host -v /home/python/fastdfs/:/var/fdfs delron/fastdfs trac e6f8909e3a376ec2c532db2f46820627e9459af7be2abe5ce2b411f0e34266d2 [root@xpq ~]# docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS e6f8909e3a37 delron/fastdfs "/usr/bin/start1.sh …" 18 seconds ago Up 17 seconds f488cef7af3b delron/elasticsearch-ik:2.4.6-1.0 "/docker-entrypoint.…" 41 hours ago Up 41 hours [root@xpq ~]# #3.开启storage容器 #我们将 storage 运行目录映射到宿主机的 /home/python/fastdfs/中。 [root@xpq ~]#docker run -dit --name storage --network=host -e TRACKER_SERVER=49.232.56.143:22122 -v /home/python/fastdfs/:/var/fdfs delron/fastdfs storage 9453366f97eeed07fcaa26b859e351057de115d80414a9f51eeba21125110251 #查看
[root@xpq ~]# docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9453366f97ee delron/fastdfs "/usr/bin/start1.sh …" 5 seconds ago Up 5 seconds storage e6f8909e3a37 delron/fastdfs "/usr/bin/start1.sh …" 4 minutes ago Up 4 minutes tracker f488cef7af3b delron/elasticsearch-ik:2.4.6-1.0 "/docker-entrypoint.…" 41 hours ago Up 41 hours elasticsearch [root@xpq ~]#
2:python 版本的fdfs 客户端上传文件(https://github.com/JaceHo/fdfs_client-py)
1.安装FastDFS客户端扩展
pip install fdfs-client-py3 ==1.0.0
$ pip install mutagen
$ pip isntall requests
2.准备FastDFS客户端扩展的配置文件
# connect timeout in seconds # default value is 30s connect_timeout=500 # network timeout in seconds # default value is 30s # the base path to stornetwork_timeout=60e log files base_path=/home/python/fastdfs/tracker/logs # tracker_server can ocur more than once, and tracker_server format is # "host:port", host can be hostname or ip address tracker_server=49.232.56.143: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
3.FastDFS客户端实现文件存储
from fdfs_client.client import Fdfs_client import json # F:\PycharmProject\meiduo_project\meiduo_demo\meiduo_demo\utils\fdfs\client.conf
#加载配置文件
client= Fdfs_client("F:\\PycharmProject\\meiduo_project\\meiduo_demo\\meiduo_demo\\utils\\fdfs\\client.conf") print(client) ret = client.upload_by_filename('C:\\Users\\asus\\Desktop\\kk01.jpeg') print(json.dumps(ret))
{"Storage IP": "49.232.56.143\u00003", "Local file name": "C:\\Users\\asus\\Desktop\\kk01.jpeg", "Status": "Upload successed.", "Group name": "group1", "Uploaded size": "34.39KB", "Remote file_id": "group1/M00/00/00/rBUABF84-uKAenJ1AACJkifT0n054.jpeg"}
4:访问
- 协议:
http
- IP地址:49.232.56.143
Nginx服务器的IP地址。- 因为 FastDFS 擅长存储静态文件,但是不擅长提供静态文件的下载服务,所以我们一般会将 Nginx 服务器绑定到 Storage ,提升下载性能。
- 端口:
8888(tracker的默认端口,storage容器里可配置)Nginx服务器的端口。
- 路径:
group1/M00/00/00/wKhnnlxw_gmAcoWmAAEXU5wmjPs35.jpeg- 文件在Storage上的文件索引。
- 完整图片下载地址
http://49.232.56.143:8888/group1/M00/00/00/wKhnnlxw_gmAcoWmAAEXU5wmjPs35.jpeg
浙公网安备 33010602011771号