欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

IPFS搭建&集群

程序员文章站 2022-05-04 14:04:17
下载go-ipfs 解压 执行insatll.sh 执行ipfs命令验证ipfs 创建data, export目录 设置ipfs_path 初始化ipfs 修改配置文件 设置ipfs_staging 和 ipfs_data docker 启动 查看是否启动成功 到这单节点ipfs安装启动完成、 以相 ......

下载go-ipfs

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

 

 解压

[root@blockchain42 ipfs]# tar -zxvf go-ipfs_v0.4.17_linux-amd64.tar.gz
  go-ipfs/build-loggo-ipfs/install.shgo-ipfs/ipfs
  go-ipfs/license
  go-ipfs/readme.md

执行insatll.sh

[root@blockchain42ipfs]# cd go-ipfs

[root@blockchain42go-ipfs]# ./install.sh
  moved ./ipfs to/usr/local/bin

执行ipfs命令验证ipfs

root@blockchain42 go-ipfs]# ipfs
 subcommands
  basic commands
    init          initialize ipfs localconfiguration
    add <path>    add a filetoipfs
    cat <ref>     show ipfs object data
    get<ref>     download ipfs objects
    ls <ref>      list links froman object
    refs <ref>    list hashes oflinks froman object

  data structure commands
    block         interact withraw blocks inthedatastore
    object        interact withraw dag nodes
    files         interact withobjects asifthey were a unix filesystem
    dag           interact withipld documents (experimental)

  advanced commands
    daemon        start a long-runningdaemon process
    mount         mount an ipfs read-only mountpoint
    resolve       resolve any type ofnamenamepublish andresolve ipns names
    key           create andlistipns namekeypairs
    dns           resolve dns links
    pin           pin objects tolocalstorage
    repo          manipulate theipfs repository
    stats         various operational stats
    p2p           libp2p stream mounting
    filestore     manage thefilestore (experimental)

  network commands
    idshow info aboutipfs peers
    bootstrap     add orremove bootstrap peers
    swarm         manage connections tothep2p network
    dht           query thedht forvalues orpeers
    ping          measure thelatency ofa connection
    diag          print diagnostics

  tool commands
    config        manage configuration
    versionshow ipfs versioninformation
    update        download andapply go-ipfs updates
    commands      list all available commands

  use 'ipfs <command> --help' to learn more about each command.ipfs uses a repository inthelocalfilesystem. by default, therepo islocated at~/.ipfs. to change therepo location, setthe$ipfs_path
  environment variable:

    export ipfs_path=/path/to/ipfsrepo

  exit status

  the cli will exitwithone ofthefollowing values:

  0successful execution.

 1failed executions.

创建data, export目录

[root@blockchain42ipfs]# mkdir data

[root@blockchain42ipfs]# mkdir export

设置ipfs_path

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

初始化ipfs

root@blockchain42 ipfs]# ipfs init

initializing ipfs node at /data/ipfs/data
generating 2048-bit rsa keypair...donepeer identity: qmcu1qxojgyv84hfrvvubblqzdlkka7kaau8puzi4djzie
togetstarted, enter:

    ipfs cat /ipfs/qms4ustl54uo8fzr9455qaxzwumiuhyvmcx9ba8nuh4uvv/readme

 

修改配置文件

[root@blockchain42 data]# cd data

[root@blockchain42 data]# vimconfig
删除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"],

 

设置ipfs_staging 和 ipfs_data

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

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

docker 启动

[root@blockchain42 data1]# docker run -d --name ipfs_host --restart="always"--privileged=true -v $ipfs_staging:/export -v $ipfs_data:/data/ipfs -p4001:4001-p127.0.0.1:8080:8080-p5001:5001ipfs/go-ipfs:latest
unable tofindimage 'ipfs/go-ipfs:latest'locally
latest:pulling from ipfs/go-ipfs
5497949500d2: pull complete9cfd2e6d2b64: pull complete8167893b973a:pull complete0f61f69d653d: pull complete8a98c133507f: pull completee9bc9df9b0ba:pull completeb5b58acfc7ee: pull complete385a82e0ccbb:pull completedigest:sha256:31cc5713ef3e3e81bf868cbb56c19de2d15d661743d8b6077804dee26e929ac5
status:downloaded newer image foripfs/go-ipfs:latestwarning: ipv4 forwarding isdisabled. networking will not work.
e48224ac7e15ed3aab532b6a79d6077ab376a5a84c6a66b1f2444b0779271322 

查看是否启动成功

[root@blockchain42 data1]# docker logs -f ipfs_host1
changinguser toipfs
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
apiserver 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安装启动完成、 以相同的步骤在另一台机器上在部署一套

查看节点信息

[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"} 

 

修改链接ip

/ip4/10.19.0.40/tcp/4001/ipfs/qmudmccbmt5cqzpzst7u5ceavdocihe2zpxhopce5gfoxp 

添加peer

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

 

测试

在一台上添加数据、另一台上去, 测试集群是否添加上

[root@blockchain40 export]#  docker exec ipfs_host ipfs add /export/yangxingadded qmakk2vxx4bgzxrnxdcugbcbx6ramez6tgtvxxe4c5qdst yangxing


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