centos-fastdfs-nginx-docker-化

66次阅读

共计 4917 个字符,预计需要花费 13 分钟才能阅读完成。

环境准备:

使用的软件:

libfatscommon:FastDFS 分离出的一些公用函数包 https://github.com/happyfish1…

FastDFS:FastDFS 本体 https://github.com/happyfish1…

fastdfs-nginx-module:FastDFS 和 nginx 的关联模块 https://github.com/happyfish1…

nginx:nginx1.16.1 http://nginx.org/en/download….

将以上文件,下载下来,并放到一个地方

Dockerfile 编写

FROM centos

MAINTAINER 陈少平 18250073990@163.com

# install dependency
RUN yum -y upgrade \
    && yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel -y

WORKDIR /usr/local/src

# copy tool package
ADD fastdfs-5.11.tar.gz ./
ADD fastdfs-nginx-module-1.20.tar.gz ./
ADD libfastcommon-1.0.39.tar.gz ./
ADD nginx-1.16.1.tar.gz ./

# install libfastcommon
WORKDIR /usr/local/src/libfastcommon-1.0.39
RUN ./make.sh && ./make.sh install

# install FastDFS
WORKDIR /usr/local/src/fastdfs-5.11
RUN ./make.sh \
     && ./make.sh install

# install fastdfs-nginx-module
ADD config /usr/local/src/fastdfs-nginx-module-1.20/src

# install nginx
WORKDIR /usr/local/src/nginx-1.16.1
RUN ./configure --add-module=/usr/local/src/fastdfs-nginx-module-1.20/src \
    && make \
    && make install

# copy files
RUN cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf \
    && cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf \
    && cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf \
    && cp /usr/local/src/fastdfs-5.11/conf/http.conf /etc/fdfs/ \
    && cp /usr/local/src/fastdfs-5.11/conf/mime.types /etc/fdfs/ \
    && cp /usr/local/src/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs

# create fastdfs storage         
RUN mkdir /home/dfs

WORKDIR /etc/fdfs

# nginx port
EXPOSE 80
# fdfs-tracker port
EXPOSE 22122
# fdfs-client port
EXPOSE 8888

CMD ["/bin/bash"]

修改 /usr/local/src/fastdfs-nginx-module/src/config 文件信息

(ngx_module_incs,CORE_INCS,CORE_LIBS 修改这 3 个地方)
ngx_addon_name=ngx_http_fastdfs_module

if test -n "${ngx_module_link}"; then
    ngx_module_type=HTTP
    ngx_module_name=$ngx_addon_name
    ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
    ngx_module_libs="-lfastcommon -lfdfsclient"
    ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
    ngx_module_deps=
    CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024'-DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
    . auto/module
else
    HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
    NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
    CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
    CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
    CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024'-DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
fi

构建镜像

docker build -t csp/fastdfs .

运行容器前准备:

复制镜像中的文件到宿主机(为了挂载)

bogon:fastdfs chenshaoping$ pwd
/Users/chenshaoping/docker-test/fastdfs

bogon:fastdfs chenshaoping$ docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
csp/fastdfs                  latest              40322e113821        3 hours ago         596MB

bogon:fastdfs chenshaoping$ docker run -it csp/fastdfs

bogon:fastdfs chenshaoping$ docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                         NAMES
63a7588fd7be        csp/fastdfs         "/bin/bash"         4 minutes ago       Up 4 minutes        80/tcp, 8888/tcp, 22122/tcp   cool_ride

bogon:fastdfs chenshaoping$ docker cp 63a7588fd7be:/etc/fdfs /Users/chenshaoping/docker-test/fastdfs/fdfs
bogon:fastdfs chenshaoping$ docker cp 63a7588fd7be:/usr/local/nginx/conf/nginx.conf /Users/chenshaoping/docker-test/fastdfs/nginx

编写 fastdfs 启动脚本

bogon:fastdfs chenshaoping$ pwd
/Users/chenshaoping/docker-test/fastdfs

bogon:fastdfs chenshaoping$ vim start.sh
bogon:fastdfs chenshaoping$ chmod &55 start.sh
#!/bin/sh
/etc/init.d/fdfs_trackerd start
/etc/init.d/fdfs_storaged start
/usr/local/nginx/sbin/nginx -g 'daemon off

修改 tracker 配置

# 服务器 ip 为 192.168.52.1
#我建议用 ftp 下载下来这些文件 本地修改
vim /Users/chenshaoping/docker-test/fastdfs/tracker.conf
#需要修改的内容如下
port=22122  # tracker 服务器端口(默认 22122, 一般不修改)base_path=/home/dfs  # 存储日志和数据的根目录

修改 storage 配置

vim /Users/chenshaoping/docker-test/fastdfs/storage.conf
#需要修改的内容如下
port=23000  # storage 服务端口(默认 23000, 一般不修改)base_path=/home/dfs  # 数据和日志文件存储根目录
store_path0=/home/dfs  # 第一个存储目录
tracker_server=192.168.52.1:22122  # tracker 服务器 IP 和端口
http.server_port=8888  # http 访问文件的端口 (默认 8888, 看情况修改, 和 nginx 中保持一致)

修改 client 配置

vim /Users/chenshaoping/docker-test/fastdfs/client.conf
#需要修改的内容如下
base_path=/home/dfs
tracker_server=192.168.52.1:22122    #tracker 服务器 IP 和端口

配置 nginx 访问

vim /Users/chenshaoping/docker-test/fastdfs/mod_fastdfs.conf
#需要修改的内容如下
tracker_server=192.168.52.1:22122  #tracker 服务器 IP 和端口
url_have_group_name=true
store_path0=/home/dfs
#配置 nginx.config
vim /Users/chenshaoping/docker-test/fastdfs/conf/nginx.conf
#添加如下配置
server {
    listen       8888;    ## 该端口为 storage.conf 中的 http.server_port 相同
    server_name  localhost;
    location ~/group[0-9]/ {ngx_fastdfs_module;}
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {root   html;}
}

# 配置 nginx 逆向代理
 server {
        listen       80;
     ...... 以上略过   
        location ~/group[0-9]/ {proxy_pass http://localhost:8888;}
     ...... 以下略过
     }


启动容器,并启动相应服务

docker run -it -p 12121:80  -v /Users/chenshaoping/docker-test/fastdfs/fdfs:/etc/fdfs    -v /Users/chenshaoping/docker-test/fastdfs/nginx/nginx.conf:/usr/local/nginx/conf/nginx.conf csp/fastdfs
./start.sh  # 运行上面编写的脚本文件


测试文件上传(docker 内执行)

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/fastdfs-5.11/INSTALL

参考:

https://github.com/happyfish1… fastdfs 安装
https://www.jianshu.com/p/103… ubuntu fastdfs docker 化

正文完
 0