注意:这里的IP 和端口一定不能写错,且必须配置,否则在测试上传文件时会遇到 Error: 2, No such file or directory 的报错
4.启动完成后,查看容器的状态是否都为 Up:
1 2 3 4
leazhi@ubuntu2204-001:~$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES eb0369695515 delron/fastdfs "/usr/bin/start1.sh …" 30 seconds ago Up 30 seconds fastdfs-storage e6b074861b94 delron/fastdfs "/usr/bin/start1.sh …" 41 seconds ago Up 41 seconds fastdfs-tracker
# 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=/var/fdfs/storage/logs/ # 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.3.200:22122 # 这里需要指定 tracker 服务IP:port #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
django shell 测试上传
1.进入 django shell 模式:
1 2 3 4
PS E:\GitLab\python3-django-small_haoke\haoke> python .\manage.py shell Python 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license"for more information. (InteractiveConsole)
In [3]: ret=client.upload_by_filename('/home/leazhi/Pictures/1044085.png') getting connection <fdfs_client.connection.Connection object at 0x7f92d81030d0> <fdfs_client.fdfs_protol.Tracker_header object at 0x7f92d8103f10>
上传成功,然后查看 storage 下面也有了数据:
1 2 3 4 5 6 7 8 9
──(leazhi㉿kali-desktop)-[~/Downloads/fdfs_client-py] └─$ ls /data/docker/mounts/fastdfs/storage/data 00 07 0E 15 1C 23 2A 31 38 3F 46 4D 54 5B 62 69 70 77 7E 85 8C 93 9A A1 A8 AF B6 BD C4 CB D2 D9 E0 E7 EE F5 FC 01 08 0F 16 1D 24 2B 32 39 40 47 4E 55 5C 63 6A 71 78 7F 86 8D 94 9B A2 A9 B0 B7 BE C5 CC D3 DA E1 E8 EF F6 FD 02 09 10 17 1E 25 2C 33 3A 41 48 4F 56 5D 64 6B 72 79 80 87 8E 95 9C A3 AA B1 B8 BF C6 CD D4 DB E2 E9 F0 F7 fdfs_storaged.pid 03 0A 11 18 1F 26 2D 34 3B 42 49 50 57 5E 65 6C 73 7A 81 88 8F 96 9D A4 AB B2 B9 C0 C7 CE D5 DC E3 EA F1 F8 FE 04 0B 12 19 20 27 2E 35 3C 43 4A 51 58 5F 66 6D 74 7B 82 89 90 97 9E A5 AC B3 BA C1 C8 CF D6 DD E4 EB F2 F9 FF 05 0C 13 1A 21 28 2F 36 3D 44 4B 52 59 60 67 6E 75 7C 83 8A 91 98 9F A6 AD B4 BB C2 C9 D0 D7 DE E5 EC F3 FA storage_stat.dat 06 0D 14 1B 22 29 30 37 3E 45 4C 53 5A 61 68 6F 76 7D 84 8B 92 99 A0 A7 AE B5 BC C3 CA D1 D8 DF E6 ED F4 FB sync
ret=client.upload_by_filename(r'C:\Users\leazh\Pictures\1319109.jpg') >>> ret=client.upload_by_filename(r'C:\Users\leazh\Pictures\1319109.jpg') Traceback (most recent call last): File "D:\Program Files\Python311\Lib\site-packages\fdfs_client\connection.py", line 131, in get_connection conn = self._conns_available.pop() ^^^^^^^^^^^^^^^^^^^^^^^^^^^ IndexError: pop from empty list
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "<console>", line 1, in <module> File "D:\Program Files\Python311\Lib\site-packages\fdfs_client\client.py", line 105, in upload_by_filename store_serv = tc.tracker_query_storage_stor_without_group() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Program Files\Python311\Lib\site-packages\fdfs_client\tracker_client.py", line 374, in tracker_query_storage_stor_witho ut_group conn = self.pool.get_connection() ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Program Files\Python311\Lib\site-packages\fdfs_client\connection.py", line 136, in get_connection conn = self.make_conn() ^^^^^^^^^^^^^^^^ File "D:\Program Files\Python311\Lib\site-packages\fdfs_client\connection.py", line 115, in make_conn conn_instance = self.conn_class(**self.conn_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Program Files\Python311\Lib\site-packages\fdfs_client\connection.py", line 26, in __init__ self.remote_port = conn_kwargs['port'] ~~~~~~~~~~~^^^^^^^^ KeyError: 'port'
from fdfs_client.client import Fdfs_client from django.core.files.storage import Storage from django.utils.deconstruct import deconstructible from django.conf import settings