美文网首页cicd
Docker 搭建FastDFS文件系统(离线)

Docker 搭建FastDFS文件系统(离线)

作者: lconcise | 来源:发表于2020-12-30 21:38 被阅读0次

    1. 下载镜像

    选择season/fastdfs,镜像地址:https://hub.docker.com/r/season/fastdfs

    下载1.2 版本镜像

    docker pull season/fastdfs:1.2
    

    如果服务器无法连接网络,docker save 镜像保存,docker load 镜像保存指令来完成镜像加载。

    2. 预先创建目录

    mkdir -p /opt/data/fastdfs/trakcer/data
    mkdir -p /opt/data/fastdfs/storage/data
    mkdir -p /opt/data/fastdfs/storage/path
    

    3. 创建trakcer容器(跟踪服务器容器)

      docker run -id --name tracker -p 22122:22122 --restart=always --net host -v /opt/data/fastdfs/trakcer/data:/fastdfs/tracker/data season/fastdfs:1.2 tracker
    

    -d:让容器在后台运行
    -p:指定容器内部使用的网络端口映射到我们使用的主机上
    --name:指定容器创建的名称
    -v:容器跟宿主机之间的挂载目录

    4. 创建storage容器(存储服务器容器)

      docker run -id --name storage --restart=always --net host -v /opt/data/fastdfs/storage/data:/fastdfs/storage/data -v /opt/data/fastdfs/storage/path:/fastdfs/store_path -e TRACKER_SERVER="172.16.37.36:22122" season/fastdfs:1.2 storage
    

    进入tracker 容器查看

    docker exec -it tracker bash
    cd /etc/fdfs/
    ls
    cat client.conf
    

    查看后需要修改:track_server 地址

    5. 修改tracker 容器中client.conf 文件

    进入 tracker 容器后不能使用 vi vim 命令,所以干脆将 client.conf 配置文件复制出来,在宿主机修改完再粘贴回去

      docker cp tracker:/etc/fdfs/client.conf /opt/data/fastdfs
    

    修改为 track_server 地址 为自己的ip


    image.png

    将修改后的文件替换回去

    docker cp /opt/data/fastdfs/client.conf tracker:/etc/fdfs
    

    5. 文件上传测试

    执行命令,进入 tracker 容器中:

    docker exec -it tracker bash
    

    随便创建一个 txt 文件:

     echo "niceyoo" > niceyoo.txt
    

    然后通过 fdfs_upload_file 命令将 niceyoo.txt 文件上传至服务器:

    fdfs_upload_file /etc/fdfs/client.conf niceyoo.txt
    

    返回 group1/M00/00/00/rBAlJF_qwxuAdLh1AAAACBfWGpM928.txt 地址 ,说明上传成功

    6. 配置nginx

    默认上传的文件是只能在本机访问的,当然这样肯定是不行的,所以我们需要配置一下Nginx 来帮我们实现 Web 访问的效果。

    创建nginx目录:

    mkdir -p /opt/data/fastdfs/nginx/
    

    将storage容器中的nginx配置文件复制出来:

    docker cp storage:/etc/nginx/conf/nginx.conf /opt/data/fastdfs/nginx/
    

    修改nginx中的配置:
    找到local节点,修改为:

     location / {
        root /fastdfs/store_path/data;
        ngx_fastdfs_module;
     }
    
    image.png

    创建nginx 容器

    docker run -id --name fastdfs_nginx --restart=always -v /opt/data/fastdfs/storage/path:/fastdfs/store_path -v /opt/data/fastdfs/nginx/nginx.conf:/etc/nginx/conf/nginx.conf -p 8888:80 -e TRACKER_SERVER=172.16.37.36:22122 season/fastdfs:1.2 nginx
    

    7. 测试

    测试之前上传的文件:

    image.png

    或者通过浏览器进行访问。

    参考博文:https://www.cnblogs.com/niceyoo/p/13511082.html

    相关文章

      网友评论

        本文标题:Docker 搭建FastDFS文件系统(离线)

        本文链接:https://www.haomeiwen.com/subject/qzafoktx.html