1. 首页
  2. 文档
  3. IPFS集群 | IPFS Cluster
  4. 用户指南 | User Guides
  5. 快速入门:启动,扩大和缩小群集

快速入门:启动,扩大和缩小群集

本指南将向您展示如何:

  • 设置,初始化并启动集群对等节点
  • 引导更多对等节点(增加集群的大小)
  • 从集群中删除对等节点

请注意,它假定您在主机中运行了IPFS守护程序,并且已正确安装 IPFS集群  。

如果要在同一台计算机上运行它,则需要:

  • 为每个节点使用不同的配置文件夹(ipfs-cluster-service -c 选项)
  • 更新配置中的所有listen地址,以便在启动节点之前他们不会发生冲突。

第0步:运行第一个集群对等节点

此步骤将创建单节点集群。

首先,创建一个将用于所有集群对等节点的密钥:

node0 $ export CLUSTER_SECRET=$(od  -vN 32 -An -tx1 /dev/urandom | tr -d ' \n')
node0 $ echo $CLUSTER_SECRET
9a420ec947512b8836d8eb46e1c56fdb746ab8a78015b9821e6b46b38344038f

第二次初始化配置:

node0 $ ipfs-cluster-service init
INFO     config: Saving configuration config.go:311
ipfs-cluster-service configuration written to /home/hector/.ipfs-cluster/service.json

然后运行  ipfs-cluster-service

node0> ipfs-cluster-service daemon
INFO    cluster: IPFS Cluster v0.3.0 listening on: cluster.go:91
INFO    cluster:         /ip4/127.0.0.1/tcp/9096/ipfs/QmZjSoXUQgJ9tutP1rXjjNYwTrRM9QPhmD9GHVjbtgWxEn cluster.go:93
INFO    cluster:         /ip4/192.168.1.2/tcp/9096/ipfs/QmZjSoXUQgJ9tutP1rXjjNYwTrRM9QPhmD9GHVjbtgWxEn cluster.go:93
INFO  consensus: starting Consensus and waiting for a leader... consensus.go:61
INFO  consensus: bootstrapping raft cluster raft.go:108
INFO    restapi: REST API: /ip4/127.0.0.1/tcp/9094 restapi.go:266
INFO   ipfshttp: IPFS Proxy: /ip4/127.0.0.1/tcp/9095 -> /ip4/127.0.0.1/tcp/5001 ipfshttp.go:159
INFO  consensus: Raft Leader elected: QmZjSoXUQgJ9tutP1rXjjNYwTrRM9QPhmD9GHVjbtgWxEn raft.go:261
INFO  consensus: Raft state is catching up raft.go:273
INFO  consensus: Consensus state is up to date consensus.go:116
INFO    cluster: Cluster Peers (without including ourselves): cluster.go:450
INFO    cluster:     - No other peers cluster.go:452
INFO    cluster: IPFS Cluster is ready cluster.go:461

步骤1:向集群添加新成员

在不同的节点中初始化并运行集群,将它们引导到第一个节点:

node1> export CLUSTER_SECRET=<copy from node0>
node1> ipfs-cluster-service init
INFO     config: Saving configuration config.go:311
ipfs-cluster-service configuration written to /home/hector/.ipfs-cluster/service.json
node1> ipfs-cluster-service daemon --bootstrap /ip4/192.168.1.2/tcp/9096/ipfs/QmZjSoXUQgJ9tutP1rXjjNYwTrRM9QPhmD9GHVjbtgWxEn
INFO    cluster: IPFS Cluster v0.3.0 listening on: cluster.go:91
INFO    cluster:         /ip4/127.0.0.1/tcp/10096/ipfs/QmYFYwnFUkjFhJcSJJGN72wwedZnpQQ4aNpAtPZt8g5fCd cluster.go:93
INFO    cluster:         /ip4/192.168.1.3/tcp/10096/ipfs/QmYFYwnFUkjFhJcSJJGN72wwedZnpQQ4aNpAtPZt8g5fCd cluster.go:93
INFO  consensus: starting Consensus and waiting for a leader... consensus.go:61
INFO  consensus: bootstrapping raft cluster raft.go:108
INFO    cluster: Bootstrapping to /ip4/127.0.0.1/tcp/9096/ipfs/QmZjSoXUQgJ9tutP1rXjjNYwTrRM9QPhmD9GHVjbtgWxEn cluster.go:471
INFO    restapi: REST API: /ip4/127.0.0.1/tcp/10094 restapi.go:266
INFO   ipfshttp: IPFS Proxy: /ip4/127.0.0.1/tcp/10095 -> /ip4/127.0.0.1/tcp/5001 ipfshttp.go:159
INFO  consensus: Raft Leader elected: QmZjSoXUQgJ9tutP1rXjjNYwTrRM9QPhmD9GHVjbtgWxEn raft.go:261
INFO  consensus: Raft state is catching up raft.go:273
INFO  consensus: Consensus state is up to date consensus.go:116
INFO  consensus: Raft Leader elected: QmZjSoXUQgJ9tutP1rXjjNYwTrRM9QPhmD9GHVjbtgWxEn raft.go:261
INFO  consensus: Raft state is catching up raft.go:273
INFO    cluster: QmYFYwnFUkjFhJcSJJGN72wwedZnpQQ4aNpAtPZt8g5fCd: joined QmZjSoXUQgJ9tutP1rXjjNYwTrRM9QPhmD9GHVjbtgWxEn's cluster cluster.go:777
INFO    cluster: Cluster Peers (without including ourselves): cluster.go:450
INFO    cluster:     - QmZjSoXUQgJ9tutP1rXjjNYwTrRM9QPhmD9GHVjbtgWxEn cluster.go:456
INFO    cluster: IPFS Cluster is ready cluster.go:461
INFO     config: Saving configuration config.go:311

您可以使用任何其他节点重复此过程。

您可以检查集群对等节点的当前列表,并查看它显示2个对等节点:

node1 > ipfs-cluster-ctl peers ls
QmYFYwnFUkjFhJcSJJGN72wwedZnpQQ4aNpAtPZt8g5fCd | Sees 1 other peers
  > Addresses:
    - /ip4/127.0.0.1/tcp/10096/ipfs/QmYFYwnFUkjFhJcSJJGN72wwedZnpQQ4aNpAtPZt8g5fCd
    - /ip4/192.168.1.3/tcp/10096/ipfs/QmYFYwnFUkjFhJcSJJGN72wwedZnpQQ4aNpAtPZt8g5fCd
  > IPFS: Qmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    - /ip4/127.0.0.1/tcp/4001/ipfs/Qmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    - /ip4/192.168.1.3/tcp/4001/ipfs/Qmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
QmZjSoXUQgJ9tutP1rXjjNYwTrRM9QPhmD9GHVjbtgWxEn | Sees 1 other peers
  > Addresses:
    - /ip4/127.0.0.1/tcp/9096/ipfs/QmZjSoXUQgJ9tutP1rXjjNYwTrRM9QPhmD9GHVjbtgWxEn
    - /ip4/192.168.1.2/tcp/9096/ipfs/QmZjSoXUQgJ9tutP1rXjjNYwTrRM9QPhmD9GHVjbtgWxEn
  > IPFS: Qmbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
    - /ip4/127.0.0.1/tcp/4001/ipfs/Qmbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
    - /ip4/192.168.1.2/tcp/4001/ipfs/Qmbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

第2步:删除不再需要的节点

您可以使用  ipfs-cluster-ctl peers rm <peer_id> 从集群中删除和断开任何节点。节点将自动关闭。可以手动重新启动它们并随时重新添加到集群:

node0> ipfs-cluster-ctl peers rm QmYFYwnFUkjFhJcSJJGN72wwedZnpQQ4aNpAtPZt8g5fCd

node1 会断开并关闭,它的日志会显示:

INFO     config: Saving configuration config.go:311
INFO    cluster: this peer has been removed and will shutdown cluster.go:386
INFO    cluster: shutting down Cluster cluster.go:498
INFO  consensus: stopping Consensus component consensus.go:159
INFO  consensus: consensus data cleaned consensus.go:400
INFO    monitor: stopping Monitor peer_monitor.go:161
INFO    restapi: stopping Cluster API restapi.go:284
INFO   ipfshttp: stopping IPFS Proxy ipfshttp.go:534
INFO pintracker: stopping MapPinTracker maptracker.go:116
INFO     config: Saving configuration config.go:311

干净关闭的节点将保持无状态,并且可以再次自举。集群中的引导地址会自动保存到配置中。

这篇文章对你有帮助吗?

我们要如何帮助您?