You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求在现有Hyperledger Fabric网络中新增通道的操作指引

Hyperledger Fabric 新增专属通道操作步骤

1. 更新 configtx.yaml 通道配置

在现有 configtx.yaml 的 Profiles 段落下,新增两个专属通道的配置,仅包含目标组织:

Profiles:
  # 保留原有全组织通道配置
  AllOrgChannel:
    Consortium: SampleConsortium
    Application:
      <<: *ApplicationDefaults
      Organizations:
        - *Org1
        - *Org2
        - *Org3
  # 新增 Org1 + Org2 通道配置
  Org1Org2Channel:
    Consortium: SampleConsortium
    Application:
      <<: *ApplicationDefaults
      Organizations:
        - *Org1
        - *Org2
  # 新增 Org1 + Org3 通道配置
  Org1Org3Channel:
    Consortium: SampleConsortium
    Application:
      <<: *ApplicationDefaults
      Organizations:
        - *Org1
        - *Org3

注:SampleConsortium 为现有联盟名称,需与原配置保持一致;Org1、Org2、Org3 为配置中已定义的组织锚点。

2. 生成通道创世块

使用 configtxgen 工具分别生成两个通道的创世块文件:

# 生成 Org1-Org2 通道创世块,通道ID设为 org1-org2-channel
configtxgen -profile Org1Org2Channel -outputBlock ./channel-artifacts/org1-org2-channel.block -channelID org1-org2-channel

# 生成 Org1-Org3 通道创世块,通道ID设为 org1-org3-channel
configtxgen -profile Org1Org3Channel -outputBlock ./channel-artifacts/org1-org3-channel.block -channelID org1-org3-channel

3. 创建通道

选择 Org1 的 peer 节点(如 peer0.org1.example.com)执行通道创建命令:

# 进入节点容器
docker exec -it peer0.org1.example.com bash

# 设置当前节点环境变量(根据实际部署调整路径)
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp

# 创建 Org1-Org2 通道
peer channel create -o orderer.example.com:7050 -c org1-org2-channel -f ./channel-artifacts/org1-org2-channel.block --tls true --cafile /etc/hyperledger/fabric/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

# 重复上述命令,将通道ID和创世块文件替换为 org1-org3-channel,创建第二个通道

执行完成后,当前节点会生成对应通道的配置块文件(如 org1-org2-channel.block)。

4. 组织节点加入通道

针对 Org1-Org2 通道:

  • Org1 节点加入:
peer channel join -b org1-org2-channel.block
  • 将通道配置块复制到 Org2 的 peer 节点,并执行加入:
# 从 Org1 节点复制文件到本地主机
docker cp peer0.org1.example.com:/opt/gopath/src/github.com/hyperledger/fabric/peer/org1-org2-channel.block ./

# 将文件复制到 Org2 节点容器内
docker cp ./org1-org2-channel.block peer0.org2.example.com:/opt/gopath/src/github.com/hyperledger/fabric/peer/

# 进入 Org2 节点容器并设置环境变量
docker exec -it peer0.org2.example.com bash
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp

# 加入通道
peer channel join -b org1-org2-channel.block

针对 Org1-Org3 通道:

重复上述操作,将目标组织替换为 Org1 和 Org3,完成节点加入。

5. 更新通道锚节点

为每个通道配置锚节点,确保组织间 gossip 通信正常:

针对 Org1-Org2 通道:

  1. 生成锚节点配置更新文件:
# 生成 Org1 锚节点配置
configtxgen -profile Org1Org2Channel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors_org1-org2-channel.tx -channelID org1-org2-channel -asOrg Org1MSP

# 生成 Org2 锚节点配置
configtxgen -profile Org1Org2Channel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors_org1-org2-channel.tx -channelID org1-org2-channel -asOrg Org2MSP
  1. 在对应组织节点提交更新:
# Org1 节点提交锚节点更新
peer channel update -o orderer.example.com:7050 -c org1-org2-channel -f ./channel-artifacts/Org1MSPanchors_org1-org2-channel.tx --tls true --cafile /etc/hyperledger/fabric/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

# Org2 节点提交锚节点更新
peer channel update -o orderer.example.com:7050 -c org1-org2-channel -f ./channel-artifacts/Org2MSPanchors_org1-org2-channel.tx --tls true --cafile /etc/hyperledger/fabric/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

针对 Org1-Org3 通道:

重复上述操作,生成并提交 Org1 和 Org3 的锚节点配置更新。

6. 部署智能合约(可选)

若新通道需要独立的智能合约,执行以下步骤:

  1. 在目标组织的 peer 节点安装链码:
peer chaincode install -n org-channel-chaincode -v 1.0 -p github.com/chaincode/your-chaincode-path/
  1. 在其中一个节点实例化链码(设置背书策略):
# 以 Org1-Org2 通道为例,背书策略允许 Org1 或 Org2 的 peer 节点签名
peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile /etc/hyperledger/fabric/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C org1-org2-channel -n org-channel-chaincode -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer')"

7. 验证通道状态

在各节点执行以下命令,确认通道加入及链码部署状态:

# 查询当前节点已加入的通道
peer channel list

# 若部署了链码,查询链码状态(示例)
peer chaincode query -C org1-org2-channel -n org-channel-chaincode -c '{"Args":["query","your-key"]}'

内容的提问来源于stack exchange,提问作者Dhrumil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 13:32:04