一 configtxgen作用及产生
configtxgen模块用来生成orderer的初始化文件和channel的初始化文件, 配合cryptogen生成的 组织结构身份文件使用,离线生成跟通道有关的配置信息,相关的实现在common/configtx。
configtxgen模块的配置文件包括Fabric系统初始块、channel初始块文件等信息。
二 产生的二进制文件命令
-asOrg string #所属组织,也就是为某个特定组织生成配置
-channelID string #channel名称,如果不指定默认是"testchainid"
-inspectBlock string #打印指定区块文件中配置内容
-inspectChannelCreateTx string #打印指定创建通道交易的配置文件
-outputAnchorPeersUpdate string #生成一个更新锚点的更新channel配置信息
-outputBlock string #输出区块文件路径
-outputCreateChannelTx string #指定一个路径,来生成channel配置文件
-profile string #配置文件中的节点,用于生成相关配置文件,默认是 “SampleInsecureSolo”)
-version #显示版本信息
三 相关配置文件 configtx.yaml
Profiles: //关键字
TwoOrgsOrdererGenesis: //组织 自定义 -profile的对应参数
Orderer: //关键字
<<: *OrdererDefaults //引用下面的OrdererDefaults
Organizations:
- *OrdererOrg
Consortiums:
SampleConsortium:
Organizations:
- *Org1
- *Org2
TwoOrgsChannel: // 自定义 -profile的对应参数
Consortium: SampleConsortium
Application: //关键字
<<: *ApplicationDefaults //引用下面的ApplicationDefaults
Organizations:
- *Org1
- *Org2
Organizations:
- &OrdererOrg
Name: OrdererOrg
ID: OrdererMSP
MSPDir: crypto-config/ordererOrganizations/example.com/msp
- &Org1
Name: Org1MSP
ID: Org1MSP
MSPDir: crypto-config/peerOrganizations/org1.example.com/msp
AnchorPeers:
- Host: peer0.org1.example.com
Port: 7051
- &Org2
Name: Org2MSP
ID: Org2MSP
MSPDir: crypto-config/peerOrganizations/org2.example.com/msp
AnchorPeers:
- Host: peer0.org2.example.com
Port: 7051
Orderer: &OrdererDefaults
OrdererType: solo
Addresses:
- orderer.example.com:7050
BatchTimeout: 2s
BatchSize:
MaxMessageCount: 10
AbsoluteMaxBytes: 98 MB
PreferredMaxBytes: 512 KB
Kafka:
Brokers:
- 127.0.0.1:9092
Organizations:
Application: &ApplicationDefaults
Organizations:
四 命令实现
生成order需要的创世区块文件
configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
生成通道配置文件
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
生成锚节点更新文件
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP