【区块链】IPFS初探之安装试玩(二十九)
安装
官方在其安装手册列举的安装方法有这样几种
- 安装已经编译好的软件包
- 用ipfs-update 安装
- 从源代码编译
下载好之后,解开安装包,运行install.sh把ipfs可执行程序移到可执行的$PATH下
$ tar xvfz go-ipfs.tar.gz
$ cd go-ipfs
$ ./install.sh
我执行后,脚本提示说
Moved ./ipfs to /usr/local/bin
OK,现在试试看
$ ipfs help
USAGE:ipfs - Global p2p merkle-dag filesystem.SYNOPSIS
ipfs [--config= | -c] [--debug= | -D] [--help=] [-h=] [--local= | -L] [--api=] ...
一切正常,这就安装好了!
纳尼,然后呢???
试玩 初始化
ipfs的设置和内部数据都存在一个叫 repository 的目录下,第一次使用IPFS需要先执行
ipfs init
命令初始化这个 repository。$ ipfs init
initializing IPFS node at /Users/whoever/.ipfs
generating 2048-bit RSA keypair...done
peer identity: QmVUbvqV91WcD7QsmSssFuhk4VBBsLScSvePaTRAeJVJvN
to get started, enter:ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme
注意,上面显示在接下来,照着屏幕上的提示继续吧,运行peer identity:
之后的那一串Hash码是你的节点ID,肯定会和我这里显示不一样,网络上的其他节点就是通过这个来和你的节点通信连接的。需要时,你可以随时ipfs id
命令来查看这个ID
ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme
(留意,这个HASH是我的,你运行时一定和我这个不同),你会看到这样一堆东西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
这几个大大的IPFS字母,让我想起了早年纯文本界面的一个叫星球大战的MUD游戏。言归正传,继续照提示操作,看看
quick-start
里的使用例子吧。$ ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/quick-start
# 0.1 - Quick StartThis is a set of short examples with minimal explanation. It is meant as
a "quick start".Add a file to ipfs:echo "hello world" >hello
ipfs add helloView it:ipfs cat Try a directory:mkdir foo
mkdir foo/bar
echo "baz" > foo/baz
echo "baz" > foo/bar/baz
ipfs add -r fooView things:ipfs ls
ipfs ls /bar
ipfs cat /baz
ipfs cat /bar/baz
ipfs cat /bar
ipfs ls /bazReferences:ipfs refs
ipfs refs -r
ipfs refs --helpGet:ipfs get -o foo2
diff foo foo2Objects:ipfs object get
ipfs object get /foo2
ipfs object --helpPin + GC:ipfs pin add
ipfs repo gc
ipfs ls
ipfs pin rm
ipfs repo gcDaemon:ipfs daemon(in another terminal)
ipfs idNetwork:(must be online)
ipfs swarm peers
ipfs id
ipfs cat Mount:(warning: fuse is finicky!)
ipfs mount
cd /ipfs/
lsTool:ipfs version
ipfs update
ipfs commands
ipfs config --help
open http://localhost:5001/webuiBrowse:webui:http://localhost:5001/webuivideo:http://localhost:8080/ipfs/QmVc6zuAneKJzicnJpfrqCH9gSy6bz54JhcypfJYhGUFQu/play#/ipfs/QmTKZgRNwDNZwHtJSjCp6r5FYefzpULfy37JvMt9DwvXseimages:http://localhost:8080/ipfs/QmZpc3HvfjEXvLWGQPWbHk3AjD5j8NEN4gmFN8Jmrd5g83/csmarkdown renderer app:http://localhost:8080/ipfs/QmX7M9CiYXjVeFnkfVGf3y5ixTZ2ACeSGyL1vBJY1HvQPp/mdown
很多例子,眼晕吗?这里的例子可以一个个玩过去,以后再慢慢看。我们先来看看最重要的:
上线
再开一个终端窗口,运行这个命令
ipfs daemon
$ ipfs daemon
Initializing daemon...
go-ipfs version: 0.4.18-
Repo version: 7
System version: amd64/darwin
Golang version: go1.11.1
Successfully raised file descriptor limit to 2048.
Swarm listening on /ip4/10.11.1.135/tcp/4001
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/172.29.143.147/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /p2p-circuit
Swarm announcing /ip4/10.11.1.135/tcp/4001
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/172.29.143.147/tcp/4001
Swarm announcing /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
看到所有这些之后,你的IPFS节点就正式上线了。再看看这个次重要的:
欣赏一下IPFS华丽的WEB UI
用浏览器打开 http://127.0.0.1:5001/webui
文章图片
ipfswebui.png 看到这华丽的Web界面,是不是顿时感觉一切都简单了?眨眼之间,我这里就连上了800多个节点,大部分就是来自国内,看来IPFS确实越来越火啊!
附:疑难问题
检查Go语言版本 IPFS需要go 语言1.7.0以上版本,可以运行
go version
来检查,我这里的版本是$go version
go version go1.10.2 darwin/amd64
如果Go 语言版本太低,官方建议去canonical Go packages升级。
推荐阅读
- 宽容谁
- 我要做大厨
- 增长黑客的海盗法则
- 画画吗()
- 2019-02-13——今天谈梦想()
- 远去的风筝
- 三十年后的广场舞大爷
- 叙述作文
- 20190302|20190302 复盘翻盘
- 学无止境,人生还很长