[去 中 心 化]--社会需要进步

IPFS安装和使用指南

作者:Eureka

安装IPFS

安装相当简单!基本上拿来就可以用,例如在64位的Windows操作系统下,只要下载这个文件: https://dist.ipfs.io/go-ipfs/v0.4.2/go-ipfs_v0.4.2_windows-amd64.zip 当然随着发布版本不同会有些不一样。

下载完成解压后会得到一个文件为 ipfs.exe,直接在命令行下运行它就可以了。 我们在命令行下运行: ipfs help 如果有内容,证明你就可以用ipfs了。

在Windows下运行结果如下:

D:\Dac\go-ipfs>ipfs help
USAGE
  ipfs - Global p2p merkle-dag filesystem.
  ipfs [<flags>] <command> [] …
SUBCOMMANDS
  BASIC COMMANDS
    init          Initialize ipfs local configuration
    add <path>    Add a file to ipfs
    cat <ref>     Show ipfs object data
    get <ref>     Download ipfs objects
    ls <ref>      List links from an object
    refs <ref>    List hashes of links from an object
  DATA STRUCTURE COMMANDS
    block         Interact with raw blocks in the datastore
    object        Interact with raw dag nodes
    files         Interact with objects as if they were a unix filesystem
  ADVANCED COMMANDS
    daemon        Start a long-running daemon process
    mount         Mount an ipfs read-only mountpoint
    resolve       Resolve any type of name
    name          Publish or resolve IPNS names
    dns           Resolve DNS links
    pin           Pin objects to local storage
    repo          Manipulate the IPFS repository
  NETWORK COMMANDS
    id            Show info about ipfs peers
    bootstrap     Add or remove bootstrap peers
    swarm         Manage connections to the p2p network
    dht           Query the DHT for values or peers
    ping          Measure the latency of a connection
    diag          Print diagnostics
  TOOL COMMANDS
    config        Manage configuration
    version       Show ipfs version information
    update        Download and apply go-ipfs updates
    commands      List all available commands
  Use ‘ipfs <command> –help’ to learn more about each command.
  ipfs uses a repository in the local file system. By default, the repo is located
  at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable:
    export IPFS_PATH=/path/to/ipfsrepo

入门参考:https://ipfs.io/docs/getting-started/

安装参考:https://ipfs.io/docs/install/

开始使用

使用 ipfs init 初始化(这个只运行一次,不需要第二次运行):

D:\Dac\go-ipfs>ipfs init
initializing ipfs node at C:\Users\eureka.ipfs
generating 2048-bit RSA keypair…done
peer identity: QmWu9qgtW7hV22Q7Yy4ED86H9CyyZsGxiioPAMYhHrFDwL
to get started, enter:
  ipfs cat /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme

使用ipfs cat显示相关文件内容:

D:\Dac\go-ipfs>ipfs cat /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/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
显示quick-start
D:\Dac\go-ipfs>ipfs cat /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/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 ipfs ls /bar ipfs cat /baz ipfs cat /bar/baz ipfs cat /bar ipfs ls /baz References: ipfs refs ipfs refs -r ipfs refs –help Get: ipfs get -o foo2 diff foo foo2 Objects: ipfs object get ipfs object get /foo2 ipfs object –help Pin + GC: ipfs pin add ipfs repo gc ipfs ls ipfs pin rm ipfs repo gc Daemon: ipfs daemon (in another terminal) ipfs id Network: (must be online) ipfs swarm peers ipfs id ipfs cat Mount: (warning: fuse is finicky!) ipfs mount cd /ipfs/ 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/pl ay#/ipfs/QmTKZgRNwDNZwHtJSjCp6r5FYefzpULfy37JvMt9DwvXse images: http://localhost:8080/ipfs/QmZpc3HvfjEXvLWGQPWbHk3AjD5j8NEN4gmFN8Jmrd5g83/cs markdown renderer app: http://localhost:8080/ipfs/QmX7M9CiYXjVeFnkfVGf3y5ixTZ2ACeSGyL1vBJY1HvQPp/mdown

运行Daemon


D:\Dac\go-ipfs>ipfs daemon
Initializing daemon...
Swarm listening on /ip4/115.215.215.61/tcp/30368
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/169.254.49.111/tcp/4001
Swarm listening on /ip4/192.168.31.101/tcp/4001
Swarm listening on /ip6/2001:0:5ef5:79fd:2003:1c97:8c28:28c2/tcp/4001
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

因为这个命令行已经被占用了,所以我们另外再开一个命令行。 看看运行ipfs swarm peers 内容太多了,我将其余的省略,如下:

D:\Dac\go-ipfs>ipfs swarm  peers
/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx
/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM
/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64
/ip4/107.161.19.160/tcp/4001/ipfs/QmYYy8L3YD1nsF4xtt4xmsc14yqvAAnKksjo3F3iZs5jPv
/ip4/107.170.183.188/tcp/4001/ipfs/QmUj1nhB7j5cACy9gA9yEcxNJsHTt4LKNgw1RhuiJM9hXU
/ip4/108.160.98.106/tcp/63763/ipfs/Qmczcan7xBx6GKGVxBmuFYzvS3whuh45T1hUqzbZNgzi2J
/ip4/110.174.228.251/tcp/4001/ipfs/QmSM7fscEPNRkmfzgzYZLMpKFmF4ACPMymk9GPrc8WmgtD
/ip4/118.138.246.95/tcp/4001/ipfs/QmSRjXXKt6QS7t7UfYHx1UT3dyhheNA6VTyy4GVkpnih1m
…

让我们放一个文件到网络中吧,我简单的做了个test.html 然后使用命令 ipfs add test.html 把它放入网络

D:\Dac\go-ipfs>ipfs add test.html
1.28 KB / 1.28 KB [================================================] 100.00 % 0
added QmWtHUyFkpx7Cy2ebzPYGSB5pGQg94kMkRvpPrc4kqvdWn test.html

这时我们得到一个hash值。 打开浏览器,我们可以直接用 http://127.0.0.1:8080/ipfs/QmWtHUyFkpx7Cy2ebzPYGSB5pGQg94kMkRvpPrc4kqvdWn 查看当前加入的文件。 我们甚至可以通过网关直接访问刚才添加的文件。 https://ipfs.io/ipfs/QmWtHUyFkpx7Cy2ebzPYGSB5pGQg94kMkRvpPrc4kqvdWn

Web 图形界面

还有一个基于Web的控制台可以操作,运行daemon后,我们打开浏览器,输入地址为:http://localhost:5001/

Web Console

通过我在这里介绍IPFS,以及在现在试用IPFS,让我们可以感受到去中心化的诸多好处。


下面您可根据自己的喜好分别使用“Disqus”或者“多说”进行留言评论: