fabric 1.4.4 搭建多链--网络环境

1 加密证书

../bin/cryptogen generate --config=./crypto-config.yaml

2创世区块

../bin/configtxgen -profile FiveOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block

3 通道配置信息
ChannelMain

../bin/configtxgen -profile MainOrgsChannel -outputCreateChannelTx ./channel-artifacts/channelmain.tx -channelID channelmain

ChannelProduce

../bin/configtxgen -profile ProduceOrgsChannel -outputCreateChannelTx ./channel-artifacts/channelproduce.tx -channelID channelproduce

ChannelProcess

../bin/configtxgen -profile ProcessOrgsChannel -outputCreateChannelTx ./channel-artifacts/channelprocess.tx -channelID channelprocess

ChannelLogistics

../bin/configtxgen -profile LogisticsOrgsChannel -outputCreateChannelTx ./channel-artifacts/channellogistics.tx -channelID channellogistics

4 更新锚节点
为通道中每个组织生成锚节点配置信息,
ChannelMain 中需要为 Org1、Org2、Org3、Org4、Org5生成锚节点配置信息
Org1

../bin/configtxgen -profile MainOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/mainchannelanchors/Org1MSPanchors.tx -channelID channelmain -asOrg Org1MSP

Org2

../bin/configtxgen -profile MainOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/mainchannelanchors/Org2MSPanchors.tx -channelID channelmain -asOrg Org2MSP

Org3

../bin/configtxgen -profile MainOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/mainchannelanchors/Org3MSPanchors.tx -channelID channelmain -asOrg Org3MSP

Org4

../bin/configtxgen -profile MainOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/mainchannelanchors/Org4MSPanchors.tx -channelID channelmain -asOrg Org4MSP

Org5

../bin/configtxgen -profile MainOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/mainchannelanchors/Org5MSPanchors.tx -channelID channelmain -asOrg Org5MSP

ProduceOrgsChannel中需要为Org1生成锚节点配置信息
Org1

../bin/configtxgen -profile ProduceOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/producechannelanchors/Org1MSPanchors.tx -channelID channelproduce -asOrg Org1MSP

ProcessOrgsChannel中需要为Org2生成锚节点配置信息
Org2

../bin/configtxgen -profile ProcessOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/processchannelanchors/Org2MSPanchors.tx -channelID channelprocess -asOrg Org2MSP

LogisticsOrgsChannel中需要为Org1生成锚节点配置信息
Org3

../bin/configtxgen -profile LogisticsOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/logisticschannelanchors/Org3MSPanchors.tx -channelID channellogistics -asOrg Org3MSP

4 启动容器

docker-compose -f docker-compose-cli.yaml up -d
docker exec -it cli bash

5创建通道
channelmain

 peer channel create -o orderer.example.com:7050 -c channelmain -f ./channel-artifacts/channelmain.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
cp channelmain.block ./channel-artifacts

channelproduce

 peer channel create -o orderer.example.com:7050 -c channelproduce -f ./channel-artifacts/channelproduce.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
cp channelproduce.block ./channel-artifacts

切换到组织2的节点创建通道:

source scripts/utils.sh
setGlobals 0 2

channelprocess

 peer channel create -o orderer.example.com:7050 -c channelprocess -f ./channel-artifacts/channelprocess.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
cp channelprocess.block ./channel-artifacts

切换到组织3的节点创建通道:

setGlobals 0 3

channellogistics

 peer channel create -o orderer.example.com:7050 -c channellogistics -f ./channel-artifacts/channellogistics.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
cp channellogistics.block ./channel-artifacts

6 加入通道
channelmain
peer0.org1

source scripts/utils.sh
setGlobals 0 1
 peer channel join -b channel-artifacts/channelmain.block

peer0.org2

setGlobals 0 2
 peer channel join -b channel-artifacts/channelmain.block

peer0.org3

setGlobals 0 3
 peer channel join -b channel-artifacts/channelmain.block

peer0.org4

setGlobals 0 4
 peer channel join -b channel-artifacts/channelmain.block

peer1.org4

setGlobals 1 4
 peer channel join -b channel-artifacts/channelmain.block

peer0.org5

setGlobals 0 5
 peer channel join -b channel-artifacts/channelmain.block

peer1.org5

setGlobals 1 5
 peer channel join -b channel-artifacts/channelmain.block

channalproduce
peer0.org1

setGlobals 0 1
 peer channel join -b channel-artifacts/channelproduce.block

peer1.org1

setGlobals 1 1
 peer channel join -b channel-artifacts/channelproduce.block

channelprocess
peer0.org2

setGlobals 0 2
 peer channel join -b channel-artifacts/channelprocess.block

peer1.org2

setGlobals 1 2
 peer channel join -b channel-artifacts/channelprocess.block

channellogistics
peer0.org3

setGlobals 0 3
 peer channel join -b channel-artifacts/channellogistics.block

peer1.org3

setGlobals 1 3
 peer channel join -b channel-artifacts/channellogistics.block

7更新锚节点
通道 channelmain中 5个组织锚节点更新

组织一

peer channel update -o orderer.example.com:7050 -c channelmain -f ./channel-artifacts/mainchannelanchors/Org1MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

组织二

peer channel update -o orderer.example.com:7050 -c channelmain -f ./channel-artifacts/mainchannelanchors/Org2MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

组织三

peer channel update -o orderer.example.com:7050 -c channelmain -f ./channel-artifacts/mainchannelanchors/Org3MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

组织四

peer channel update -o orderer.example.com:7050 -c channelmain -f ./channel-artifacts/mainchannelanchors/Org4MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

组织五

peer channel update -o orderer.example.com:7050 -c channelmain -f ./channel-artifacts/mainchannelanchors/Org5MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

通道 channelproduce 中为组织一更新锚节点
组织一

peer channel update -o orderer.example.com:7050 -c channelproduce -f ./channel-artifacts/producechannelanchors/Org1MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

通道 channelprocess 中为组织二更新锚节点
组织二

peer channel update -o orderer.example.com:7050 -c channelprocess -f ./channel-artifacts/processchannelanchors/Org2MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

通道 channellogistics 中为组织三更新锚节点
组织三

peer channel update -o orderer.example.com:7050 -c channellogistics -f ./channel-artifacts/logisticschannelanchors/Org3MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

8 安装链码
测试链码:
安装:

peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/

实例化:

peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C channelmain -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'OR ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'

查询:

peer chaincode query -C channelmain -n mycc -c '{"Args":["query","a"]}'

invoke

 peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C channelmain  -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'

组织一:
peer0.org1
安装链码 producepub、producepri、main
链码producepub
安装

peer chaincode install -n producepub -v 1.0 -l golang -p github.com/chaincode/mulchannel/produce/producepub/

实例化

peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C channelproduce -n producepub -l golang -v 1.0  -c '{"Args":["init"]}' -P 'AND ('\''Org1MSP.peer'\'')'

addTraceinfo

peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C channelproduce -n producepub --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt  -c '{"Args":["addTraceinfo","001","0001","corn,yhj,2020-11-5,plant"]}'

readTraceinfo

peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C channelproduce -n producepub --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt  -c '{"Args":["readTraceinfo","001"]}'

执行多次addTraceinfo 操作 , (同一批次号 0001)
执行 queryTraceinfoByBatchNum 测试

peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C channelproduce -n producepub --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt  -c '{"Args":["queryTraceinfoByBatchNum","0001"]}'
peer chaincode install -n producepri -v 1.0 -l golang -p github.com/chaincode/mulchannel/produce/producepri/

peer1.org1
安装链码 producepub、producepri

组织二:
peer0.org2
安装链码 producepub、producepri、main

peer1.org2
安装链码 producepub、producepri

组织三:
peer0.org3
安装链码 producepub、producepri、main

peer1.org3
安装链码 producepub、producepri

组织四:
peer0.org4
安装链码main

peer1.org4
安装链码main

组织五:
peer0.org5
安装链码main

peer1.org5
安装链码main

介绍Hyperledger fabric的PPT(52页)
密码学笔记
区块链知识体系简介
部署 ipfs 网络 对接联盟链网络
Hyperledger fabric网络(多共识 多版本 多数据库 ca ) 封装接口sdk
Hyperledger Caliper 测试(多组织 多节点 多共识)
区块链浏览器
联系We-chat V : 18852897525

你可能感兴趣的:(fabric-多通道,接口,fabric,fabric,网络,docker)