如何使用 raft 在正在运行的超级账本结构网络中添加新的排序器



我想向现有的正在运行的网络添加新的排序器。目前我的网络如下:

码头工人 PS -a

CONTAINER ID        IMAGE                               COMMAND                  CREATED              STATUS              PORTS                                        NAMES
998b93eb81c6        hyperledger/fabric-tools:latest     "/bin/bash"              About a minute ago   Up About a minute                                                cli
87bada2d914b        hyperledger/fabric-orderer:latest   "orderer"                About a minute ago   Up About a minute   0.0.0.0:8050->7050/tcp                       orderer2.example.com
5907f35bb5b4        hyperledger/fabric-orderer:latest   "orderer"                About a minute ago   Up About a minute   0.0.0.0:8750->7050/tcp                       orderer6.example.com
7876e35f2fb9        hyperledger/fabric-orderer:latest   "orderer"                About a minute ago   Up About a minute   0.0.0.0:10050->7050/tcp                      orderer4.example.com
fba3185ec9c6        hyperledger/fabric-peer:latest      "peer node start"        About a minute ago   Up About a minute   0.0.0.0:7051->7051/tcp                       peer0.org1.example.com
8b5e4348f04c        hyperledger/fabric-orderer:latest   "orderer"                About a minute ago   Up About a minute   0.0.0.0:9050->7050/tcp                       orderer3.example.com
a5cffb73ceca        hyperledger/fabric-couchdb          "tini -- /docker-ent…"   About a minute ago   Up About a minute   4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp   couchdb0
6be4405ec45b        hyperledger/fabric-orderer:latest   "orderer"                About a minute ago   Up About a minute   0.0.0.0:11050->7050/tcp                      orderer5.example.com
790c9aa84911        hyperledger/fabric-orderer:latest   "orderer"                About a minute ago   Up About a minute   0.0.0.0:8055->7050/tc

我尝试在 etcDraft 文件中添加排序器,但它不起作用。我在这里使用第一网络。

您可以按照以下步骤在 RAFT 共识协议设置中添加新的排序器。这是一个漫长的过程,所以我稍后也会添加一个脚本,但现在您可以按照以下步骤操作。在这里,我使用结构示例中的第一个网络来启动具有 5 个排序器的网络。

  1. 首先在 OrdererOrgs 下的加密配置中: 规格:为您的排序者创建一个新的主机名(使用与另一个相同的域和名称)。

  2. 然后,运行命令cryptogen extend --config=./crypto-config.yaml注意:"扩展"部分,以便它生成您需要的内容,而不是重新生成所有内容。

  3. 现在首先我们将排序器添加到系统通道,然后当它具有系统通道的所有块时,我们会将其移动到应用程序通道中,因此请确保您正确执行此操作。

  4. 使用docker exec -it cli bash进入您的 cli 容器并使用活动的排序器信息引导它,因为您将需要OrdererMSP来签署此更改。

以下是使用排序器引导 cli 所需的一些环境变量:

CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin@example.com/msp
CORE_PEER_ADDRESS=orderer.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/orderer.example.com/tls/ca.crt
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
CHANNEL_NAME=[system-channel-name]
  1. 接下来是确保所有二进制文件都在 cli 容器中工作,因为我们将在此处使用 jq 和configtxlator工具将块从 protobuf 转换为json并返回

  2. 获取最新的配置块:peer channel fetch config config_block.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA

  3. 转换为 json 并修剪标头:configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config > config.json

  4. 打开 JSON 文件查找">共识类型">部分,在该标题下应该有另一个标签"同意者"。现在,您必须在上面创建的最新排序器的此部分中添加新的TLS证书。但是这里的证书是 Base64 编码形式,因此首先您必须寻找您的 tlscert,然后您必须在base64中进行转换,然后将其插入本节。

就我而言,tls 证书在这里:

crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt

现在将其添加到上面给出的部分中,就像其他人提到的那样:

{
"client_tls_cert": "xxxxxxxxxxxx",
"host": "new_orderer.example.com",
"port": 7050,
"server_tls_cert": "xxxxxxxxxxxx"
}

添加 base64 编码的证书而不是上面给出的 xxxxxxx,并将更改另存为modified_config.json

  1. 将步骤 6 中的 json 转换为阻止configtxlator proto_encode --input config.json --type common.Config --output config.pb

  2. 将步骤 7 中的 json 转换为块configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb

  3. 计算步骤 8 和 9 中块之间的增量:configtxlator compute_update --channel_id $CHANNEL_NAME --original config.pb --updated modified_config.pb --output orderer_update.pb

  4. 将增量更改回 JSON:configtxlator proto_decode --input orderer_update.pb --type common.ConfigUpdate | jq . > orderer_update.json

  5. 现在,我们有一个解码的更新文件 - orderer_update.json - 我们需要将其包装在信封消息中。此步骤将返回我们之前删除的标头字段。我们将此文件命名为:orderer_update_in_envelope.json

echo '{"payload":{"header":{"channel_header":{"channel_id":"$CHANNEL_NAME", "type":2}},"data":{"config_update":'$(cat orderer_update.json)'}}}' | jq . > orderer_update_in_envelope.json
  1. 现在我们将它转换回 Fabric 所需的完全成熟的 protobuf 格式。我们将最终更新对象命名为 orderer_update_in_envelope.pb
configtxlator proto_encode --input orderer_update_in_envelope.json --type common.Envelope --output orderer_update_in_envelope.pb
  1. 由于您的 cli 已经作为活动订购者引导,您可以提交它,因为提交方会给您一个免费签名,这是您唯一需要的签名:
peer channel update -f orderer_update_in_envelope.pb -c $CHANNEL_NAME -o orderer.example.com:7050 --tls --cafile $ORDERER_CA

通过检查获取的配置块是否包含(即将添加的)节点的证书,确保将添加的节点是系统通道的一部分。

    启动一个新的排序器容器,
  1. 该容器与另一个排序器基本相同,除了加密卷指向步骤 2 中生成的新加密(可能有不同的端口,具体取决于您的设置)。最重要的是将此排序器与最新的配置块合并,为此您必须获取配置块
peer channel fetch config config_block.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA

然后,将此配置块移动到通道工件文件夹,并将此env 变量的路径添加到 Orderer 的 docker-compose 文件中:

ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block

启动您的排序器后,您可能会注意到此时它已连接到木筏并且 Steprequest 成功并且具有您的通道和块,因为它使用相同的创世块。需要做的是网络需要知道这个新排序者的地址。

  1. >等待 Raft节点从现有节点复制其证书添加到的所有通道的块。完成此步骤后,节点开始为通道提供服务。

  2. 将新添加的 Raft 节点的端点添加到系统通道的通道配置中,为此您必须再次重复通道更新事务的整个过程,就像我们之前从 (5th 到 14th) 所做的那样,您唯一需要做的不同的事情是在步骤 7 中您必须这样做:

打开 json 文件查找">OrdererAddresses">部分,在该标题下应该有另一个标签"地址"。为该数组中的新排序程序终结点添加新的 IP 和端口。将更改另存为 modified_config.json,然后按上述方式执行其余操作。

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

  1. 现在您必须通过将其添加到应用程序通道来重复所有步骤,为此只需在 docker 环境变量中更改它:
CHANNEL_NAME=[application-channel-name]

您必须将相同的 tls 证书添加到同意者部分,然后在复制应用程序通道的块后,您可以在地址部分添加排序者的终结点,然后它将开始反映您将对应用程序通道所做的所有最新更改。

最新更新