当前位置:   article > 正文

分布式文件系统-FastDFS的使用分享_fastdfs use_connection_pool

fastdfs use_connection_pool

FastDFS是一个用C语言编写的开源的轻量级分布式文件系统,支持文件上传和下载功能,它由3部分以下组成(FastDFS服务器端有两个角色:跟踪器(tracker)和存储节点(storage)):

  •  client,客户端,用来上传和下载图片的
  •  tracker, 跟踪服务器,主要做调度工作,起负载均衡的作用
  •  storage, 存储服务器, 文件和文件属性都保存到存储服务器上

 使用Docker安装FastDFS服务器段的tracker和storage

1、获取dastdfs镜像

  • 1.1.远程下载镜像 sudo docker image pull delron/faskdfs
  • 1.2.本地镜像加载 sudo docker load -i 文件路径/faskdfs_docker.tar

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配置文件所有内容如下图:

  1. # connect timeout in seconds
  2. # default value is 30s
  3. connect_timeout=30
  4. # network timeout in seconds
  5. # default value is 30s
  6. network_timeout=120
  7. # the base path to store log files
  8. base_path=C:/Users/86183/Desktop
  9. # tracker_server can ocur more than once, and tracker_server format is
  10. # "host:port", host can be hostname or ip address
  11. tracker_server=192.168.31.198:22122
  12. #standard log level as syslog, case insensitive, value list:
  13. ### emerg for emergency
  14. ### alert
  15. ### crit for critical
  16. ### error
  17. ### warn for warning
  18. ### notice
  19. ### info
  20. ### debug
  21. log_level=info
  22. # if use connection pool
  23. # default value is false
  24. # since V4.05
  25. use_connection_pool = false
  26. # connections whose the idle time exceeds this time will be closed
  27. # unit: second
  28. # default value is 3600
  29. # since V4.05
  30. connection_pool_max_idle_time = 3600
  31. # if load FastDFS parameters from tracker server
  32. # since V4.05
  33. # default value is false
  34. load_fdfs_parameters_from_tracker=false
  35. # if use storage ID instead of IP address
  36. # same as tracker.conf
  37. # valid only when load_fdfs_parameters_from_tracker is false
  38. # default value is false
  39. # since V4.05
  40. use_storage_id = false
  41. # specify storage ids filename, can use relative or absolute path
  42. # same as tracker.conf
  43. # valid only when load_fdfs_parameters_from_tracker is false
  44. # since V4.05
  45. storage_ids_filename = storage_ids.conf
  46. #HTTP settings
  47. http.tracker_server_port=80
  48. #use "#include" directive to include HTTP other settiongs
  49. ##include http.conf

7、上传文件代码如下

  1.  from fdfs_client import client
  2. tracker=client.get_tracker_conf(r'D:\day01\meiduo17\meiduo_mall\meiduo_mall\utils\fdfs\client.conf')
  3. client=client.Fdfs_client(tracker) result=client.upload_by_filename(r'C:\Users\86183\Desktop\shu.jpg')
  4. print(result)
  5. #输出内容,代表上传成功
  6. {'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之后出现了你上传的图片,说明上传成功

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/169839
推荐阅读
相关标签
  

闽ICP备14008679号