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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2016-12-25 Sonar安装配置
2016-12-25 SpringCloud Sleuth 使用
2013-12-25 zeroMQ 学习
2013-12-25 SocketIO4Net.Client