docker 中安裝 FastDFS 總結

 如題,參考各資料後,安裝FastDFS總結。基於已有docker鏡像php


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


docker pull luhuiguo/fastdfsnginx

luhuiguo/fastdfs:latestdocker

原:服務器

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 trakcersession

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

主:host的網絡方式 至關於 宿主直接映射22122, 因此容器裏面查不到ipdom

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

改:
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

相關文章
相關標籤/搜索