您的位置:首页 > 其它

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

2017-08-14 23:37 381 查看

什么是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[/code] 

尝试运行

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

遇到了一些小问题

参考资料

https://ipfs.io/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐