陈述
主要讲Fabric核心模块中Configtxgen
- 生成Orderer节点的初始化文件
- 生成channel的初始化文件
Configtxgen模块命令
onfigtxgen模块是通过命令行的方式运行的,通过执行命令Configtxgen --help
可以显示 Configtxgen 模块的命令行选项,执行结果如下所示:
$ Configtxgen --help
Usage of ./Configtxgen:
# 指定所属的组织
-asOrg string
Performs the config generation as a particular organization (by name), only
including values in the write set that org (likely) has privilege to set
# 指定创建的channel的名字, 如果没指定系统会提供一个默认的名字.
-channelID string
The channel ID to use in the configtx
# 执行命令要加载的配置文件的路径, 不指定会在当前目录下查找
-configPath string
The path containing the configuration to use (if set)
# 打印指定区块文件中的配置内容,string:查看的区块文件的名字
-inspectBlock string
Prints the configuration contained in the block at the specified path
# 打印创建通道的交易的配置文件
-inspectChannelCreateTx string
Prints the configuration contained in the transaction at the specified path
# 更新channel的配置信息
-outputAnchorPeersUpdate string
Creates an config update to update an anchor peer (works only with the default
channel creation, and only for the first update)
# 输出区块文件的路径
-outputBlock string
The path to write the genesis block to (if set)
# 标示输出创始区块文件
-outputCreateChannelTx string
The path to write a channel creation configtx to (if set)
# 将组织的定义打印为JSON(这对在组织中手动添加一个通道很有用)。
-printOrg string
Prints the definition of an organization as JSON. (useful for adding an org to
a channel manually)
# 指定配置文件中的节点
-profile string
The profile from configtx.yaml to use for generation. (default
"SampleInsecureSolo")
# 显示版本信息
-version
Show version information
Configtxgen模块配置文件
Configtxgen 模块的配置文件包含Fabric系统初始块、Channel初始块文件等信息。
Configtxgen模块的配置文件样例如下所示,以下部分定义了整个系统的配置信息:
Profiles:
# 组织定义标识符,可自定义,命令中的 -profile 参数对应该标识符, 二者要保持一致
ydqyOrgsOrdererGenesis:
Capabilities:
<<: *ChannelCapabilities # 引用下面为 ChannelCapabilities 的属性
Orderer: # 配置属性,系统关键字,不能修改
<<: *OrdererDefaults # 引用下面为 OrdererDefaults 的属性
Organizations:
- *OrdererOrg # 引用下面为 OrdererOrg 的属性
Capabilities:
<<: *OrdererCapabilities # 引用下面为 OrdererCapabilities 的属性
Consortiums: # 定义了系统中包含的组织
SampleConsortium:
Organizations: # 系统中包含的组织
- *OrgGo # 引用了下文包含的配置
- *OrgJava
# 通道定义标识符,可自定义
TwoOrgsChannel:
Consortium: SampleConsortium
Application:
<<: *ApplicationDefaults
Organizations:
- *OrgGo
- *OrgJava
Capabilities:
<<: *ApplicationCapabilities
# 所有的值使用默认的true即可, 不要修改
Capabilities:
Global: &ChannelCapabilities
V1_1: true
Orderer: &OrdererCapabilities
V1_1: true
Application: &ApplicationCapabilities
V1_2: true
# 组织节点相关配置信息
Organizations:
# orderer节点配置信息
- &OrdererOrg
Name: OrdererOrg # orderer节点名称
ID: OrdererMSP # orderer节点编号
MSPDir: ./crypto-config/ordererOrganizations/ydqy.com/msp # msp文件路径
#orderer节点中包含的组织,如果有有多个需要配置多个
- &OrgGo
Name: OrgGoMSP # 组织名称
ID: OrgGoMSP # 组织编号
# 组织msp文件路径
MSPDir: ./crypto-config/peerOrganizations/go.ydqy.com/msp
AnchorPeers: # 组织的访问域名和端口
- Host: peer0.go.ydqy.com
Port: 7051
- &OrgJava
Name: OrgJavaMSP
ID: OrgJavaMSP
MSPDir: ./crypto-config/peerOrganizations/java.ydqy.com/msp
AnchorPeers:
- Host: peer0.java.ydqy.com
Port: 7051
# orderer节点的配置信息
Orderer: &OrdererDefaults
# orderer节点共识算法,有效值:"solo" 和 "kafka"
OrdererType: solo
Addresses:
- ubuntu.ydqy.com:7050 # orderer节点监听的地址
BatchTimeout: 2s
BatchSize:
MaxMessageCount: 10
AbsoluteMaxBytes: 99 MB
PreferredMaxBytes: 512 KB
# kafka相关配置
Kafka:
Brokers:
- 127.0.0.1:9092
Organizations:
Application: &ApplicationDefaults
Organizations:
说明
上述配置文件中的 Profiles节点定义了整个系统的结构和channel的结构, 配置文件中的Profiles
关键字不允许修改,否则配置无效。系统配置信息中设置了系统中orderer节点的信息以及系统中包含的组织数。
Configtxgen 的使用
为了统一管理,可以将生成的初始块文件放入指定目录中,如:channel-artifacts,我们在TestNetWork目录中创建该子目录。
Configtxgen 命令在执行的时候需要加载一个叫做configtx.yaml的配置文件, 如果没有指定默认重命令执行的当前目录查找,我们可以通过参数 -configPath
进行指定,也可以将这个目录设置到环境变量FABRIC_CFG_PATH
中。
`export FABRIC_CFG_PATH=$(pwd)/networks/config/`
-
创建
orderer
的初始块ydqy@ubuntu:TestNetWork$ Configtxgen -profile ydqyOrgOrdererGenesis -outputBlock ./channel-artifacts/genesis.block # ydqyOrgOrdererGenesis: 要和配置文件中的配置项对应, 可以由数字和字母构成. # orderer初始块文件为genesis.block,生成在channel-artifacts目录中
-
创建
channel
的初始块ydqy@ubuntu:TestNetWork$ Configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel # TwoOrgsChannel: 要和配置文件中的配置项对应 # channel.tx 为生成的频道文件, 在channel-artifacts目录中 # 创建的频道名称为: mychannel
-
创建锚点更新文件 - 每个组织分别进行更新
# 更新第一个组织 OrgGoMSP 的peer节点 ydqy@ubuntu:TestNetWork$ Configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/GoMSPanchors.tx -channelID mychannel -asOrg OrgGoMSP # TwoOrgsChannel: 要和配置文件中的配置项对应 # OrgGoMSP组织使用的频道为 mychannel 生成的配置信息文件名为 GoMSPanchors.tx #============================================================================== # 更新第2个组织 OrgJavaMSP 的peer节点 ydqy@ubuntu:TestNetWork$ Configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/JavaMSPanchors.tx -channelID mychannel -asOrg OrgJavaMSP # TwoOrgsChannel: 要和配置文件中的配置项对应 # OrgJavaMSP组织使用的频道为 mychannel 生成的配置信息文件名为 JavaMSPanchors.tx