IPFS使用篇
安装和启动ipfs
首先是安装ipfs,这里我选择在linux上安装,其他安装教程详见https://ipfs.tech
1 | 正常安装使用 |
初始化
1 | 如果在小机器上安装使用 |
启动进程
1 | ipfs daemon |
查看类似节点
1 | ipfs swarm peers |
创建一个文件放到ipfs里面去
1 | echo "meow" > meow.txt |
我们也可以在本地查看文件
1 | curl "http://127.0.0.1:8080/ipfs/QmabZ1pL9npKXJg8JGdMwQMJo2NCVy9yDVYjhiHK4LTJQH" |
注意,这个本地网关不会被暴露在外部世界。
下面我们尝试在外部网络访问ipfs-desktop,我们需要先修改ipfs的config,因为之前是绑定在127.0.0.1上的
1 | vim config然后把5001端口绑定的ip改为我们的外部ip |
然后访问
1 | curl -L "http://ip:5001/webui" |
在浏览器打开可以看到
然后还可以输入hash来查询我们上传的文件信息
可以查看全球其他节点
比如我们自己的peer ID 12D3KooWAmukrZkUwm9sX2dhrXthNtabTAynHYB93fjJ6UrG8Xfn
我们可以设置成后台一直运行,用如下命令启动
1 | nohup ipfs daemon > ipfs.log & |
我们之前ipfs add的文件并未自动添加到MFS系统,MFS是web端的一个工具帮助我们导航文件的,我们使用如下命令加入
1 | ipfs files cp /ipfs/QmabZ1pL9npKXJg8JGdMwQMJo2NCVy9yDVYjhiHK4LTJQH /1.txt |
然后我们在web界面点击文件。
可以看到成功上传。
IPNS(interplanetary name system)
It is created for updating and creating mutable links to IPFS content. IPNS is used for publishing the lastest version of IPFS content.
DNSlink
DNSlink is a protocol to link content and services directly from DNS, it looks like an IPNS address, but it uses a domain name instead of a hashed public key, like /ipns/en.wikipedia-on-ipfs.org
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment