[fastdfs] dockerfile搭建fastdfs分布式集群

[fastdfs] dockerfile搭建fastdfs分布式集群

具体搭建过程参照官方wiki:

https://github.com/happyfish100/fastdfs/wiki

按照官方wiki,将配置文件做修改并打包,然后自己写成Dockerfile

1.环境准备

1.虚拟机三台:

  • 10.211.55.21 centos7
  • 10.211.55.22 centos7
  • 10.211.55.23 centos7

2.用到的包文件,可以选择下载好,也可以直接通过dockerfile中指定命令git下载;

这里我使用下载好的包文件:tools.tar.gz
下载地址:https://download.csdn.net/download/Ryxiong728/12396474

[ryxiong@centos7 fdfs_env_single]$ tree tools
tools
├── client.conf
├── fastdfs-master.zip
├── fastdfs-nginx-module-master.zip
├── libfastcommon-master.zip
├── mod_fastdfs.conf
├── nginx-1.16.1.tar.gz
├── nginx.conf
├── start.sh
├── storage.conf
└── tracker.conf

3.创建目录

mkdir -p ~/fasdfs/tracker  # tracker映射路径
mkdir -p ~/fasdfs/storage  # storage映射路径
mkdir -p ~/fdfs_env  # dockerfile和包文件路径

将包文件tools.tar.gz放于~/fdfs_env

2.Dockerfile和fdfs配置文件准备

1.Dockerfile编写

~/fdfs_env下新建Dockerfile文件

FROM centos7:1.0
MAINTAINER ryxiong
#安装编译环境
RUN yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim unzip -y
RUN mkdir -p /home/fastdfs/tracker
RUN mkdir -p /home/fastdfs/storage
RUN ls /home/fastdfs
WORKDIR /usr/local/src
#复制并解压缩各种源码
ADD tools.tar.gz /usr/local/src
RUN cp -r /usr/local/src/tools/* .
RUN rm -rf tools
# 安装 libfastcommon

RUN /usr/bin/unzip ./libfastcommon-master.zip
WORKDIR /usr/local/src/libfastcommon-master
RUN ./make.sh && ./make.sh install

# 安装 FastDFS
WORKDIR /usr/local/src
RUN /usr/bin/unzip ./fastdfs-master.zip
WORKDIR /usr/local/src/fastdfs-master
RUN ./make.sh && ./make.sh install
RUN cp /usr/local/src/tracker.conf /etc/fdfs/tracker.conf
RUN cp /usr/local/src/storage.conf /etc/fdfs/storage.conf
RUN cp /usr/local/src/client.conf /etc/fdfs/client.conf
RUN cp /usr/local/src/fastdfs-master/conf/http.conf /etc/fdfs/
RUN cp /usr/local/src/fastdfs-master/conf/mime.types /etc/fdfs/

#安装fastdfs-nginx-module
WORKDIR /usr/local/src
RUN /usr/bin/unzip ./fastdfs-nginx-module-master.zip
RUN cp /usr/local/src/mod_fastdfs.conf /etc/fdfs
#安装nginx
RUN /usr/bin/tar -zxvf ./nginx-1.16.1.tar.gz
WORKDIR /usr/local/src/nginx-1.16.1
RUN ./configure --add-module=/usr/local/src/fastdfs-nginx-module-master/src/
RUN make && make install

RUN cp /usr/local/src/nginx.conf /usr/local/nginx/conf
# 启动文件
RUN cp /usr/local/src/start.sh /usr/local/bin/
RUN ls /usr/local/bin
RUN chmod +x /usr/local/bin/start.sh
ENTRYPOINT ["/usr/local/bin/start.sh"]

WORKDIR /
EXPOSE 8888

2.docker-compose.yml编写

回到上层路径,cd ~

创建docker-compose.yml

fastdfs:
  # build: ./fdfs_env
  build: ./fdfs_env_single
  restart: always  # 开机自启
  container_name: fastdfs
  volumes:
    - ./fastdfs/tracker:/home/fastdfs/tracker
    - ./fastdfs/storage:/home/fastdfs/storage
    - /etc/localtime:/etc/localtime
  environment:
    - LANG=C.UTF-8
  network_mode: host

3.tools包中的配置文件修改

  • client.conf
# 主要修改的内容如下
base_path=/home/fastdfs/tracker
tracker_server=10.211.55.21:22122
tracker_server=10.211.55.22:22122
tracker_server=10.211.55.23:22122
  • mod_fastdfs.conf
# 主要修改的内容如下
tracker_server=10.211.55.21:22122
tracker_server=10.211.55.22:22122
tracker_server=10.211.55.23:22122
url_have_group_name=true
store_path0=/home/fastdfs/storage
  • storage.conf
# 主要修改的内容如下
port=23000  # storage服务端口(默认23000,一般不修改)
base_path=/home/fastdfs/storage  # 数据和日志文件存储根目录
store_path0=/home/fastdfs/storage  # 第一个存储目录
 
tracker_server=10.200.18.200:22122
tracker_server=10.200.18.201:22122
tracker_server=10.200.18.202:22122
 
http.server_port=8888  # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)
  • tracker.conf
# 主要修改的内容如下
port=22122  # tracker服务器端口(默认22122,一般不修改)
base_path=/home/fastdfs/tracker  # 存储日志和数据的根目录
  • start.sh脚本
#!/bin/sh
/etc/init.d/fdfs_trackerd start
/etc/init.d/fdfs_storaged start
/usr/local/nginx/sbin/nginx -g 'daemon off;'

3.测试上传

1.任意节点上传文件

选择一个节点,进入容器

docker exec -it fastdfs bash

上传文件

fdfs_upload_file /etc/fdfs/client.conf 上传文件路径

成功,则返回

root@centos7 /]# fdfs_upload_file /etc/fdfs/client.conf anaconda-post.log 
group1/M00/00/00/rBJ76F6zgdmASUvqAAAvW43Lfro568.log

2.通过nginx访问该文件

http://10.211.55.21:8888/group1/M00/00/00/rBJ76F6zgdmASUvqAAAvW43Lfro568.log
http://10.211.55.22:8888/group1/M00/00/00/rBJ76F6zgdmASUvqAAAvW43Lfro568.log
http://10.211.55.23:8888/group1/M00/00/00/rBJ76F6zgdmASUvqAAAvW43Lfro568.log

可以下载,说明成功了。

你可能感兴趣的:([fastdfs] dockerfile搭建fastdfs分布式集群)