IPFS初体验(环境搭建,私有网络环境搭建,API演示)

基本命令

$ ipfs init

$ ipfs daemon

$ ipfs cat ahash

$ ipfs ls ahash

$ ipfs id

$ echo "This is some data" | ipfsblock put


 $ ipfs swarm peers

$ ipfs swarm connect

/ip4/98.207.107.204/tcp/4001/ipfs/QmVenSWgxVW4NVLCwBHTxXxuzNLaXTDoxUTqVxeaJM5avt


$ echo "ipfs rocks" > foo

$ ipfs add foo

$ ipfs pin ls --type=all

$ ipfs pin rm <foo hash>

$ ipfs pin rm -r <foo hash>        //宣布为垃圾,还可以读取该文件

$ ipfs repo gc                    //垃圾回收,回收完再也看不到该文件了

$ ipfs pin ls --type=all


$ ipfs name publish <that hash>                //制作ipns

Published to<your peer ID>: <that hash>    // /ipns/peerId会指向/ipfs/thathash

$ ipfs name resolve <your peer ID>

$ ipfs cat <your peer ID>


$ ipfs bootstrap list

$ ipfs bootstrap add

$ ipfs bootstrap rm

建立私有的IPFS网络

$ ipfs boostrap rm --all

$ ipfs bootstrap add <your peerID>

$ ipfs daemon

注意所有的peer节点重新设定peer之后还要重新启动ipfs 。

API演示

先用nginx做个代理转发

增加一个文件 /api/v0/add?arg=file


根据返回的哈希值查询该文件 /api/v0/cat?arg=<filehash>


其他API演示

/api/v0/bootstrap/list

/api/v0/swarm/peers

/api/v0/id






猜你喜欢

转载自blog.csdn.net/wen942467928/article/details/79377402