如何将更多排序节点添加到 运行 hyperledger fabric 网络

How to add more orderer nodes to a running hyperledger fabric network

我已经设置了一个带有 1 个排序节点的超级账本结构网络,但不知道如何向 运行 生产超级账本网络添加更多排序节点。

如有任何帮助,我们将不胜感激。

首先,您的网络订购服务必须设置为 Kafka 服务,而不是独立服务。您可以在 OrdererType 下的 configtx.yaml 文件中执行此操作。然后,您还必须创建 kafka 代理、zookeeper 并配置所有这些。如果您对此不熟悉,我发现试验和研究此存储库 https://github.com/keenkit/fabric-sample-with-kafka 非常有帮助。

假设您有一个带有 Kafka 排序服务的工作网络,添加一个额外的排序器是通过通道更新完成的,这与添加一个新组织非常相似。涉及的步骤很多,但都在此处列出并进行了解释 http://hyperledger-fabric.readthedocs.io/en/release-1.1/channel_update_tutorial.html。我建议您首先了解添加组织的工作原理,但如果您觉得合适,那么添加订购者的唯一区别是:

  • 显然不需要创建新的组织加密 materials 但您需要为另一个排序者 materials 创建加密
  • 而不是 运行 将新组织密码 material 添加到网络的命令 jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./channel-artifacts/org3.json > modified_config.json,打开 json 文件并查找 "OrdererAddresses".在另一个标签 "addresses" 下应该有一个排序器数组。在此处添加您的订购者并将文件另存为 modified_config.json。然后,您可以 运行 继续执行相同的命令。
  • 当您使用 peer channel signconfigtx -f org3_update_in_envelope.pb bootstrap 您的 CLI 与活跃的订购者签署信封并使用 OrdererMSP 时,否则订购者将拒绝您的交易。用于添加新组织的组织 MSP 将不起作用。

为了帮助解决问题,我发现最初启动上面 github 回购创建的 2 个订购者设置,然后测试删除 1 个订购者,然后将其重新添加进去更容易。在进一步实验之后添加第三个。

作为旁注,您可以在此处找到可以通过频道更新更改的所有其他内容:http://hyperledger-fabric.readthedocs.io/en/release-1.1/config_update.html。单击 "Click here to see the config" 查看 json 配置的示例(注意:示例是 solo 而不是 Kafka)。

逐步(按要求):

  1. 在 OrdererOrgs 下的 crypto-config 中:规范:为您的订购者创建一个新的主机名(使用与其他人相同的域名和名称)。
  2. 运行 命令 cryptogen extend --config=./crypto-config.yaml 注意:'extend' 部分会生成您需要的内容,而不是重新生成所有内容。
  3. 启动一个新的排序器容器,它与另一个排序器基本相同,除了加密卷指向在步骤 2 中生成的新加密(可能是不同的端口,具体取决于您的设置)。您可能会注意到此时它已连接到 kafka 代理并具有您的通道和块,因为它使用相同的创世块。不过需要做的是让网络知道这个新订购者的地址。
  4. docker exec -it cli bash 到您的 CLI 容器中,并 bootstrap 它带有活动的订购者信息,因为您需要 OrdererMSP 签署此更改。

Bootstrap 例如(你的可能不同):CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin@example.com/msp

CORE_PEER_ADDRESS=orderer0.example.com:7050

CORE_PEER_LOCALMSPID=OrdererMSP

CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/tls/ca.crt

ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

CHANNEL_NAME=mychannel

  1. 在 CLI 容器中安装 jq 以将块转换为 json 并返回 apt update && apt install -y jq
  2. 获取最新的配置块peer channel fetch config config_block.pb -o orderer0.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
  3. 转换为 json 和 trim headers configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config > config.json
  4. 打开 json 文件查找 "OrdererAddresses",在该标题下应该有另一个标签 "addresses"。在该数组中为新订购者添加新 IP 和端口。将更改保存为 modified_config.json
  5. 隐藏 json 形成第 7 步以阻止 configtxlator proto_encode --input config.json --type common.Config --output config.pb
  6. 将 json 从步骤 8 转换为块 configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb
  7. 计算步骤 9 和步骤 10 中块之间的增量 configtxlator compute_update --channel_id $CHANNEL_NAME --original config.pb --updated modified_config.pb --output org3_update.pb
  8. 将增量改回 json configtxlator proto_decode --input org3_update.pb --type common.ConfigUpdate | jq . > org3_update.json
  9. 将 json 包裹在 header echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":'$(cat org3_update.json)'}}}' | jq . > org3_update_in_envelope.json
  10. 将其转换回块 configtxlator proto_encode --input org3_update_in_envelope.json --type common.Envelope --output org3_update_in_envelope.pb
  11. 由于您是 bootstrap 作为活跃的订购者,您可以提交它,因为提交方会为您提供免费签名,并且这是您唯一需要的签名 peer channel update -f org3_update_in_envelope.pb -c $CHANNEL_NAME -o orderer0.example.com:7050 --tls --cafile $ORDERER_CA

一旦你的同行得到这个新区块,他们现在就知道新订购者的地址并可以联系它。

除了 Antonio 的回答之外,您还需要将系统通道的创世块批量添加到您的新订购者中。

可以从已有的orderer中获取,通道名称选择为testchainid(default name)