FastDFS部署

部署FastDFS

1、安装docker

安装教程:https://www.cnblogs.com/52note/p/15085961.html

2、搜索并下载 fastdfs 镜像

sudo docker search fastdfs
sudo docker pull delron/fastdfs

3、创建两个容器分别运行跟踪和存储服务器

先查询虚拟机占用的宿主机ip,跟踪服务器在这个ip上运行,启动存储服务器需要指定跟踪服务器的ip
ip addr或者ipconfig
选择这个ip

FastDFS部署

启动fastdfs服务

sudo docker run -dit --name tracker --network=host -v ~/fdfs/tracker:/var/fdfs delron/fastdfs tracker
sudo docker run -dit --name storage --network=host -e TRACKER_SERVER=你查到的ip地址:22122 -v ~/fdfs/storage:/var/fdfs delron/fastdfs storage

4、下载第三方库 fdfs_client_py34 到虚拟环境中

pip install fdfs_client_py34

5、配置 fastdfs

创建一个 fastfds 工具包

在包中创建 client.conf 配置文件,内容如下

# connect timeout in seconds
# default value is 30s
connect_timeout=300

# network timeout in seconds
# default value is 30s
network_timeout=300

# the base path to store log files
base_path=~/fdfs/logs  # 自定义你的日志文件路径

# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
#tracker_server=10.20.10.191:22122
tracker_server= 192.168.176.134:22122  # 写你自己的跟踪服务器ip

#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

5、试运行

进入 shell 窗口

python

导入 Fdfs_client 类

from fdfs_client.client import Fdfs_client

创建客户端

client = Fdfs_client(‘你的client.conf文件路径‘)

上传图片

ret = client.upload_by_filename(‘图片‘)

查看图片保存位置

ret

结果如下
{‘Group name‘: b‘group1‘,
‘Local file name‘: ‘本地文件路径‘,
‘Remote file_id‘: b‘文件在远程storage服务器中的保存路径‘,
‘Status‘: ‘Upload successed.‘,
‘Storage IP‘: b‘192.168.176.134‘,
‘Uploaded size‘: ‘103.13KB‘}

6、查看上传的图片

上传的图片保存在
~/fdfs/storage/data/00/00/
目录中
~/fdfs/storage 为创建存储服务器时自定义的宿主机映像目录,手动修改其中的文件会自动同步到远程storage服务器。

FastDFS部署

上一篇:安装pip过程中,出现'sudo'不是内部或外部命令,,,,的解决办法


下一篇:最新32位和64位xp,win7,win8,win10系统大全(电脑装机版)