美文网首页
fabric 2.3系统通道

fabric 2.3系统通道

作者: yuan1028 | 来源:发表于2021-01-21 16:40 被阅读0次

Orderer Without System Channel

为了简化创建通道的过程并提升通道的私密性和扩展性,2.3支持无系统通道创建应用通道的功能。

  • 不再需要系统通道:
  • 不再需要财团(Consortium):
  • 简化了排序节点的启动流程

目前2.3版本支持有系统通道和无系统通道两种模式的排序节点。

  • 如果是有系统通道的模式,那么是不支持channel joinchannel remove操作的,同样如果是使用solo模式或者kafka模式,两者也不支持。
  • 不支持混合模式,即不支持已经有了系统通道,又需要通过无系统通道来建立新的应用通道。这种情况需要按照原有的创建通道方法,或者需要先将系统通道移除。

osnadmin

在无系统通道的情况下,可以通过osnadmin命令来进行通道创建和移除操作。

开启osnadmin服务需要配置文件orderer.yaml中的相关项

General:    
    # Bootstrap method: The method by which to obtain the bootstrap block
    # system channel is specified. The option can be one of:
    #   "file" - path to a file containing the genesis block or config block of system channel
    #   "none" - allows an orderer to start without a system channel configuration
    BootstrapMethod: none 
    
################################################################################
#
#   Admin Configuration
#
#   - This configures the admin server endpoint for the orderer
#
################################################################################
Admin:
    # host and port for the admin server
    ListenAddress: 127.0.0.1:9443

    # TLS configuration for the admin endpoint
    TLS:
        # TLS enabled
        Enabled: false

        # Certificate is the location of the PEM encoded TLS certificate
        Certificate:

        # PrivateKey points to the location of the PEM-encoded key
        PrivateKey:

        # Most admin service endpoints require client authentication when TLS
        # is enabled. ClientAuthRequired requires client certificate authentication
        # at the TLS layer to access all resources.
        #
        # NOTE: When TLS is enabled, the admin endpoint requires mutual TLS. The
        # orderer will panic on startup if this value is set to false.
        ClientAuthRequired: true

        # Paths to PEM encoded ca certificates to trust for client authentication
        ClientRootCAs: []

################################################################################
#
#   Channel participation API Configuration
#
#   - This provides the channel participation API configuration for the orderer.
#   - Channel participation uses the ListenAddress and TLS settings of the Admin
#     service.
#
################################################################################
ChannelParticipation:
    # Channel participation API is enabled.
    Enabled: false

    # The maximum size of the request body when joining a channel.
    MaxRequestBodySize: 1 MB

其中

  • General.BootstrapMethod:将该字段设置为none,即代表排序节点将以无系统通道方式启动
  • Admin.ListenAddress:排序节点的Admin服务,之后使用osnadmin命令的时候需要联接到该服务上,配置格式为host:port
  • Admin.TLS.Enabled:排序节点Admin服务是否开启TLS,默认为false,但是建议设置为true
  • Admin.TLS.PrivateKey:排序节点Admin服务开启TLS时所使用的私钥文件路径
  • Admin.TLS.Certificate:排序节点Admin服务开启TLS时所使用的证书文件路径
  • Admin.TLS.ClientAuthRequired:排序节点Admin服务开启TLS时,是否需要开启客户端的双向验证。建议配置为true
  • Admin.TLS.ClientRootCAs:排序节点Admin服务开启TLS时,允许的客户端的根CA证书
  • ChannelParticipation.Enabled:使用无系统通道,该字段必须设置为true

可以在docker-compose中按如下配置

- ORDERER_GENERAL_BOOTSTRAPMETHOD=none
- ORDERER_ADMIN_LISTENADDRESS=0.0.0.0:9443
- ORDERER_ADMIN_TLS_ENABLED=true
- ORDERER_ADMIN_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
- ORDERER_ADMIN_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
- ORDERER_ADMIN_TLS_CLIENTAUTHREQUIRED=true
- ORDERER_ADMIN_TLS_CLIENTROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
- ORDERER_CHANNELPARTICIPATION_ENABLED=true

#ports:
#      - 9443:9443 #记得添加端口

客户端设置相关tls证书

export ADMIN_TLS_PRIVATE_KEY=./organizations/ordererOrganizations/example.com/users/Admin\@example.com/tls/client.key
export ADMIN_TLS_SIGN_CERT=./organizations/ordererOrganizations/example.com/users/Admin\@example.com/tls/client.crt
export OSN_TLS_CA_ROOT_CERT=./organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
export ORDERER_ADMIN_LISTENADDRESS=localhost:9443
  • osnadmin channel list: 显示orderer节点的通道列表
osnadmin channel list -o $ORDERER_ADMIN_LISTENADDRESS --ca-file $OSN_TLS_CA_ROOT_CERT --client-cert $ADMIN_TLS_SIGN_CERT --client-key $ADMIN_TLS_PRIVATE_KEY

结果示例

Status: 200
{
    "systemChannel": null,
    "channels": null
}

无系统通道下使用osnadmin创建应用通道

  1. 首先需要生成通道的genesis_block.pb文件

例如在configtx.yaml中配置

#加在configtx.yaml末尾,注意缩进
SampleAppGenesisEtcdRaft:
        <<: *ChannelDefaults
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
            Capabilities:
                <<: *OrdererCapabilities
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org1
                - *Org2

使用configtxgen生成genesis_block.pb文件,注意这里-outputBlock,而不是-outputCreateChannelTx(之前用来生成创建通道的交易的命令)。

export FABRIC_CFG_PATH=../config
configtxgen -profile SampleAppGenesisEtcdRaft -outputBlock genesis_block.pb -channelID mychannel -configPath configtx/
  1. 使用osnadmin channel join将orderer节点加入到通道中
osnadmin channel join --channel-id mychannel  --config-block genesis_block.pb -o orderer.example.com:9443 --ca-file $OSN_TLS_CA_ROOT_CERT --client-cert $ADMIN_TLS_SIGN_CERT --client-key $ADMIN_TLS_PRIVATE_KEY

返回

Status: 201
{
    "name": "channel2",
    "url": "/participation/v1/channels/mychannel",
    "consensusRelation": "consenter",
    "status": "active",
    "height": 1
}

如果该应用通道需要有多个raft节点,需要逐一使用join命令来添加

  1. peer节点加入到通道中
peer channel fetch config -o orderer.example.com:7050 -c mychannel --tls --cafile $ORDERER_CA
peer channel join -b mychannel_config.block

orderer删除通道(是指单个节点)

  • 如果orderer节点是raft集群中的节点,则可以首先更新配置将该orderer节点从集群中移除
  • 使用osnadmin channel remove删除通道
osnadmin channel remove --channel-id mychannel -o orderer.example.com:9443 --ca-file $OSN_TLS_CA_ROOT_CERT --client-cert $ADMIN_TLS_SIGN_CERT --client-key $ADMIN_TLS_PRIVATE_KEY
  • 如果该orderer节点是该通道唯一的orderer节点,则该通道就会无法在接受新的交易

排序节点是否参与共识

  • 任何一个一个拥有通道读策略的排序节点,都可以通过osnadmin channel join加入到通道里,同步区块,如果其不参与raft共识,则它并不是一个consenter。
  • 通道配置中的etcd consenter中的排序节点才是会参与raft共识的节点。
  • 当需要新增一个raft节点的时候,可以考虑先使用osnadmin channel join加入到通道里,同步区块,等区块同步完成后,再更新通道配置将其变更为一个参与共识的consenter节点。

没有系统通道下的一些其它尝试

  • 发送invoke的消息,-o指定一个follower会返回channel creation request not allowed because the orderer system channel is not defined错误。
  • 节点必须执行osnadmin channel join之后才可以同步区块。

相关文章

网友评论

      本文标题:fabric 2.3系统通道

      本文链接:https://www.haomeiwen.com/subject/zkrdzktx.html