【IPFS】IPFS部署分布式项目到开发机的基础实践

什么是IPFS

IPFS 是一个点对点的分布式文件系统,它希望将所有的计算设备都连接到同一个文件系统中。

IPFS能做到去中心化的分布式部署

IPFS旨在替代HTTP和为我们所有人建立更好的网络。

安装

以下地址进行下载
https://dist.ipfs.io/go-ipfs/v0.4.10/go-ipfs_v0.4.10_darwin-amd64.tar.gz

wget https://dist.ipfs.io/go-ipfs/v0.4.10/go-ipfs_v0.4.10_darwin-amd64.tar.gz
tar xvfz go-ipfs_v0.4.10_darwin-amd64.tar.gz
mv go-ipfs/ipfs /usr/local/bin/ipfs

GO环境
https://storage.googleapis.com/golang/go1.8.3.darwin-amd64.pkg

go version
go version go1.8.3 darwin/amd64

实践

初始化


ipfs init

initializing IPFS node at /Users/xiaoyu/.ipfs
generating 2048-bit RSA keypair...done
peer identity: QmSTt7gDRf5RhWDQRAp516d9hDf5ZTeyi5mcjqnL61n9ok
to get started, enter:
ipfs cat /ipfs/QmVLDAhCY3X9P2uRudKAryuQFPM5zqA3Yij1dY8FpGbL7T/readme

ipfs cat /ipfs/QmVLDAhCY3X9P2uRudKAryuQFPM5zqA3Yij1dY8FpGbL7T/readme

Hello and Welcome to IPFS!

██╗██████╗ ███████╗███████╗
██║██╔══██╗██╔════╝██╔════╝
██║██████╔╝█████╗  ███████╗
██║██╔═══╝ ██╔══╝  ╚════██║
██║██║     ██║     ███████║
╚═╝╚═╝     ╚═╝     ╚══════╝

If you're seeing this, you have successfully installed
IPFS and are now interfacing with the ipfs merkledag!

 -------------------------------------------------------
| Warning:                                              |
|   This is alpha software. Use at your own discretion! |
|   Much is missing or lacking polish. There are bugs.  |
|   Not yet secure. Read the security notes for more.   |
 -------------------------------------------------------

Check out some of the other files in this directory:

  ./about
  ./help
  ./quick-start     <-- usage examples
  ./readme          <-- this file
  ./security-notes

也就是这个文档,我们可以访问下面的文件进行访问

  • ./about
  • ./help
  • ./quick-start
  • ./readme
  • ./security-notes

quick-start

ipfs cat /ipfs/QmVLDAhCY3X9P2uRudKAryuQFPM5zqA3Yij1dY8FpGbL7T/quick-start 
# 0.1 - Quick Start //快速开始

This is a set of short examples with minimal explanation. It is meant as
a "quick start". Soon, we'll write a longer tour :-)


Add a file to ipfs://添加文件

  echo "hello world" >hello
  ipfs add hello


View it: //查看文件

  ipfs cat <the-hash-you-got-here>


Try a directory: //添加文件夹

  mkdir foo
  mkdir foo/bar
  echo "baz" > foo/baz
  echo "baz" > foo/bar/baz
  ipfs add -r foo


View things: //列出查看文件和文件夹

  ipfs ls <the-hash-here>
  ipfs ls <the-hash-here>/bar
  ipfs cat <the-hash-here>/baz
  ipfs cat <the-hash-here>/bar/baz
  ipfs cat <the-hash-here>/bar
  ipfs ls <the-hash-here>/baz


References: //重定向

  ipfs refs <the-hash-here>
  ipfs refs -r <the-hash-here>
  ipfs refs --help


Get://对比文件

  ipfs get <the-hash-here> -o foo2
  diff foo foo2


Objects://列出对象

  ipfs object get <the-hash-here>
  ipfs object get <the-hash-here>/foo2
  ipfs object --help


Pin + GC:

  ipfs pin add <the-hash-here>
  ipfs repo gc
  ipfs ls <the-hash-here>
  ipfs pin rm <the-hash-here>
  ipfs repo gc


Daemon:

  ipfs daemon  (in another terminal)
  ipfs id


Network:

  (must be online)
  ipfs swarm peers
  ipfs id
  ipfs cat <hash-of-remote-object>


Mount:

  (warning: fuse is finicky!)
  ipfs mount
  cd /ipfs/<the-hash-here>
  ls


Tool: //工具

  ipfs version
  ipfs update
  ipfs commands
  ipfs config --help
  open http://localhost:5001/webui


Browse:

  webui:

    http://localhost:5001/webui

  video:

    http://localhost:8080/ipfs/QmVc6zuAneKJzicnJpfrqCH9gSy6bz54JhcypfJYhGUFQu/play#/ipfs/QmTKZgRNwDNZwHtJSjCp6r5FYefzpULfy37JvMt9DwvXse

  images:

    http://localhost:8080/ipfs/QmZpc3HvfjEXvLWGQPWbHk3AjD5j8NEN4gmFN8Jmrd5g83/cs

  markdown renderer app:

    http://localhost:8080/ipfs/QmX7M9CiYXjVeFnkfVGf3y5ixTZ2ACeSGyL1vBJY1HvQPp/mdown

尝试运行

ipfs daemon

Initializing daemon...
Adjusting current ulimit to 2048...
Successfully raised file descriptor limit to 2048.
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/192.168.0.106/tcp/4001
Swarm listening on /ip4/192.168.1.5/tcp/50092
Swarm listening on /ip6/::1/tcp/4001
API server listening on /ip4/127.0.0.1/tcp/5001
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready

注意此时终端的命令没有结束,也就是说目前的启动是不能关闭终端的

此时访问之前的图片网址http://localhost:8080/ipfs/QmZpc3HvfjEXvLWGQPWbHk3AjD5j8NEN4gmFN8Jmrd5g83/cs,展示效果如下,文件访问成功。

这里写图片描述

同理,访问视频文件和markdown文件也能正常访问。

在demo中给的webui实际上是一个管理后台,可以查看这个项目被放到了全球多少个节点上。

出现的报错

  • ERROR core/serve: ipfs resolve -r /ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/locale/webui-zh.json: no link named "webui-zh.json" under Qmc6bAsXTFFdvV3RoLuf6jjV3jzsRLntfsivWQZ75s8QaL gateway_handler.go:584
  • ERROR flatfs: too many open files, retrying in 100ms flatfs.go:180
  • ERROR mdns: mdns lookup error: failed to bind to any unicast udp port mdns.go:135

总结

  • 了解了IPFS的安装
  • 本机成功启动了demo
  • 遇到了一些小问题

参考资料

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
IPFS(InterPlanetary File System)是一个基于内容寻址的、分布式的、新型超媒体传输协议。IPFS支持创建完全分布式的应用。它旨在使网络更快、更安全、更开放。IPFS是一个分布式文件系统,它的目标是将所有计算设备连接到同一个文件系统,从而成为一个全球统一的存储系统。某种意义上讲,这与Web最初的目标非常相似,但是它是利用BitTorrent协议进行Git数据对象的交换来达到这一个目的的。IPFS正在成为现在互联网的一个子系统。IPFS有一个更加宏伟而疯狂的目标:补充和完善现有的互联网,甚至最终取代它,从而成为新一代的互联网。这听起来有些不可思议,甚至有些疯狂,但的确是IPFS正在做的事情。图1-1所示为IPFS的官方介绍。 图1-1 IPFS官方介绍IPFS项目通过整合已有的技术(BitTorrent、DHT、Git和SFS),创建一种点对点超媒体协议,试图打造一个更加快速、安全、开放的下一代互联网,实现互联网中永久可用、数据可以永久保存的全球文件存储系统。同时,该协议有内容寻址、版本化特性,尝试补充甚至最终取代伴随了我们20多年的超文本传输协议(即HTTP协议)。IPFS是一个协议,也是一个P2P网络,它类似于现在的BT网络,只是拥有更强大的功能,使得IPFS拥有可以取代HTTP的潜力。Filecoin是运行在IPFS上的一个激励层,是一个基于区块链的分布式存储网络,它把云存储变为一个算法市场,代币(FIL)在这里起到了很重要的作用。代币是沟通资源(存储和检索)使用者(IPFS用户)和资源的提供者(Filecoin矿工)之间的中介桥梁,Filecoin协议拥有两个交易市场—数据检索和数据存储,交易双方在市场里面提交自己的需求,达成交易。IPFS和Filecoin相互促进,共同成长,解决了互联网的数据存储和数据分发的问题,特别是对于无数的区块链项目IPFS和Filecoin将作为一个基础设施存在。这就是为什么我们看到越来越多的区块链项目采取了IPFS作为存储解决方案,因为它提供了更加便宜、安全、可快速集成的存储解决方案。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值