fabric学习(10)——在3个组织基础上新建一个channel

byfn网络启动后启动了两个组织,每个组织内包含2个peer,然后使用eyfn脚本启动org3,这样就变成了3个组织,每个组织下两个peer,结构图如下:

在此基础上,如果org1和org2有新的业务往来,而又不想让org3加入的话,就需要新建一个channel

命名为mynewchannel,连接着peer0.org1和peer0.org2

结构图如下:

下面开始

进入cli容器

docker exec -it cli bash

新建一个文件夹用于存放配置文件

mkdir newChannel
cd newChannel/

另起一个终端,把configtx.yaml拷贝到cli容器中

docker cp configtx.yaml cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/newChannel

回到容器内,生成创世块文件

configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock newgenesis.block

设置新的channel名字

export CHANNEL_NAME=mynewchannel 

生成channel文件

configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel.tx -channelID $CHANNEL_NAME

定义两个组织的锚节点

configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP

切换到org1的admin用户,默认就是

CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
CORE_PEER_LOCALMSPID="Org1MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt

回到第二个终端,把core.yaml文件拷贝到cli容器中,要先从peer容器拷出来:

docker cp peer0.org1.example.com:/etc/hyperledger/fabric/core.yaml .

docker cp core.yaml cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/newChannel

rm -rf core.yaml

回到cli容器,创建通道

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

org1的peer0加入通道

peer channel join -b mynewchannel.block

切换到peer0.org2

CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp 
CORE_PEER_ADDRESS=peer0.org2.example.com:9051 
CORE_PEER_LOCALMSPID="Org2MSP" 
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt 

加入通道

加入通道

peer channel join -b mynewchannel.block

更新org2锚节点

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

切换到org1更新锚节点

CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
CORE_PEER_LOCALMSPID="Org1MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f Org1MSPanchors.tx --tls --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可以发现,mynewchannel只有在peer0.org1和peer0.org2上面安装

查询channel的命令:

peer channel list

转载请注明来源

×

喜欢就点赞,疼爱就打赏