目录结构
 

weed-fs master 服务接口,分配文件 id,查找 volume,volume 服务接口,在指定的 volume 服务创建指定的 volume,检查 volume 服务的状态。

master 服务接口

所有的 HTTP API 都可以通过添加 &pretty=y 参数来格式化 json 输出。

分配文件 id

# 简单用法:
curl http://localhost:9333/dir/assign
{"count":1,"fid":"3,01637037d6","url":"127.0.0.1:8080","publicUrl":"localhost:8080"} # 分配文件 id 并且指定副本类型
curl "http://localhost:9333/dir/assign?replication=001" # 指定需要分配多少个文件 id
curl "http://localhost:9333/dir/assign?count=5" # 指定指定的 data center
curl "http://localhost:9333/dir/assign?dataCenter=dc1"

查找 volume

我们需要找到 volume 服务是否已经转移了地方。

curl "http://localhost:9333/dir/lookup?volumeId=3&pretty=y"
{
"locations": [
{
"publicUrl": "localhost:8080",
"url": "localhost:8080"
}
]
}
# 其他用法:
# 你可以通过一个文件 id 来查找
curl "http://localhost:9333/dir/lookup?volumeId=3,01637037d6" # 如果你知道 collection,指定collection会变得快一点。
curl "http://localhost:9333/dir/lookup?volumeId=3&collection=turbo"

强制垃圾回收

如果你的系统有大量的文件删除。那些删除文件的空间不会同时被删除。

有一个后台任务在检查 volume 空间的使用率。如果空白的空间比率超过一定的额度(默认值是 0.3)时,该任务就会让 volume 变成只读,然后把没有存在的文件拷到另外一个新的 volume 中。

如果你觉得不耐烦,你可以通过该方法来回收那些不用的方法。

curl "http://localhost:9333/vol/vacuum"
curl "http://localhost:9333/vol/vacuum?garbageThreshold=0.4"

garbageThreshold 参数是可选的,并不会改变该默认值。你通可以通过在启动时添加 garbageThreshold 参数来指定该值。

提前创建 volumes

volume 只能同时写一个文件,如果你需要并发写,你可以提前创建多个 volume。

curl "http://localhost:9333/vol/grow?replication=000&count=4"
{"count":4} # 指定collection
curl "http://localhost:9333/vol/grow?collection=turbo&count=4" # 指定 data center
curl "http://localhost:9333/vol/grow?dataCenter=dc1&count=4"

检查系统状态

curl "http://10.0.2.15:9333/cluster/status?pretty=y"
{
"IsLeader": true,
"Leader": "10.0.2.15:9333",
"Peers": [
"10.0.2.15:9334",
"10.0.2.15:9335"
]
}
curl "http://localhost:9333/dir/status?pretty=y"
{
"Topology": {
"DataCenters": [
{
"Free": 3,
"Id": "dc1",
"Max": 7,
"Racks": [
{
"DataNodes": [
{
"Free": 3,
"Max": 7,
"PublicUrl": "localhost:8080",
"Url": "localhost:8080",
"Volumes": 4
}
],
"Free": 3,
"Id": "DefaultRack",
"Max": 7
}
]
},
{
"Free": 21,
"Id": "dc3",
"Max": 21,
"Racks": [
{
"DataNodes": [
{
"Free": 7,
"Max": 7,
"PublicUrl": "localhost:8081",
"Url": "localhost:8081",
"Volumes": 0
}
],
"Free": 7,
"Id": "rack1",
"Max": 7
},
{
"DataNodes": [
{
"Free": 7,
"Max": 7,
"PublicUrl": "localhost:8082",
"Url": "localhost:8082",
"Volumes": 0
},
{
"Free": 7,
"Max": 7,
"PublicUrl": "localhost:8083",
"Url": "localhost:8083",
"Volumes": 0
}
],
"Free": 14,
"Id": "DefaultRack",
"Max": 14
}
]
}
],
"Free": 24,
"Max": 28,
"layouts": [
{
"collection": "",
"replication": "000",
"writables": [
1,
2,
3,
4
]
}
]
},
"Version": "0.47"
}

上面操作会创建 4 个空白的 volume。

volume 服务接口

上传文件到weedfs

curl -F file=@/home/www/myphoto.jpg http://127.0.0.1:8080/3,01637037d6
{"size": 43234}

返回的大小是文件保存在 weed-fs 的大小,有时候文件会根据文件类型自动压缩。

直接上传文件

curl -F file=@/home/chris/myphoto.jpg http://localhost:9333/submit
{"fid":"3,01fbe0dc6f1f38","fileName":"myphoto.jpg","fileUrl":"localhost:8080/3,01fbe0dc6f1f38","size":68231}

这 API 只是为了方便使用,master 服务会受到一个文件 id 并且把文件保存到正确的 volume 上,该接口不支持其他参数。

删除文件

curl -X DELETE http://127.0.0.1:8080/3,01637037d6

在指定的 volume 服务创建指定的 volume

curl "http://localhost:8080/admin/assign_volume?replication=000&volume=3"

该命令会创建 volume 3 在该 volume 服务上。

如果你使用了副本类型(replication),那么你需要在在其他 volume 服务上创建同样的镜像文件。

检查 volume 服务的状态

curl "http://localhost:8080/status?pretty=y"
{
"Version": "0.34",
"Volumes": [
{
"Id": 1,
"Size": 1319688,
"RepType": "000",
"Version": 2,
"FileCount": 276,
"DeleteCount": 0,
"DeletedByteCount": 0,
"ReadOnly": false
},
{
"Id": 2,
"Size": 1040962,
"RepType": "000",
"Version": 2,
"FileCount": 291,
"DeleteCount": 0,
"DeletedByteCount": 0,
"ReadOnly": false
},
{
"Id": 3,
"Size": 1486334,
"RepType": "000",
"Version": 2,
"FileCount": 301,
"DeleteCount": 2,
"DeletedByteCount": 0,
"ReadOnly": false
},
{
"Id": 4,
"Size": 8953592,
"RepType": "000",
"Version": 2,
"FileCount": 320,
"DeleteCount": 2,
"DeletedByteCount": 0,
"ReadOnly": false
},
{
"Id": 5,
"Size": 70815851,
"RepType": "000",
"Version": 2,
"FileCount": 309,
"DeleteCount": 1,
"DeletedByteCount": 0,
"ReadOnly": false
},
{
"Id": 6,
"Size": 1483131,
"RepType": "000",
"Version": 2,
"FileCount": 301,
"DeleteCount": 1,
"DeletedByteCount": 0,
"ReadOnly": false
},
{
"Id": 7,
"Size": 46797832,
"RepType": "000",
"Version": 2,
"FileCount": 292,
"DeleteCount": 0,
"DeletedByteCount": 0,
"ReadOnly": false
}
]
}

 

Weed-FS 接口 master、volume 服务接口(转)的更多相关文章

  1. 第6章 服务模式 Service Interface(服务接口)

    Service Interface(服务接口) 上下文 您正在设计企业应用程序,并且需要能够通过网络使用其部分功能.此功能需要能够被各类系统使用,因此互操作性是设计的重要方面.除互操作性之外,可能还需 ...

  2. 010.Delphi插件之QPlugins,遍历服务接口

    这个DEMO注意是用来看一个DLL所拥有的全部服务接口 演示效果如下 代码如下: unit Frm_Main; interface uses Winapi.Windows, Winapi.Messag ...

  3. 开发FTP服务接口,对外提供接口服务

    注意:本文只适合小文本文件的上传下载,因为post请求是有大小限制的.默认大小是2m,虽然具体数值可以调节,但不适合做大文件的传输 最近公司有这么个需求:以后所有的项目开发中需要使用ftp服务器的地方 ...

  4. C# 用SoapUI调试WCF服务接口(WCF中包含用户名密码的验证)

    问题描述: 一般调试wcf程序可以直接建一个单元测试,直接调接口. 但是,这次,我还要测试在接口内的代码中看接收到的用户名密码是否正确,所以,单一的直接调用接口方法行不通, 然后就想办法通过soapU ...

  5. 《连载 | 物联网框架ServerSuperIO教程》- 12.服务接口的开发,以及与云端双向交互

    1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架ServerSuperIO教程>1.4种通讯模式机制. <连载 | 物联网框架Serve ...

  6. 使用jMeter测试Solr服务接口

    之前一直用ab做简单的服务接口测试,ab功能强悍,使用简单,但是没有生成专题图和表格等功能,因此,我们决定使用jmeter来作为我们测试工具.接下来,我们将详细介绍jmeter使用的步骤,主要包括:j ...

  7. WCF服务接口多,客户端在引用时出错!报WCF The maximum nametable character count quota (16384) has been exceeded while reading XML data错误

    WCF服务接口多,客户端在引用时出错!报WCF The maximum nametable character count quota (16384) has been exceeded while ...

  8. 服务接口API限流 Rate Limit 续

    一.前言 上一篇文章中粗浅的介绍使用Redis和基于令牌桶算法进行对服务接口API限流,本文介绍另一种算法---漏桶算法的应用.Nginx想必大家都有所了解是一个高性能的 HTTP 和反向代理服务器, ...

  9. 服务接口API限流 Rate Limit

    一.场景描述 很多做服务接口的人或多或少的遇到这样的场景,由于业务应用系统的负载能力有限,为了防止非预期的请求对系统压力过大而拖垮业务应用系统. 也就是面对大流量时,如何进行流量控制? 服务接口的流量 ...

随机推荐

  1. 计划任务at、crontab

    at一次性计划任务 格式: at + 时间 命令 安装at # yum install at -y 如果执行at命令时,出现一下情况 Can't open /var/run/atd.pid to si ...

  2. Java常用的线程池

    Java通过Executors提供四种线程池,分别为:newCachedThreadPool创建一个可缓存线程池,如果线程池长度超过处理需要,可灵活回收空闲线程,若无可回收,则新建线程.newFixe ...

  3. MySQL 插件CONNECTION_CONTROL和CONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS

    mysql> show variables like 'plugin_dir';+---------------+------------------------------+| Variabl ...

  4. (error) MOVED 5798 172.17.0.3:6379

    登录没有启动集群模式(即缺少了那个"-c"): redis-cli -c -h yourhost -p yourpost

  5. css3凹角效果

    <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...

  6. Spring MVC 类型转换

    SpringMVC类型转换: 1 日期类型转换: private Date birthday; <label for="">生日:<input type=&quo ...

  7. Kafka分布式集群部署

    这个是kafka的官网地址:http://kafka.apache.org/ 1.kafka是一个消息系统. 2.kafka对流数据可以高效的实时处理. 3.分布式集群的环境下能够保证数据的安全. k ...

  8. 《Linux 性能及调优指南》1.1 Linux进程管理

    https://blog.csdn.net/ljianhui/article/details/46718835 本文为IBM RedBook的Linux Performanceand Tuning G ...

  9. 常用正则表达式—邮箱(Email)

    本文针对有一点正则基础的同学,如果你对正则一无所知,请移步“正则表达式30分钟入门教程”学习.  要验证一个字符串是否为邮箱的话,首先要了解邮箱账号的格式.我尝试过在网上找出一个标准的格式,但是很遗憾 ...

  10. 【CF1132F】Clear the String (DP)

    /* 区间dp题目, 考虑当前区间l,r 是可以枚举最后一次拿的分界点来考虑最右边节点是不是具有贡献 */ #include<cstdio> #include<algorithm&g ...