Hyperlegder Fabric 1.4.4 手动搭建BYFN网络

#下载bootstrap.sh
git clone https://gitee.com/real__cool/fabric_install

#下载工具文件
./bootstrap3.sh 1.4.4 1.4.4 -s

#创建 .env file
COMPOSE_PROJECT_NAME=net 
IMAGE_TAG=latest 
SYS_CHANNEL=byfn-sys-channel

#生成证书材料
./bin/cryptogen generate --config=./crypto-config.yaml
#创建通道相关资料文件夹
mkdir channel-artifacts
#生成创世区块
./bin/configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
#生成通道配置
./bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
#生成锚节点配置
./bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
#生成锚节点配置
./bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
#启动网络
docker-compose -f docker-compose-cli.yaml up -d
#查看当前容器
docker ps

#复制链码到../chaincode

#进入cli容器
docker exec -it cli bash
#设置环境变量
peer0org1="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_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp CORE_PEER_ADDRESS=peer0.org1.example.com:7051"
peer1org1="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_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp CORE_PEER_ADDRESS=peer1.org1.example.com:8051"
peer0org2="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 CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp CORE_PEER_ADDRESS=peer0.org2.example.com:9051"
peer1org2="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 CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp CORE_PEER_ADDRESS=peer1.org2.example.com:10051"

#刚进cli使用的是peer0org1
peer channel \
create -o orderer.example.com:7050 \
-c mychannel \
-f ./channel-artifacts/channel.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


#将所有节点加入通道
export $peer0org1
peer channel join -b mychannel.block
export $peer1org1
peer channel join -b mychannel.block
export $peer0org2
peer channel join -b mychannel.block
export $peer1org2
peer channel join -b mychannel.block


#更新锚节点
export $peer0org1
peer channel update \
-o orderer.example.com:7050 \
-c mychannel \
-f ./channel-artifacts/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

export $peer0org2
peer channel update \
-o orderer.example.com:7050 \
-c mychannel \
-f ./channel-artifacts/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


#安装链码,只需要在背书节点安装
export $peer0org1
peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
export $peer0org2
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 mychannel -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'AND ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'

#在peer0org1上query测试
export $peer0org1
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'

#在peer0org2上invoke测试
export $peer0org2
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 mychannel -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 --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'

#在peer1org1上安装并query测试
export $peer1org1
peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'

#输出结果是100-10=90,则证明e2e测试成功


#删除产生的网络资料
rm -rf crypto-config && mkdir crypto-config
rm -rf channel-artifacts && mkdir channel-artifacts
docker-compose -f docker-compose-cli.yaml down -v

你可能感兴趣的:(fabric,网络,docker)