版权声明:忠于祖国,忠于人民 https://blog.csdn.net/boss2967/article/details/84204506
陈述
主要讲Fabric怎样生成创始块文件和通道文件
创始块文件和通道文件的生成
命令介绍
$ configtxgen --help
# 输出创始块区块文件的路径和名字
`-outputBlock string`
# 指定创建的channel的名字, 如果没指定系统会提供一个默认的名字.
`-channelID string`
# 表示输通道文件路径和名字
`-outputCreateChannelTx string`
# 指定配置文件中的节点
`-profile string`
# 更新channel的配置信息
`-outputAnchorPeersUpdate string`
# 指定所属的组织名称
`-asOrg string`
# 要想执行这个命令, 需要一个配置文件 configtx.yaml
创始块/通道文件的生成
-
配置文件的编写 - 参考模板
--- ################################################################################ # # Section: Organizations # # - This section defines the different organizational identities which will # be referenced later in the configuration. # ################################################################################ Organizations: # 固定的不能改 - &OrdererOrg # 排序节点组织, 自己起个名字 Name: OrdererOrg # 排序节点的组织名 ID: OrdererMSP # 排序节点组织的ID MSPDir: crypto-config/ordererOrganizations/example.com/msp # 组织的msp账号信息 - &Org1 # 第一个组织, 名字自己起 Name: Org1MSP # 第一个组织的名字 ID: Org1MSP # 第一个组织的ID MSPDir: crypto-config/peerOrganizations/org1.example.com/msp AnchorPeers: # 锚节点 - Host: peer0.org1.example.com # 指定一个peer节点的域名 Port: 7051 # 端口不要改 - &Org2 Name: Org2MSP ID: Org2MSP MSPDir: crypto-config/peerOrganizations/org2.example.com/msp AnchorPeers: - Host: peer0.org2.example.com Port: 7051 ################################################################################ # # SECTION: Capabilities, 在fabric1.1之前没有, 设置的时候全部设置为true # ################################################################################ Capabilities: Global: &ChannelCapabilities V1_1: true Orderer: &OrdererCapabilities V1_1: true Application: &ApplicationCapabilities V1_2: true ################################################################################ # # SECTION: Application # ################################################################################ Application: &ApplicationDefaults Organizations: ################################################################################ # # SECTION: Orderer # ################################################################################ Orderer: &OrdererDefaults # Available types are "solo" and "kafka" # 共识机制 == 排序算法 OrdererType: solo # 排序方式 Addresses: # orderer节点的地址 - orderer.example.com:7050 # 端口不要改 # BatchTimeout,MaxMessageCount,AbsoluteMaxBytes只要一个满足, 区块就会产生 BatchTimeout: 2s # 多长时间产生一个区块 BatchSize: MaxMessageCount: 10 # 交易的最大数据量, 数量达到之后会产生区块, 建议100左右 AbsoluteMaxBytes: 99 MB # 数据量达到这个值, 会产生一个区块, 32M/64M PreferredMaxBytes: 512 KB Kafka: Brokers: - 127.0.0.1:9092 Organizations: ################################################################################ # # Profile # ################################################################################ Profiles: # 不能改 TwoOrgsOrdererGenesis: # 区块名字, 随便改 Capabilities: <<: *ChannelCapabilities Orderer: <<: *OrdererDefaults Organizations: - *OrdererOrg Capabilities: <<: *OrdererCapabilities Consortiums: SampleConsortium: # 这个名字可以改 Organizations: - *Org1 - *Org2 TwoOrgsChannel: # 通道名字, 可以改 Consortium: SampleConsortium # 这个名字对应93行 Application: <<: *ApplicationDefaults Organizations: - *Org1 - *Org2 Capabilities: <<: *ApplicationCapabilities
-
按照要求编写的配置文件
# configtx.yaml --- ################################################################################ # # Section: Organizations # ################################################################################ Organizations: - &OrdererOrg Name: OrdererOrg ID: OrdererMSP MSPDir: crypto-config/ordererOrganizations/ydqy.com/msp - &org_go Name: OrgGoMSP ID: OrgGoMSP MSPDir: crypto-config/peerOrganizations/orggo.ydqy.com/msp AnchorPeers: - Host: peer0.orggo.ydqy.com Port: 7051 - &org_cpp Name: OrgCppMSP ID: OrgCppMSP MSPDir: crypto-config/peerOrganizations/orgcpp.ydqy.com/msp AnchorPeers: - Host: peer0.orgcpp.ydqy.com Port: 7051 ################################################################################ # # SECTION: Capabilities # ################################################################################ Capabilities: Global: &ChannelCapabilities V1_1: true Orderer: &OrdererCapabilities V1_1: true Application: &ApplicationCapabilities V1_2: true ################################################################################ # # SECTION: Application # ################################################################################ Application: &ApplicationDefaults Organizations: ################################################################################ # # SECTION: Orderer # ################################################################################ Orderer: &OrdererDefaults # Available types are "solo" and "kafka" OrdererType: solo Addresses: - orderer.ydqy.com:7050 BatchTimeout: 2s BatchSize: MaxMessageCount: 100 AbsoluteMaxBytes: 32 MB PreferredMaxBytes: 512 KB Kafka: Brokers: - 127.0.0.1:9092 Organizations: ################################################################################ # # Profile # ################################################################################ Profiles: ydqyOrgsOrdererGenesis: Capabilities: <<: *ChannelCapabilities Orderer: <<: *OrdererDefaults Organizations: - *OrdererOrg Capabilities: <<: *OrdererCapabilities Consortiums: SampleConsortium: Organizations: - *org_go - *org_cpp ydqyOrgsChannel: Consortium: SampleConsortium Application: <<: *ApplicationDefaults Organizations: - *org_go - *org_cpp Capabilities: <<: *ApplicationCapabilities
-
执行命令生成文件
-profile 后边的参数从configtx.yaml中的Profiles 里边的配置项
-
生成创始块文件
$ configtxgen -profile ydqyOrgsOrdererGenesis -outputBlock ./genesis.block - 在当前目录下得到一个文件: genesis.block
-
生成通道文件
$ configtxgen -profile ydqyOrgsChannel -outputCreateChannelTx channel.tx -channelID ydqychannel
-
生成锚节点更新文件
这个操作是可选的
# 每个组织都对应一个锚节点的更新文件 # go组织锚节点文件 $ configtxgen -profile ydqyOrgsChannel -outputAnchorPeersUpdate GoMSPanchors.tx -channelID ydqychannel -asOrg OrgGoMSP # cpp组织锚节点文件 $ configtxgen -profile ydqyOrgsChannel -outputAnchorPeersUpdate CppMSPanchors.tx -channelID ydqychannel -asOrg OrgCppMSP
# 查看生成的文件 $ tree -L 1 . ├── channel-artifacts ├── channel.tx ----------> 生成的通道文件 ├── configtx.yaml ├── CppMSPanchors.tx -----> 生成的cpp组织锚节点文件 ├── crypto-config ├── crypto-config.yaml ├── genesis.block --------> 生成的创始块文件 └── GoMSPanchors.tx ------> 生成的go组织锚节点文件
-