zoukankan      html  css  js  c++  java
  • docker 中安装 FastDFS 总结

     如题,参考各资料后,安装FastDFS总结。基于已有docker镜像


    https://hub.docker.com/r/luhuiguo/fastdfs/


    docker pull luhuiguo/fastdfs

    luhuiguo/fastdfs:latest

    原:

    docker run -dti --network=host --name tracker -v /var/fdfs/tracker:/var/fdfs luhuiguo/fastdfs tracker

    改:
    docker run -dti --privileged=true --network=host --name aps-fastdfs-trakcer -v /var/fdfs/tracker:/var/fdfs -p 22122:22122 luhuiguo/fastdfs trakcer

    Ok: 跟踪器
    sudo docker run -dti --privileged=true --net=host --name aps-fastdfs-trakcer -v /var/fdfs/tracker:/var/fdfs -p 22122:22122 luhuiguo/fastdfs trakcer

    主:host的网络方式 相当于 宿主直接映射22122, 所以容器里面查不到ip

    存储器原:
    docker run -dti --network=host --name storage0 -e TRACKER_SERVER=10.1.5.85:22122 -e -v /var/fdfs/storage0:/var/fdfs luhuiguo/fastdfs storage

    改:
    sudo docker run -dti --privileged=true --net=host --name aps-fastdfs-storage -e TRACKER_SERVER=172.16.16.201:22122 -v /var/fdfs/storage:/var/fdfs luhuiguo/fastdfs storage

    参考:
    docker run -t -i --privileged=true --name="aps-fastdfs-trakcer" -p 22122:22122 john123951/fastdfs_tracker


    此镜像配置:

    跟踪器:
    配置文件: /etc/fdfs
    核心脚本: /usr/bin ls |grep fd fdfs_upload_file脚本
    管理脚本: /usr/bin fdfs_storaged fdfs_trackerd
    数据日志目录: /var/fdfs
    lib文件:/usr/lib libfastcommon.so、libfdfsclient.so 配置nginx module时用到
    /usr/lib64
    include目录: /usr/include fastcommon、fastdfs 目录 配置nginx module时用到

    存储器:
    配置文件: /etc/fdfs
    核心脚本: /usr/bin ls |grep fd fdfs_upload_file脚本
    管理脚本: /usr/bin fdfs_storaged fdfs_trackerd
    数据日志目录: /var/fdfs 注意没有后面的 tracker或 storage
    lib文件:/usr/lib libfastcommon.so、libfdfsclient.so
    /usr/lib64
    include目录: /usr/include fastcommon、fastdfs 目录

    测试上传:
    /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/zhanghui.txt

    返回结果
    group1/M00/00/00/rBAQyVk_g0aAG_iEAABEkzPAQWA637.jpg 最新测试结果

    当配置好fastdfs-nginx-module之后
    可以这样访问
    http://172.16.16.201:8888/group1/M00/00/00/rBAQyVk_g0aAG_iEAABEkzPAQWA637.jpg


    6>查看当前目录下user目录的大小,并不想看其他目录以及其子目录:

    du -sh user

    使用FastDFS遇到问题记录:

    Q1.通过命令行上传文件时出现错误:tracker_query_storage_fail,error no:28, error info No space left on device
    ——2010-7-27已解决
    原因:tracker.conf的配置项reserved_storage_space的值默认为4GB,而当前环境下剩余空间已不足4GB。
    解决:根据实际空间情况修改配置项reserved_storage_space的值。
    修改成500M已经可以

    Q2.通过JavaAPI上传文件时出现错误:Java.lang.Exception: getStoreStorage fail, errno code :2
    ——2010-7-28已解决
    原因:由于某种原因(重启或网络原因等)导致tracker认为storage服务器还没准备好。
    解决:稍待片刻,等storage服务器向tracker服务器发送心跳后即可。


    监控日志:

    fdfs_monitor /etc/fdfs/storage.conf

    正常:
    Storage 1:
    id = 172.16.16.201
    ip_addr = 172.16.16.201 (localhost.localdomain) ACTIVE


    不正常:
    Storage 1:
    id = 172.16.16.201
    ip_addr = 172.16.16.201 (localhost.localdomain) OFFLINE

    重启跟踪器:
    /usr/bin/restart.sh /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf


    重启存储器
    /usr/bin/restart.sh /usr/bin/fdfs_storaged /etc/fdfs/storage.conf

    每个存储节点安装nginx模块
    fastdfs-nginx-module_v1.16.tar.gz

    存放目录: /usr/local/src


    下载:
    fastdfs-nginx-module:
    http://172.16.16.201:5186/down/fastdfs-nginx-module-master.zip
    换一个版本
    http://172.16.16.201:5186/down/fastdfs-nginx-module_v1.15.tar.gz (这个版本可以,编译不会报错)


    nginx:
    http://172.16.16.201:5186/down/nginx-1.12.0.tar.gz (安装报错,应该不是这个的问题,是fastdfs-nginx-module版本的问题)
    wget -c https://nginx.org/download/nginx-1.10.1.tar.gz


    #修改模块中对应的路径,要不然模块不能正确安装加载
    cd fastdfs-nginx-module/src
    vi config #更改如下, 去掉local,并指定lib64(64系统)
    CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
    CORE_LIBS="$CORE_LIBS -L/usr/lib64 -lfastcommon -lfdfsclient"


    添加fastdfs-nginx-module模块:
    ./configure --add-module=/home/soft/fastdfs-nginx-module/src

    换目录
    ./configure --add-module=/usr/local/src/fastdfs-nginx-module/src

    配置完毕,安装过程中会提示很多not found和 found,忽略

    nginx path prefix: "/usr/local/nginx"
    nginx binary file: "/usr/local/nginx/sbin/nginx"
    nginx modules path: "/usr/local/nginx/modules"
    nginx configuration prefix: "/usr/local/nginx/conf"
    nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
    nginx pid file: "/usr/local/nginx/logs/nginx.pid"
    nginx error log file: "/usr/local/nginx/logs/error.log"
    nginx http access log file: "/usr/local/nginx/logs/access.log"
    nginx http client request body temporary files: "client_body_temp"
    nginx http proxy temporary files: "proxy_temp"
    nginx http fastcgi temporary files: "fastcgi_temp"
    nginx http uwsgi temporary files: "uwsgi_temp"
    nginx http scgi temporary files: "scgi_temp"

    安装:
    make && make install


    检查安装:
    /usr/local/nginx/sbin/nginx -V

    复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录,并修改

    cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

    vi /etc/fdfs/mod_fastdfs.conf

    复制 FastDFS 的部分配置文件到/etc/fdfs 目录

    cd /usr/local/src/FastDFS/conf

    cp http.conf mime.types /etc/fdfs/


    在/fastdfs/storage 文件存储目录下创建软连接,将其链接到实际存放数据的目录

    ln -s /var/fdfs/data/ /var/fdfs/data/M00

    nginx 配置

    user  root;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
    
        #access_log  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    
        server {
            listen       8888;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location ~/group([0-9])/M00 {
                ngx_fastdfs_module;
            }
    
            #error_page  404              /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ .php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            #location ~ .php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /.ht {
            #    deny  all;
            #}
        }
    
    
        # another virtual host using mix of IP-, name-, and port-based configuration
        #
        #server {
        #    listen       8000;
        #    listen       somename:8080;
        #    server_name  somename  alias  another.alias;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
    
    
        # HTTPS server
        #
        #server {
        #    listen       443 ssl;
        #    server_name  localhost;
    
        #    ssl_certificate      cert.pem;
        #    ssl_certificate_key  cert.key;
    
        #    ssl_session_cache    shared:SSL:1m;
        #    ssl_session_timeout  5m;
    
        #    ssl_ciphers  HIGH:!aNULL:!MD5;
        #    ssl_prefer_server_ciphers  on;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
    
    }
    user  root;
    server {
            listen       8888;

     location ~/group([0-9])/M00 {
                ngx_fastdfs_module;
            }

    启动nginx
    /usr/local/nginx/sbin/nginx
    注:重启 Nginx 的命令为:/usr/local/nginx/sbin/nginx -s reload


    测试:
    本地:
    http://127.0.0.1:8888/group1/M00/00/00/rBAQyVk-OouAeQFzAAAAIpJOfic350.txt

    让其他电脑能访问:开放端口 端口映射
    因为这个容器的网络是 是 --network=host,所以需要对 8888端口暴露出来。

    经过测试发现这种方式的端口不用特殊配置,直接给外面用。

    即不用配置直接可以访问
    http://172.16.16.201:8888/group1/M00/00/00/rBAQyVk-OouAeQFzAAAAIpJOfic350.txt

  • 相关阅读:
    npm升级package.json依赖包到最新版本号
    vue中 父子组件的通讯
    vue组件开发
    vue模拟后端获取数据——json-server与express
    vue-cli 2.x 搭建项目
    python socket编程
    python异常处理
    python反射
    python特殊成员函数
    Executor ExecutorService Executors
  • 原文地址:https://www.cnblogs.com/hutuchong/p/7001090.html
Copyright © 2011-2022 走看看