## 1. 釋義
`configtxgen`命令用來創建或查看通道配置相關的構件。生成的構件內容取決于 configtx.yaml文件。
## 2. 命令語法
`configtxgen`工具沒有子命令,使用標志來完成不同的任務:
```
~$ configtxgen [flag]
```
可用標志如下:
```
-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
-channelID string
The channel ID to use in the configtx
-configPath string
The path containing the configuration to use (if set)
-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
-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)
-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
```
## 3. 示例代碼
下面的示例依據配置SampleSingleMSPSoloV1\_1將通道orderer-system-channel的創世塊寫入文件genesis\_block.pb:
```
~$ configtxgen -outputBlock genesis_block.pb -profile SampleSingleMSPSoloV1_1 -channelID orderer-system-channel
```
下面的示例依據配置Sam跑了Sin過了MSPChannelV1\_1將通道創建交易寫入文件create\_chan\_tx.pb:
```
~$ configtxgen -outputCreateChannelTx create_chan_tx.pb -profile SampleSingleMSPChannelV1_1 -channelID application-channel-1
```
下面的示例在屏幕以JSON格式顯示名為genesis\_block.pb的創世塊的內容:
```
~$ configtxgen -inspectBlock genesis_block.pb
```
下面的示例在屏幕以JSON格式顯示通道創建交易文件create\_chan\_tx.pb的內容:
```
~$ configtxgen -inspectChannelCreateTx create_chan_tx.pb
```
下面的示例基于configtx.yaml中的參數(例如MSPDir)構造一個組織定義,并在屏幕以 JSON格式顯示:
```
~$ configtxgen -printOrg Org1
```
上述命令的輸出對于通道重新配置任務(例如添加新的成員)非常有幫助。
下面的示例將配置更新交易寫入文件anchor\_peer\_tx.pb,該交易為配置SampleSingleMSPChannelV1\_1 中的組織Org1設置錨節點:
```
~$ configtxgen -outputAnchorPeersUpdate anchor_peer_tx.pb -profile SampleSingleMSPChannelV1_1 -asOrg Org1
```
## 4. 配置文件
configtxgen的輸出很大程度上受控于配置文件configtx.yaml的內容,該文件的搜索路徑由 環境變量FABRIC\_CFG\_PATH指定。
配置文件configtx.yaml中的單個屬性值可以使用環境變量覆蓋,例如CONFIGTX\_ORDERER\_ORDERERTYPE=kafka。
對于很多configtxgen的操作,必須提供一個配置集(profile)名稱。配置集是在單一配置文件中 表示多個類似的配置的一個方法。例如,其中一個配置集可能定義了一個包含3個組織的通道, 而另一個則可能定義包含了4個組織的通道。為了避免某些配置項重復地出現,configtx.yaml 依賴于標準YAML特性中的錨點和引用。配置中的基準部分被標記為錨點例如&OrdererDefault, 然后這部分可以使用<<: \*OrdererDefaults這樣的引用合并入一個配置集。
注意,當configtxgen運作于一個配置集時,環境變量不需要包含配置集前綴。例如不需要 指定CONFIGTX\_PROFILE\_SAMPLEINSECURESOLO\_ORDERER\_ORDERERTYPE,只要簡單的省略配置集 部分,直接使用CONFIGTX\_ORDERER\_ORDERERTYPE即可。
- Fabric命令手冊
- Peer命令
- peer
- peer node
- peer node start
- peer node status
- peer channel
- peer channel create
- peer channel fetch
- peer channel getinfo
- peer channel join
- peer channel list
- peer channel signconfigtx
- peer channel update
- peer chaincode
- peer chaincode install
- peer chaincode instantiate
- peer chaincode invoke
- peer chaincode list
- peer chaincode package
- peer chaincode query
- peer chaincode signpackage
- peer chaincode upgrade
- peer version
- peer logging
- peer logging getlevel
- peer logging revertlevels
- peer logging setlevel
- Configtxgen命令
- configtxgen
- Configtxlator命令
- configtxlator
- configtxlator start
- configtxlator proto_encode
- configtxlator proto_decode
- configtxlator compute_update
- configtxlator version
- Cryptogen命令
- cryptogen
- cryptogen help
- cryptogen generate
- cryptogen showtemplate
- FabricCA命令
- fabric-ca-client
- fabric-ca-server