1 | echo "a">test.txt |
master:
1 | # ipfs --api /ip4/127.0.0.1/tcp/9095 add test3.txt |
注:QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn 是一个空的文件目录,每个初始化的节点都有。
在另外两台服务器上都执行 pin ls,
1 | # ipfs --api /ip4/127.0.0.1/tcp/9095 pin ls |
说明使用cluster add的时候在所有的节点都已经同步保存了。
whx:
1 | # ipfs add test.txt |
说明普通的add命令只在本机pin
whx:
1 | # ipfs --api /ip4/127.0.0.1/tcp/9095 pin add Qmbvkmk9LFsGneteXk3G7YLqtLVME566ho6ibaQZZVHaC9 |
在另外两台服务器上都执行 pin ls,
1 | # ipfs --api /ip4/127.0.0.1/tcp/9095 pin ls |
说明使用 ipfs add 以后需要用 cluster 的 pin add 来让 cluster 保存了。
whx:
1 | # ipfs --api /ip4/127.0.0.1/tcp/9095 pin rm Qmbvkmk9LFsGneteXk3G7YLqtLVME566ho6ibaQZZVHaC9 |
执行删除操作后,pin ls看不到该文件了。
master:
1 | # ipfs --api /ip4/127.0.0.1/tcp/9095 pin add Qmbvkmk9LFsGneteXk3G7YLqtLVME566ho6ibaQZZVHaC9 |
在master上执行pin add 后该文件又出现了。(难到这个在存储里还有,重新pin add 后又出现了)
worker:
1 | # ipfs add test2.txt |
whx:
1 | # ipfs cat QmR9pC5uCF3UExca8RSrCVL8eKv7nHMpATzbEQkAHpXmVM |
说明可以看不同节点增加的文件,但是并没有pin。
whx:
1 | # ipfs --api /ip4/127.0.0.1/tcp/9095 pin add QmR9pC5uCF3UExca8RSrCVL8eKv7nHMpATzbEQkAHpXmVM |
在任意一台服务器上
1 |
|
这时候删除了都能看,然后在一台清除gc
1 | # ipfs repo gc |
一台上清除gc后依然能看,下面在所有服务器上清除
1 | # ipfs repo gc |
清除完以后就看不到文件了,说明只要gc还没有清除,文件就都还能看。
测试 replication_factor_min
和 replication_factor_max
~/.ipfs-cluster/service.json 文件中 replication_factor_min
和 replication_factor_max
均为默认值 -1
集群中每个节点都存了一份文件副本。这不是我们想要的,需要继续实验如何控制副本数。
修改 ~/.ipfs-cluster/service.json 文件中的两个配置项: replication_factor_min
和 replication_factor_max
。
- replication_factor_min 代表存储该文件的集群最小节点数,可以理解为副本数下线,-1 代表全部。本次实验中设置为 1.
- replication_factor_max 代表存储该文件的集群最大阶段属,可以理解为副本数上限,-1 代表全部。本次实验中设置为 1.
1 | jq ".cluster.replication_factor_min = 2" ${IPFS_CLUSTER_PATH}/service.json |jq ".cluster.replication_factor_max = 3" > ${IPFS_CLUSTER_PATH}/tmp.service.json |
随机生成100M的大文件
1 | dd if=/dev/urandom of=test1.file count=100000 bs=1024 |
添加文件并查看ipfs存储
1 | # ipfs --api /ip4/127.0.0.1/tcp/9095 add test1.file |
所有三台服务器上存储内容一致.
清理所有存储
1 | # ipfs --api /ip4/127.0.0.1/tcp/9095 pin rm QmVFxmvDaBBGBFUMPLSRL9mb4N6Xm8xEYnCuy5m85gPAaP |
重新设定复制因子
1 | jq ".cluster.replication_factor_min = 1" ${IPFS_CLUSTER_PATH}/service.json |jq ".cluster.replication_factor_max = 2" > ${IPFS_CLUSTER_PATH}/tmp.service.json |
添加文件并查看ipfs存储
1 |
|
添加第二个文件:
1 | whx: # ipfs --api /ip4/127.0.0.1/tcp/9095 add test2.file |
结论:每个文件保存了两份
在master上新增文件:
1 | master: # ipfs --api /ip4/127.0.0.1/tcp/9095 add test3.file |
这时候三台服务器持平
在worker上操作:
1 | dd if=/dev/urandom of=test4.file count=100000 bs=1024 |
完成后所有服务器存储容量一致:
1 | # du -hs /data/* |
继续增加
1 | dd if=/dev/urandom of=test7.file count=100000 bs=1024 |
说明cluster尽量在节点之间保持平衡
使用ipfs-cluster-ctl添加
1 | # dd if=/dev/urandom of=test9.file count=100000 bs=1024 |
单独增加一个后,增加到master
继续
1 | # dd if=/dev/urandom of=test10.file count=100000 bs=1024 |
这时候所有服务器存储容量保持平衡。
测试别的命令:
1 | # ipfs add usage-ipfs.txt |
测试curl方式
1 | # curl -X POST "http://127.0.0.1:4001/api/v0/pin/ls" |jq |
add method param
1 | replication |
1 | ipfs --api /ip4/127.0.0.1/tcp/9095 cat |
As a final tip, this table provides a quick summary of methods available.
METHOD | ENDPOINT | COMMENT |
---|---|---|
GET |
/id |
Cluster peer information |
GET |
/version |
Cluster version |
GET |
/peers |
Cluster peers |
DELETE |
/peers/{peerID} |
Remove a peer |
POST |
/add |
Add content to the cluster |
GET |
/allocations |
List of pins and their allocations (pinset) |
GET |
/allocations/{cid} |
Show a single pin and its allocations (from the pinset) |
GET |
/pins |
Local status of all tracked CIDs |
POST |
/pins/sync |
Sync local status from IPFS |
GET |
/pins/{cid} |
Local status of single CID |
POST |
/pins/{cid} |
Pin a CID |
POST |
/pins/{ipfs|ipns|ipld}/<path> |
Pin using an IPFS path |
DELETE |
/pins/{cid} |
Unpin a CID |
DELETE |
/pins/{ipfs|ipns|ipld}/<path> |
Unpin using an IPFS path |
POST |
/pins/{cid}/sync |
Sync a CID |
POST |
/pins/{cid}/recover |
Recover a CID |
POST |
/pins/recover |
Recover all pins in the receiving Cluster peer |
GET |
/monitor/metrics |
Get a list of metric types known to the peer |
GET |
/monitor/metrics/{metric} |
Get a list of current metrics seen by this peer |
GET |
/health/alerts |
Display a list of alerts (metric expiration events) |
GET |
/health/graph |
Get connection graph |
GET |
/health/alerts |
Get connection graph |
POST |
/ipfs/gc |
Perform GC in the IPFS nodes |