ipfs cluster 模式部署使用(docker-compose 环境运行)

ipfs 点对点的分布式文件系统,官方提供了集群模式运行的docker 镜像,以及docker-compose 文件
所以测试下

环境准备

  • docker-compose
 
version: '3.4'
# This is an example docker-compose file for IPFS Cluster
# It runs two Cluster peers (cluster0, cluster1) attached to two
# IPFS daemons (ipfs0, ipfs1).
#
# It expects a "compose" subfolder as follows where it will store configurations
# and states permanently:
#
# compose/
# |-- cluster0
# |-- cluster1
# |-- ipfs0
# |-- ipfs1
#
# 
# During the first start, default configurations are created for all peers.
services:
##################################################################################
## Cluster PEER 0 ################################################################
##################################################################################
  ipfs0:
    container_name: ipfs0
    image: ipfs/go-ipfs:release
    ports:
          - "4001:4001" # ipfs swarm
          - "5001:5001" # expose if needed/wanted
          - "8080:8080" # exposes if needed/wanted
    volumes:
      - ./compose/ipfs0:/data/ipfs
      - ./compose/export0:/export
  cluster0:
    container_name: cluster0
    image: ipfs/ipfs-cluster:latest
    depends_on:
      - ipfs0
    environment:
      CLUSTER_SECRET: 3d4aa5422351fabcb0a93d201fb2751f4f3b8a5080f210b775409ca25ba86b49 # From shell variable
      IPFS_API: /dns4/ipfs0/tcp/5001
    ports:
          - "9094:9094" # API
          - "9096:9096" # Cluster IPFS Proxy endpoint
    volumes:
      - ./compose/cluster0:/data/ipfs-cluster
##################################################################################
## Cluster PEER 1 ################################################################
##################################################################################
  ipfs1:
    container_name: ipfs1
    image: ipfs/go-ipfs:release
    ports:
          - "4101:4001" # ipfs swarm
          - "5101:5001" # expose if needed/wanted
          - "8180:8080" # exposes if needed/wanted
    volumes:
      - ./compose/ipfs1:/data/ipfs
      - ./compose/export2:/export
  # cluster1 bootstraps to cluster0 if not bootstrapped before
  cluster1:
    container_name: cluster1
    image: ipfs/ipfs-cluster:latest
    depends_on:
      - cluster0
      - ipfs1
    environment:
      CLUSTER_SECRET: 3d4aa5422351fabcb0a93d201fb2751f4f3b8a5080f210b775409ca25ba86b49 # From shell variable
      IPFS_API: /dns4/ipfs1/tcp/5001
    ports:
          - "9194:9094" # API
          - "9196:9096" # Cluster IPFS Proxy endpoint
    volumes:
      - ./compose/cluster1:/data/ipfs-cluster
    entrypoint:
      - "/sbin/tini"
      - "--"
    # Translation: if state folder does not exist, find cluster0 id and bootstrap
    # to it.
    command: >-
      sh -c '
        cmd="daemon --upgrade"
        if [ ! -d /data/ipfs-cluster/raft ]; then
          while ! ipfs-cluster-ctl --host /dns4/cluster0/tcp/9094 id; do
            sleep 1
          done
          pid=`ipfs-cluster-ctl --host /dns4/cluster0/tcp/9094 id | grep -o -E "^(\w+)"`
          sleep 10
          cmd="daemon --bootstrap /dns4/cluster0/tcp/9096/ipfs/$$pid"
        fi
        exec /usr/local/bin/entrypoint.sh $$cmd
      '
# For adding more peers, copy PEER 1 and rename things to ipfs2, cluster2.
# Keep bootstrapping to cluster0.
 
 
  • 说明
    我在官方的基础上添加了secret ,方便直接运行,同时开启了网络访问
  • 效果

操作

  • 添加文件测试
    直接在export0 添加一个简单的静态页面就可以了
 
docker-compose exec ipfs0 sh
ipfs add -f /export/users
  • 效果
added QmQPZwCUtjjTnWiMuyS7un6T2WdHtxWfa5YyFqwwSp9UwF users/index.css
added QmSj9817rjvUYLCWXSxgMT89Sfr8jdYWJevrPDU2rACpvf users/index.html
added QmZEubFCffhFAfPro18PSt78M1mtR32wcC82y13so91zcN users
  • 访问文件
http://localhost:8080/ipfs/QmZEubFCffhFAfPro18PSt78M1mtR32wcC82y13so91zcN
http://localhost:8180/ipfs/QmZEubFCffhFAfPro18PSt78M1mtR32wcC82y13so91zcN
  • 效果

说明

ipfs cluster 的配置参数也挺多的,最好是参考官方文档,ipfs 是一个很不错的项目。

参考文档

https://cluster.ipfs.io/documentation/configuration/
https://github.com/rongfengliang/ipfs-clutser-docker-compose

posted on 2018-12-25 10:40  荣锋亮  阅读(2180)  评论(0编辑  收藏  举报

导航