neo blockchain book
  • NEOHOPE's Blockchain Book
  • 概述
    • 本书内容
    • 读者定位
    • 本书约定
    • 项目对比
    • 名词释义
  • 基本原理
    • 区块链
    • 智能合约
    • 交易所
    • 系统架构
  • 基础算法
    • 默克尔树
    • Bloom过滤器
    • 公钥私钥及椭圆曲线
  • 共识算法
    • 分布式系统
    • Paxos与Raft算法
    • 拜占庭容错算法
  • Bitcoin
    • 整体架构
    • 状态转换
    • 区块确认
    • 分叉处理
    • P2P
    • 脚本
    • 钱包
    • 使用
    • 编译(Ubuntu)
    • 私链搭建(Linux)
    • 私链搭建(Docker)
  • Ethereum
    • 整体架构
    • 状态转换
    • 区块确认
    • 使用
    • Remix IDE环境搭建(Ubuntu16)
    • 智能合约编写01
    • 智能合约编写02
    • 智能合约编写03
    • 智能合约编写04
    • 编译(MacOS)
    • 私链搭建
  • EOS
    • 整体架构
    • 使用
    • 智能合约使用(单机单节点单钱包)
    • 智能合约使用(单机单节点多钱包)
    • 编写简单的智能合约
    • 编写有数据存储的智能合约
    • 编译(Linux)
    • 私链搭建(单机多节点)
    • 私链搭建(多机多节点)
  • Fabric
    • 整体架构
    • 身份管理
    • 共识达成
    • 使用
    • 智能合约介绍
    • 智能合约使用01
    • 智能合约使用02
    • 编译(MacOS)
    • 私链搭建(Ubuntu)
    • 在私链中添加一个机构
  • Cosmos
    • 整体架构
    • Zone与Hub
    • 使用
  • IPFS
    • 整体架构
    • 使用
    • 编译(MacOS)
    • 私链搭建
  • 然后呢?
由 GitBook 提供支持
在本页
  • 下载及安装
  • 下载到本地
  • 解压及安装
  • 编译及安装
  • 初始化节点
  • 开启服务
  • 查看到的节点
  • 上传文件
  • 下载文件
  • 完结
  1. IPFS

使用

下载及安装

下载到本地

https://dist.ipfs.io/#go-ipfs

解压及安装

#解压及安装
tar -zxf go-ipfs_v0.4.14_linux-amd64.tar.gz
cd go-ipfs/
./install.sh

#测试
ipfs help
USAGE
  ipfs - Global p2p merkle-dag filesystem.

  ipfs [--config=<config> | -c] [--debug=<debug> | -D] [--help=<help>] [-h=<h>] [--local=<local> | -L] [--api=<api>] <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
    dag           Interact with IPLD documents (experimental)

  ADVANCED COMMANDS
    daemon        Start a long-running daemon process
    mount         Mount an IPFS read-only mountpoint
    resolve       Resolve any type of name
    name          Publish and resolve IPNS names
    key           Create and list IPNS name keypairs
    dns           Resolve DNS links
    pin           Pin objects to local storage
    repo          Manipulate the IPFS repository
    stats         Various operational stats
    p2p           Libp2p stream mounting
    filestore     Manage the filestore (experimental)

  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

  EXIT STATUS

  The CLI will exit with one of the following values:

  0     Successful execution.
  1     Failed executions.

编译及安装

请参考后面对于的章节。

初始化节点

#初始化节点
ipfs init
initializing IPFS node at /home/hiup/.ipfs
generating 2048-bit RSA keypair...done
peer identity: QmXhJw36JVpGNxiLK7Vxim6bJ2Qj2mPB8AdvBZ7u8HRTyE
to get started, enter:

        ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme


#查看信息
ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/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

开启服务

ipfs daemon &
[1] 4546
Initializing daemon...
Successfully raised file descriptor limit to 2048.
Swarm listening on /ip4/10.0.3.15/tcp/4001
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/172.16.172.71/tcp/4001
Swarm listening on /ip4/172.17.0.1/tcp/4001
Swarm listening on /ip4/172.18.0.1/tcp/4001
Swarm listening on /ip4/172.19.0.1/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /p2p-circuit/ipfs/QmXhJw36JVpGNxiLK7Vxim6bJ2Qj2mPB8AdvBZ7u8HRTyE
Swarm announcing /ip4/10.0.3.15/tcp/4001
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/172.16.172.71/tcp/4001
Swarm announcing /ip4/172.17.0.1/tcp/4001
Swarm announcing /ip4/172.18.0.1/tcp/4001
Swarm announcing /ip4/172.19.0.1/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 swarm peers
/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ
/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx
...

上传文件

ipfs add heart.png
added QmWnt2azBmxL3Q6bZ9YpbnwHkreYbRoDzoRCKgX8HmFN6x heart.png
#注意返回的哈希值,文件地址为
#/ipfs/QmWnt2azBmxL3Q6bZ9YpbnwHkreYbRoDzoRCKgX8HmFN6x

下载文件

#用另外一台设备,完成IPFS安装、初始化并开启服务

#下载文件
ipfs get /ipfs/QmWnt2azBmxL3Q6bZ9YpbnwHkreYbRoDzoRCKgX8HmFN6x
Saving file(s) to QmWnt2azBmxL3Q6bZ9YpbnwHkreYbRoDzoRCKgX8HmFN6x
 4.63 KB / 4.63 KB [=============================================================================================================================] 100.00% 0s

#文件重命名
mv QmWnt2azBmxL3Q6bZ9YpbnwHkreYbRoDzoRCKgX8HmFN6x heart_from_ipfs.png

完结

上一页整体架构下一页编译(MacOS)

最后更新于7年前