Centos7使用docker搭建fastdfs及windows 10安装fdfs_client-py-master.zip错误记录

fastdfs的安装配置比较复杂,不过网上有人做的docker可以直接拿来用,记录下过程。

一、Centos7安装docker

安装步骤参照清华源说明:https://mirrors.tuna.tsinghua.edu.cn/help/docker-ce/
(一)如果之前安装过 docker,请先删掉

sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

(二)安装一些依赖

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

(三)下载docker-ce.repo

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

(四)把软件仓库地址替换为 TUNA:

sudo sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo

(五)最后安装

sudo yum makecache fast
sudo yum install docker-ce

(六)安装后启动docker

systemctl start docker

查看状态

systemctl status docker

二、获取并运行fastdfs的docker镜像

docker的常用命令不赘述,网上资料很多

(一)获取fastdfs的docker镜像

docker image pull delron/fastdfs

如果已经下载好的该镜像可以用load命令加载镜像:

docker load -i 文件路径/fastdfs_docker.tar

(二)在运行fastdfs镜像时需要将容器中的运行目录映射到宿主机的目录,这里在Centos中先创建好

mkdir -p /var/fdfs/tracker
mkdir -p /var/fdfs/storage

(三)运行fastdfs镜像

fastdfs镜像要运行2次,先运行tracker server,再运行storage server,顺序不能互换

1、运行tracker server

docker run -dit --name tracker --network=host -v /var/fdfs/tracker:/var/fdfs delron/fastdfs tracker

-d是以守护进程的方式运行该tracker容器,–network为将容器的网络映射到主机,-v为映射目录,即宿主机目录:容器中目录
最后一个tracker为让tracker server运行

2、运行storage server

docker run -dti --name storage --network=host -e TRACKER_SERVER=192.168.5.192:22122 -v /var/fdfs/storage:/var/fdfs delron/fastdfs storage

各选项的含义与上面类似,其中TRACKER_SERVER=192.168.5.192:22122中的IP地址注意修改为自己宿主机的IP。

(四)检查容器的运行状态

docker container list -a
CONTAINER ID   IMAGE            COMMAND                  CREATED        STATUS        PORTS     NAMES
3ca387cac802   delron/fastdfs   "/usr/bin/start1.sh …"   11 hours ago   Up 10 hours             storage
14b5a18cc965   delron/fastdfs   "/usr/bin/start1.sh …"   11 hours ago   Up 11 hours             tracker

三、windows 10安装fdfs_client-py-master.zip

开发端用的windows 10的python环境,安装fdfs_client-py-master.zip的时候有报错

(一)安装py3Fdfs

pip install py3Fdfs

(二)修改fdfs_client-py-master.zip

需要修改2个地方,解压fdfs_client-py-master.zip
1、修改fdfs_client\storage_client.py
注释第12行

#from fdfs_client.sendfile import *

2、修改setup.py
注释第33、34行

# 'ext_modules': [Extension('fdfs_client.sendfile',                       
    #                           sources=['fdfs_client/sendfilemodule.c'])], 

3、重新压缩为fdfs_client-py-master.zip

pip install fdfs_client-py-master.zip

(三)安装mutagen

注意版本选择1.40,好像新的版本会报错

pip install mutagen==1.40

(四)安装requests

pip install requests

(五)windows10中的fastdfs的client.conf,自己根据自己的配置进行修改,特别是IP

# 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=../../logs/fastdfs-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.5.192: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

(六)使用python上传图片验证

进入python的命令行终端

>>> from fdfs_client.client import Fdfs_client
>>> client = Fdfs_client('utils/fastdfs/client.conf')	# 配置文件目录
>>> client.upload_by_filename('E:/11-life/02-picture/tmp/1.JPG')	# 要上传的图片路径
上传成功的话会有下面的提示
{'Group name': 'group1', 'Remote file_id': 'group1\\M00/00/00/wKgFwGJ2ZEyAOBG2AABo9FzmFBU118.JPG', 'Status': 'Upl
oad successed.', 'Local file name': 'E:/11-life/02-picture/tmp/1.JPG', 'Uploaded size': '26.00KB', 'Storage IP':
'192.168.5.192'}

验证方法:http://192.168.5.192:8888/group1\\M00/00/00/wKgFwGJ2ZEyAOBG2AABo9FzmFBU118.JPG

这个地方端口号好像必须是8888,不能改。
如果上传失败,可能是网络或防火墙的问题。

四、防火墙配置

firewall-cmd --zone=public --add-port=23000/tcp --permanent
firewall-cmd --zone=public --add-port=22122/tcp --permanent
firewall-cmd --zone=public --add-port=8888/tcp --permanent
systemctl restart firewalld

或者直接关闭防火墙

systemctl stop firewalld

你可能感兴趣的:(centos7,docker,docker,fastdfs,centos7,windows,10)