使用 Docker 安装 IPFS 星际文件系统

IPFS简介

IPFS: InterPlanetary File System,星际文件系统.

技术

关键词: 持久化 分布式 存储 去中心化 共享文件 节点 Git DHTs 哈希 区块链 P2P BitTorrent

存储特性

使用存储对象的哈希值来获取对象内容。相同内容的文件由于哈希值一样,在系统中只会存在一份,有效的节约存储空间。

注意:用户无法在提交文件后修改文件。共享文件方便且非常安全。

安全性

IPFS 本身并不加密文件内容。假如有人刚好猜到某文件的哈希值,那他就可以获得该文件。

注意:需要保密的情况下,可以在共享之前把需要加密的文件进行加密(温馨提示:注意密钥的存储、传输过程)。

IPFS 的 3 个代码库

  • github.com/ipfs/ipfs - IPFS 规范
  • github.com/ipfs/go-ipfs - Go 实现
  • github.com/protocol/ipfs-webui - Web 工作台

ipfs 命令

USAGE
  ipfs  - Global p2p merkle-dag filesystem.

  ipfs [--config=<config> | -c] [--debug | -D] [--help] [-h] [--api=<api>] [--offline] [--cid-base=<base>] [--upgrade-cidv0-in-output] [--encoding=<encoding> | --enc] [--timeout=<timeout>] <command> ...

SUBCOMMANDS
  BASIC COMMANDS
    init          Initialize local IPFS 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
    dag           Interact with IPLD DAG nodes
    files         Interact with files as if they were a unix filesystem
    block         Interact with raw blocks in the datastore

  TEXT ENCODING COMMANDS
    cid           Convert and discover properties of CIDs
    multibase     Encode and decode data with Multibase format

  ADVANCED COMMANDS
    daemon        Start a long-running daemon process
    shutdown      Shut down the daemon process
    resolve       Resolve any type of content path
    name          Publish and resolve IPNS names
    key           Create and list IPNS name keypairs
    pin           Pin objects to local storage
    repo          Manipulate the IPFS repository
    stats         Various operational stats
    p2p           Libp2p stream mounting (experimental)
    filestore     Manage the filestore (experimental)
    mount         Mount an IPFS read-only mount point (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
    routing       Issue routing commands
    ping          Measure the latency of a connection
    bitswap       Inspect bitswap state
    pubsub        Send and receive messages via pubsub

  TOOL COMMANDS
    config        Manage configuration
    version       Show IPFS version information
    diag          Generate diagnostic reports
    update        Download and apply go-ipfs updates
    commands      List all available commands
    log           Manage and show logs of running daemon

  Use 'ipfs  --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.

利用 Docker 安装 IPFS

使用 Docker 将使安装过程变得非常简单。本文简要介绍在Docker 中如何安装和使用它。

启动 Docker

这里我们使用 systemd 启动 Docker

sudo systemctl start docker

创建 Docker 挂载目录

mkdir -p $HOME/ipfs/{staging,data}

安装 IPFS

sudo docker run -d --name ipfs -v $HOME/ipfs/staging:/export -v $HOME/ipfs/data:/data/ipfs -p 4001:4001 -p 8080:8080 -p 5001:5001 ipfs/go-ipfs:latest

测试 IPFS

sudo docker exec ipfs ipfs cat QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme

使用 IPFS 伴侣

在 Firefox 浏览器中安装IPFS 伴侣扩展程序
设置您的IPFS API 链接 和 设置您的本地网关URL

Docker 容器中配置跨域

sudo docker exec ipfs ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://localhost:3000", "https://webui.ipfs.io", "http://127.0.0.1:5001"]'
sudo docker exec ipfs ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["POST"]'

重启 ipfs 容器

sudo docker restart ipfs

尽情使用吧!

浏览器中输入http://本地ip:5001/webui 看看效果把!
来试试用 ipfs-search.com来搜索资源把!

你可能感兴趣的:(docker,网络,docker,区块链,IPFS,分布式,存储)