手动搭建hyperledger fabric v2.x 生产网络(二)通过configtxgen和configtx.yaml来创建交易相关的配置,如应用通道Channe、锚节点、Ordering服务等

手动搭建hyperledger fabric v2.x 生产网络(二)通过configtxgen和configtx.yaml来创建交易相关的配置,如应用通道Channe、锚节点、Ordering服务等,第1张

官方文档地址:https://hyperledger-fabric.readthedocs.io/zh_CN/release-2.2/create_channel/create_channel_config.html
transaction的英文缩写是TX(表示交易),configtx表示交易配置,所以和交易相关的配置,如应用通道、锚节点、Ordering服务等,都是在configtx.yaml文件中配置的;

1、使用configtxgen和configtx.yaml文件可以更轻松地创建通道(通道创世块,通道交易);
2、configtx.yaml是Fabric区块链网络运维工具,configtxgen用于生成通道创世块或通道交易的工具,configtx.yaml的内容直接决定了所生成的创世区块的内容;
3、在fabric2.3当中取消了系统通道的概念,本篇创建通道的教程以fabric2.2为例来创建通道,之后会介绍fabric2.3的内容:
	configtx.yaml包含的内容(详解请参考官方文档)
	Organizations  组织的部分
	Capabilities   能力的部分
	Application    应用的部分
	Orderer        排序节点
	Channel        通道
	Profiles       配置
4、configtx.yaml官方示例文件地址:https://github.com/hyperledger/fabric-samples/blob/main/test-network/configtx/configtx.yaml
因为本篇以fabric2.2为例,所以将fabric2.3文件configtx.yaml中Profiles部分改为(注意空格以及前后缩进,刚开始我一直报错,没有办法,手打了下面两段):
Profiles:

    TwoOrgsOrdererGenesis:
    <<: *ChannelDefaults
    Orderer:
        <<: *OrdererDefaults
        Organizations:
            - *OrdererOrg
        Capabilities:
            <<: *OrdererCapabilities
    Consortiums:
        SampleConsortium:
            Organizations:
                - *Org1
                - *Org2
    TwoOrgsChannel:
    Consortium: SampleConsortium
    <<: *ChannelDefaults
    Application:
        <<: *ApplicationDefaults
        Organizations:
            - *Org1
            - *Org2
        Capabilities:
            <<: *ApplicationCapabilities
5、将configtx.yaml文件上传到我们的项目目录下:/root/block/geneg/twonodes
	root@aa:~/block/geneg/twonodes# ls
	configtx.yaml  crypto-config  cryptogen-config.yaml
6、修改配置文件configtx.yaml
(1)所有的MSPDir路径修改为我们上一节所生成的msp证书所在位置:

	# orderer节点的msp所在位置:/root/block/geneg/twonodes/crypto-config/ordererOrganizations/example.com/msp
	# MSPDir is the filesystem path which contains the MSP configuration
    # MSPDir: ../organizations/ordererOrganizations/example.com/msp
	MSPDir: crypto-config/ordererOrganizations/example.com/msp
	
	# peer节点的org1,msp所在位置:/root/block/geneg/twonodes/crypto-config/peerOrganizations/org1.example.com/msp
	# ID to load the MSP definition as
        ID: Org1MSP
		# MSPDir: ../organizations/peerOrganizations/org1.example.com/msp
        MSPDir: crypto-config/peerOrganizations/org1.example.com/msp
	
	# peer节点的org2,msp所在位置:/root/block/geneg/twonodes/crypto-config/peerOrganizations/org2.example.com/msp
	 # ID to load the MSP definition as
        ID: Org2MSP
		# MSPDir: ../organizations/peerOrganizations/org2.example.com/msp
        MSPDir: crypto-config/peerOrganizations/org2.example.com/msp
		
(2)ClientTLSCert和ServerTLSCert证书文件位置,修改为我们上一节所生成的证书server.crt所在位置:
	# /block/geneg/twonodes/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
	EtcdRaft:
        Consenters:
        - Host: orderer.example.com
          Port: 7050
          # ClientTLSCert: ../organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
          # ServerTLSCert: ../organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
		  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
          ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
7、通过configtxgen和configtx.yaml来生成Channel通道配置
	项目目录下执行:
	root@aa:~/block/geneg/twonodes# pwd
	/root/block/geneg/twonodes
	root@aa:~/block/geneg/twonodes# 
	
	# 生成创世块文件
	$ configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block -channelID fabric-channel
		root@aa:~/block/geneg/twonodes# configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block -channelID fabric-channel
		2022-02-24 17:31:12.999 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
		2022-02-24 17:31:13.007 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft
		2022-02-24 17:31:13.007 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216 
		2022-02-24 17:31:13.007 CST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: configtx.yaml
		2022-02-24 17:31:13.034 CST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block
		2022-02-24 17:31:13.034 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Creating system channel genesis block
		2022-02-24 17:31:13.034 CST [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block
		
	# 生成通道
	$ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
		root@aa:~/block/geneg/twonodes# configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
		2022-02-24 17:35:00.312 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
		2022-02-24 17:35:00.319 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: configtx.yaml
		2022-02-24 17:35:00.319 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 003 Generating new channel configtx
		2022-02-24 17:35:00.322 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 004 Writing new channel tx

	# 生成组织1的锚节点文件
	$ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
		root@aa:~/block/geneg/twonodes# configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
		2022-02-24 17:57:00.688 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
		2022-02-24 17:57:00.696 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: configtx.yaml
		2022-02-24 17:57:00.696 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Generating anchor peer update
		2022-02-24 17:57:00.697 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 004 Writing anchor peer update
	
	# 生成组织2的锚节点文件
	$ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
		root@aa:~/block/geneg/twonodes# configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
		2022-02-24 17:57:15.068 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
		2022-02-24 17:57:15.075 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: configtx.yaml
		2022-02-24 17:57:15.075 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Generating anchor peer update
		2022-02-24 17:57:15.077 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 004 Writing anchor peer update

常见报错:
(1)在生成创世块时候出现了错误
	* Profiles【Application】 has invalid keys: Organizations
	* Profiles【Capabilities】 has invalid keys: V2_0
	* Profiles【Consortium】 expected a map, got string
	* Profiles【Consortiums】 has invalid keys: SampleConsortium
	* Profiles【Orderer】 has invalid keys: Addresses, BatchSize, BatchTimeout, EtcdRaft, OrdererType, Organizations
	解决方法:
	肯定是你格式错了,多空格少空格之类的,你的结尾部分增改的地方有多余的空格!格式和位置要与原来(TwoOrgsApplicationGenesis:)完全一致,尤其是缩进所使用的的空格数量!刚开始我一直报错,没有办法,手打了第4步的两段
(2)生成组织1的锚节点文件和组织2的锚节点文件时报错:
	Error on inspectChannelCreateTx: org 'Org1MSP' does not have any anchor peers defined
	解决方法:
	configtx.yaml底下的Org1,即peer节点的配置少了下面的属性,在节点属性MSPDir下面增加:
	AnchorPeers:
		- Host: 127.0.0.1
		  Port: 7051
    # 锚节点(Anchor Peer):每个组织可以指定Anchor Peer,其他组织的节点就可以将Gossip消息发送到这个Anchor Peer上,进而Anchor Peer将获得整个网络信息,区块广播到本组织内;
	修改完成之后,按照顺序重新生成创世块文件,生成通道,生成组织1的锚节点文件,生成组织2的锚节点文件
	
8、创建Channel通道完成,生成下列文件
root@aa:~/block/geneg/twonodes/channel-artifacts# ls
channel.tx  genesis.block  Org1MSPanchors.tx  Org2MSPanchors.tx

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/926788.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存