IPFS集群搭建记录

阅历笔记 · · 874 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

1 下载go-ipfs

wget  https://github.com/ipfs/go-ipfs/releases/download/v0.4.17/go-ipfs_v0.4.17_linux-amd64.tar.gz

2 解压

[root@blockchain42 ipfs]# tar -zxvf go-ipfs_v0.4.17_linux-amd64.tar.gz
go-ipfs/build-log
go-ipfs/install.sh
go-ipfs/ipfs
go-ipfs/LICENSE
go-ipfs/README.md

3 执行insatll.sh

[root@blockchain42 ipfs]# cd go-ipfs

[root@blockchain42 go-ipfs]# ./install.sh

Moved ./ipfs to /usr/local/bin

4 执行ipfs命令验证ipfs

[root@blockchain42 go-ipfs]# ipfs
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.

5 创建data, export目录

[root@blockchain42 ipfs]# mkdir data

[root@blockchain42 ipfs]# mkdir export

6 设置ipfs_path

[root@blockchain42 ipfs]# export IPFS_PATH=/data/ipfs/data

7 初始化ipfs

[root@blockchain42 ipfs]# ipfs init

initializing IPFS node at /data/ipfs/data
generating 2048-bit RSA keypair...done
peer identity: Qmcu1qxojgYV84hfRvvUBBLQzDLKka7kaAu8PUZi4DJziE
to get started, enter:

    ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme

8 修改配置文件

[root@blockchain42 data]# cd data

[root@blockchain42 data]# vim config
删除Bootstrap中的内容防止链接外部节点
 "Bootstrap": [
    "/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
    "/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
    "/dnsaddr/bootstrap.libp2p.io/ipfs/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
    "/dnsaddr/bootstrap.libp2p.io/ipfs/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
    "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
    "/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
    "/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
    "/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
    "/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
    "/ip6/2604:a880:1:20::203:d001/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
    "/ip6/2400:6180:0:d0::151:6001/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
    "/ip6/2604:a880:800:10::4a:5001/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
    "/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd"
  ],

9 设置ipfs_staging 和 ipfs_data

[root@blockchain42 data1]# export ipfs_staging=/data/ipfs/export

[root@blockchain42 data1]# export ipfs_data=/data/ipfs/data

10 docker 启动

[root@blockchain42 data1]# docker run -d --name ipfs_host --restart="always" --privileged=true -v $ipfs_staging:/export -v $ipfs_data:/data/ipfs -p 4001:4001 -p 127.0.0.1:8080:8080 -p 5001:5001 ipfs/go-ipfs:latest

Unable to find image 'ipfs/go-ipfs:latest' locally
latest: Pulling from ipfs/go-ipfs
5497949500d2: Pull complete
9cfd2e6d2b64: Pull complete
8167893b973a: Pull complete
0f61f69d653d: Pull complete
8a98c133507f: Pull complete
e9bc9df9b0ba: Pull complete
b5b58acfc7ee: Pull complete
385a82e0ccbb: Pull complete
Digest: sha256:31cc5713ef3e3e81bf868cbb56c19de2d15d661743d8b6077804dee26e929ac5
Status: Downloaded newer image for ipfs/go-ipfs:latest
WARNING: IPv4 forwarding is disabled. Networking will not work.
e48224ac7e15ed3aab532b6a79d6077ab376a5a84c6a66b1f2444b0779271322

10.1 查看是否启动成功

[root@blockchain42 data1]# docker logs -f ipfs_host1
Changing user to ipfs
ipfs version 0.4.15
Found IPFS fs-repo at /data/ipfs
Initializing daemon...
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/172.17.0.6/tcp/4001
Swarm listening on /p2p-circuit/ipfs/QmdafoEj6roToSiACimBxUhgdTa46gNfsfsNEKcqY8A6oP
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/172.17.0.6/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安装启动完成、
以相同的步骤在另一台机器上在部署一套

10.2 查看节点信息

[root@blockchain40 ~]# docker exec ipfs_host ipfs swarm peers
/ip4/172.17.0.3/tcp/4001/ipfs/QmUjD1DQwxfSVkac12mK74ozhe34eoxX7DoJTFev2NemFd

或者查看ipfs id

[root@blockchain40 ~]# docker exec ipfs_host ipfs id
{
    "ID": "QmUdmCCbmt5cQzPZST7U5ceaVdoCiHe2ZpxHopce5gFoXp",
    "PublicKey": "CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC1u+LC40JsmMVMemNiRu7n9OEaiJDSh78WWgqzER3KuuUrBJDyO7FW/UG4jtT2hoPLpsfZtw0LsPO+LNQY6Je78AMYB6It0bQ9yLLI8crpYhIrPXdL9MxYi6E+ITiyz+64SVLlDbW/7q5xvMLr2jfQHTxrmBhkkULfqX0unBR3tm9AnhfN1Gwi+xrAYw1aZmN53cj2h12oWFZzLgd9XmWQtx5+32U+qECCfqQ9JnQVSy8LGKis3ZlgHSIg0m7upc3h7p/RQU1QWW4NHdW3KvSMB6QSIufUSc+rQ4rIz5QdWAv+iuXp89l2mialJbJ5sCHqyL6vCo/OHgkDPPOYlyx5AgMBAAE=",
    "Addresses": [
        "/ip4/127.0.0.1/tcp/4001/ipfs/QmUdmCCbmt5cQzPZST7U5ceaVdoCiHe2ZpxHopce5gFoXp",
        "/ip4/172.17.0.2/tcp/4001/ipfs/QmUdmCCbmt5cQzPZST7U5ceaVdoCiHe2ZpxHopce5gFoXp"
    ],
    "AgentVersion": "go-ipfs/0.4.15/",
    "ProtocolVersion": "ipfs/0.1.0"
}

10.3修改链接ip

/ip4/10.19.0.40/tcp/4001/ipfs/QmUdmCCbmt5cQzPZST7U5ceaVdoCiHe2ZpxHopce5gFoXp

10.4添加peer

[root@blockchain42 ~]# docker exec ipfs_host ipfs swarm connect /ip4/10.19.0.40/tcp/4001/ipfs/QmUdmCCbmt5cQzPZST7U5ceaVdoCiHe2ZpxHopce5gFoXp
connect QmUdmCCbmt5cQzPZST7U5ceaVdoCiHe2ZpxHopce5gFoXp success

11 测试


[root@blockchain40 export]#  docker exec ipfs_host ipfs add /export/yangxing
added QmaKK2vxX4bGzXrnxdCuGBCBx6RAmez6TGtVXxE4c5QDst yangxing


[root@blockchain42 ~]# docker exec ipfs_host ipfs cat QmaKK2vxX4bGzXrnxdCuGBCBx6RAmez6TGtVXxE4c5QDst
asydfklsajdflkjsaldfjks

有疑问加站长微信联系(非本文作者)

本文来自:Segmentfault

感谢作者:阅历笔记

查看原文:IPFS集群搭建记录

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

874 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传