seaweedfs文件服务器使用

1、下载文件至 /var/liulei,tar -xf 解压

https://github.com/chrislusf/seaweedfs/releases/tag/0.77

https://github.com/chrislusf/seaweedfs/wiki/Getting-Started

2.

nohup /var/liulei/weed master -mdir="/var/liulei/weedfile" -ip=123.56.100.207 &
nohup /var/liulei/weed volume -max=1000000 -mserver="123.56.100.207:9333" -port=9111 -ip=123.56.100.207 -publicUrl="123.56.100.207:9222" -dir="/var/liulei/weedfilevolume" &

3.Java客户端

https://github.com/zenria/Weed-FS-Java-Client

4.Js客户端

4.1.跨域问题,需要用到nginx。配置如下

upstream volume{
     server 123.56.100.207:9111;
}

 server {
        listen       9222;
        #server_name  www.lingpaojiakao.com;

        location / {
        proxy_pass http://volume/;
        proxy_redirect          off;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        add_header Access-Control-Allow-Origin *;
        }


}

upstream master {
     server 123.56.100.207:9333;
}

 server {
        listen       9090;
        #server_name  www.lingpaojiakao.com;

        location / {
        proxy_pass http://master/;
        proxy_redirect          off;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        add_header Access-Control-Allow-Origin *;
        }


}

4.2 使用的库:https://github.com/atroo/node-weedfs

4.3 上传部分代码:(对js文件了解的不多,搞了两天才搞出来。读取buffer上传)

export function sendImageFileToServer(file, onSuccess, onError) {
    //file.name,file.type,file.size
    var reader = new FileReader();
    reader.addEventListener("load", function() {
        var parts = reader.result;
        var weedClient = require("node-seaweedfs");

        var seaweedfs = new weedClient({
            server: FILE_SERVER.host,
            port: FILE_SERVER.port,
            usePublicUrl:true
        });

        seaweedfs.write(new Buffer(parts),{collection:file.name}).then(function(fileInfo) {
            console.log(fileInfo);
            file.url = "http://"+fileInfo.publicUrl+"/"+fileInfo.fid+file.name.substring(file.name.lastIndexOf('.'));
            onSuccess(file);
        }).catch(function(err) {
            //error handling
            console.log(err);
            onError(err);
        });
    }, false);
    reader.readAsArrayBuffer(file);
}

 

你可能感兴趣的:(工具使用)