FastDFS 镜像搭建

1. 环境准备

2. 构建步骤

参考文档:https://github.com/happyfish100/fastdfs/wiki
官网dockerfile地址及依赖包位置:(官网有两种构建方式,一直基于本地文件构建,实际测试source包下文件有问题,因此自己打包,见步骤一,可自行下载,第二种模式,是自动从网上下载以依赖资源,本文构建基于第一种方式)https://github.com/happyfish100/fastdfs/tree/master/docker/dockerfile_local
dockerfile_local目录结构如下

[root@localhost dockerfile_local]# ll
总用量 12
drwxr-xr-x. 2 root root  142 7月  13 10:52 conf
-rw-r--r--. 1 root root 1144 7月  13 12:45 Dockerfile
-rw-r--r--. 1 root root  679 7月  13 10:52 fastdfs.sh
-rw-r--r--. 1 root root 2018 7月  13 10:52 README.md
drwxr-xr-x. 5 root root  258 7月  13 13:22 source

2.1 将步骤一依赖包上传到目录source

目录结构如下:

[root@localhost source]# ll
总用量 1556
drwxr-xr-x. 11 root root     272 7月  13 12:32 fastdfs
drwxr-xr-x.  3 root root      47 7月  13 12:33 fastdfs-nginx-module
-rw-r--r--.  1 root root   19709 7月  13 12:43 fastdfs-nginx-module.tar.gz
-rw-r--r--.  1 root root  379835 7月  13 12:42 fastdfs.tar.gz
drwxr-xr-x.  5 root root     135 7月  13 12:34 libfastcommon
-rw-r--r--.  1 root root  162395 7月  13 12:43 libfastcommon.tar.gz
-rw-r--r--.  1 root root 1024694 7月  13 13:22 nginx-1.15.4.tar.gz

2.2 回到目录dockerfile_local

# centos 7
FROM centos:7
# 添加配置文件
# add profiles
ADD conf/client.conf /etc/fdfs/
ADD conf/http.conf /etc/fdfs/
ADD conf/mime.types /etc/fdfs/
ADD conf/storage.conf /etc/fdfs/
ADD conf/tracker.conf /etc/fdfs/
ADD fastdfs.sh /home
ADD conf/nginx.conf /etc/fdfs/
ADD conf/mod_fastdfs.conf /etc/fdfs

# 添加源文件
# add source code
ADD source/libfastcommon.tar.gz /usr/local/src/
ADD source/fastdfs.tar.gz  /usr/local/src/
ADD source/fastdfs-nginx-module.tar.gz /usr/local/src/
ADD source/nginx-1.15.4.tar.gz /usr/local/src/

# Run
RUN yum install git gcc gcc-c ++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y \
  &&  mkdir /home/dfs   \
  &&  cd /usr/local/src/  \
  &&  cd libfastcommon/   \
  &&  ./make.sh && ./make.sh install  \
  &&  cd ../  \
  &&  cd fastdfs/   \
  &&  ./make.sh && ./make.sh install  \
  &&  cd ../  \
  &&  cd nginx-1.15.4/  \
  &&  ./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/   \
  &&  make && make install  \
  &&  chmod +x /home/fastdfs.sh


# export config
VOLUME /etc/fdfs


EXPOSE 2122 23000 8888 80
ENTRYPOINT ["/home/fastdfs.sh"]

执行docker镜像构建命令

docker build -f Dockerfile -t fastdfs:v0.1 .

-f :指示Dockerfile的文件名
-t:制定镜像的名称和tag
.:指示镜像位置

2.3 执行相关镜像

docker run -d -e FASTDFS_IPADDR=192.168.199.118 -p 8888:8888 -p 22122:22122 -p 23000:23000 -p 8011:80 --name fastdfs fastdfs:v0.1

FASTDFS_IPADDR:指示宿主机的ip
8888:为nginx端口
22122:tracker_server_port tracer端口
23000:storage端口

2.4 验证容器是否启动

docker ps

[root@localhost dockerfile_local]# docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                                                                                                                                                         NAMES
3cb785eb0f18        fastdfs:v0.1                "/home/fastdfs.sh"       53 minutes ago      Up 52 minutes       0.0.0.0:8888->8888/tcp, 0.0.0.0:22122->22122/tcp, 2122/tcp, 0.0.0.0:23000->23000/tcp, 0.0.0.0:8011->80/tcp                                                    fastdfs
6a367f5a57f2        redis:3.2                   "docker-entrypoint..."   3 days ago          Up 3 days           0.0.0.0:6739->6379/tcp                                                                                                                                        redis-container-0011
7279773afddd        mysql:5.7.21                "docker-entrypoint..."   7 weeks ago         Up 4 days           0.0.0.0:53308->3306/tcp                                                                                                                                       mysql_container_004
13a4fb2ac6a2        elasticsearch:6.5.4         "/usr/local/bin/do..."   7 weeks ago         Up 4 days           0.0.0.0:9201->9200/tcp, 0.0.0.0:9301->9300/tcp                                                                                                                elasticsearch01
0ce183053042        kibana:6.5.4                "/usr/local/bin/ki..."   7 weeks ago         Up 4 days           0.0.0.0:5601->5601/tcp                                                                                                                                        kibana_6.5.4
52779514accb        elasticsearch:6.5.4         "/usr/local/bin/do..."   7 weeks ago         Up 4 days           0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp                                                                                                                elasticsearch
01c87143ae71        rabbitmq:management         "docker-entrypoint..."   2 months ago        Up 4 days           4369/tcp, 0.0.0.0:1883->1883/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 0.0.0.0:15672->15672/tcp, 0.0.0.0:25672->25672/tcp, 0.0.0.0:61613->61613/tcp, 15671/tcp   rabbit_001_container
f2aace94bbb1        mysql:5.7.21                "docker-entrypoint..."   3 months ago        Up 4 days           0.0.0.0:53307->3306/tcp                                                                                                                                       mysql_container_003
6be4f61073f3        docker.io/sonatype/nexus3   "sh -c ${SONATYPE_..."   3 months ago        Up 4 days           0.0.0.0:8082->8081/tcp                                                                                                                                        nexus3_container

问题:

本地上传文件到FastDFS命令上传报错:ERROR - file: connection_pool.c, line: 130, connect to 47.96.88.182:22122 fail

解决方案:关闭宿主机的防火墙
参照文章如下:

https://blog.csdn.net/qq_42910468/article/details/88702643

2.4 验证fastdfs是否按照成功

进入fastdfs容器

docker exec -it 3cb785eb0f18 bash

执行命令
首先创建/home/text.txt,然后执行指令如下

fdfs_upload_file /etc/fdfs/client.conf /home/test.txt

如果返回内容如下

group1/M00/00/00/rBEAA10pfmeAV2kKAAAABTu5NcY826.txt

也可通过nginx查看

http://192.168.199.118:8888/group1/M00/00/00/rBEAA10pfmeAV2kKAAAABTu5NcY826.txt
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页