Fabric多机环境搭建,测试通过

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Fabric多机环境搭建,测试通过相关的知识,希望对你有一定的参考价值。

超级账本网络多机联网测试

A demo to setup hyperledger fabric network with mulitple machines/servers.

前提条件

  • Installed Docker (version >= 17.06.2)
  • Installed Docker Composer (version >= 1.14.0)
  • Installed Golang (version >= 1.11.0)
  • Installed git
  • Installed python (Only Support 2.7.*)
  • Installed Node.js (version >= 8.9.0)
  • IP address of host 1: 10.222.48.146
  • IP address of host 2: 10.222.48.162
  • There are 2 peers in org1, and 2 peers in org2.
  • There orderer is in host 1.

And You have pulled following docker images:

REPOSITORY TAG IMAGE ID CREATED SIZE
hyperledger/fabric-javaenv 1.3.0 2476cefaf833 5 weeks ago 1.7GB
hyperledger/fabric-javaenv latest 2476cefaf833 5 weeks ago 1.7GB
hyperledger/fabric-ca 1.3.0 5c6b20ba944f 5 weeks ago 244MB
hyperledger/fabric-ca latest 5c6b20ba944f 5 weeks ago 244MB
hyperledger/fabric-tools 1.3.0 c056cd9890e7 5 weeks ago 1.5GB
hyperledger/fabric-tools latest c056cd9890e7 5 weeks ago 1.5GB
hyperledger/fabric-ccenv 1.3.0 953124d80237 5 weeks ago 1.38GB
hyperledger/fabric-ccenv latest 953124d80237 5 weeks ago 1.38GB
hyperledger/fabric-orderer 1.3.0 f430f581b46b 5 weeks ago 145MB
hyperledger/fabric-orderer latest f430f581b46b 5 weeks ago 145MB
hyperledger/fabric-peer 1.3.0 f3ea63abddaa 5 weeks ago 151MB
hyperledger/fabric-peer latest f3ea63abddaa 5 weeks ago 151MB
hyperledger/fabric-zookeeper 0.4.13 e62e0af39193 6 weeks ago 1.39GB
hyperledger/fabric-zookeeper latest e62e0af39193 6 weeks ago 1.39GB
hyperledger/fabric-kafka 0.4.13 4121ea662c47 6 weeks ago 1.4GB
hyperledger/fabric-kafka latest 4121ea662c47 6 weeks ago 1.4GB
hyperledger/fabric-couchdb 0.4.13 1d3266e01e64 6 weeks ago 1.45GB
hyperledger/fabric-couchdb latest 1d3266e01e64 6 weeks ago 1.45GB
hyperledger/fabric-baseos amd64-0.4.13 f0fe49196c40 6 weeks ago 124MB

Please replace the IP address in the docker-compose-org1.yaml and docker-compose-org1.yaml with the IP addresses of your hosts.

执行命令步骤

Step1, Run following commands in Machine 2

  1. git clone https://github.com/fifahuihua/fabric-network-setup.git
  2. cd fabric-network-setup
  3. ./byfn.sh down
  4. docker volume rm net_peer0.org2.example.com
  5. docker volume rm net_peer1.org2.example.com
  6. docker image rm $(docker image ls -q dev-*)

Step2, Run following commands in Machine 1

  1. git clone https://github.com/fifahuihua/fabric-network-setup.git
  2. cd fabric-network-setup
  3. ./byfn.sh down
  4. docker volume rm net_orderer.example.com
  5. docker volume rm net_peer0.org1.example.com
  6. docker volume rm net_peer1.org1.example.com
  7. docker image rm $(docker image ls -q dev-*)
  8. ./byfn.sh generate
  9. scp -r ./crypto-config [email protected]:/home/antony/projects/fabric-network-setup
  10. docker-compose -f docker-compose-org1.yaml up -d

Step3, Run following commands in Machine 2

  1. docker-compose -f docker-compose-org2.yaml up -d

Step4, Run following commands in Machine 1

  1. docker exec -it cli bash
  2. export CHANNEL_NAME=mychannel
  3. peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/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
  4. peer channel join -b mychannel.block
  5. 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 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 mychannel.block
  6. peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/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
  7. 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 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 update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/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
  8. peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
  9. 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 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 chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
  10. peer chaincode instantiate -o orderer.example.com:7050 --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 -C $CHANNEL_NAME -n mycc -v 1.0 -c ‘{"Args":["init","a", "100", "b","200"]}‘ -P "AND (‘Org1MSP.peer‘,‘Org2MSP.peer‘)"
  11. peer chaincode query -C $CHANNEL_NAME -n mycc -c ‘{"Args":["query","a"]}‘
  12. 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 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 chaincode query -C $CHANNEL_NAME -n mycc -c ‘{"Args":["query","a"]}‘
  13. 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 $CHANNEL_NAME -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"]}‘
  14. peer chaincode query -C $CHANNEL_NAME -n mycc -c ‘{"Args":["query","a"]}‘
  15. 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 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 chaincode query -C $CHANNEL_NAME -n mycc -c ‘{"Args":["query","a"]}‘

以上是关于Fabric多机环境搭建,测试通过的主要内容,如果未能解决你的问题,请参考以下文章

区块链——Hyperledger Fabric2.2多机搭建及区块链浏览器

Hyperledger Fabric多机及explorer搭建

Hyperledger Fabric 环境搭建及Fabric 测试网络使用(区块链联盟链)

FabricV2.2测试网络搭建以及开发环境部署

HyperLedger Fabric 2.x 环境搭建

区块链(ubuntu)-Hyperledger Fabric实验环境搭建,修改chaincode,部署chaincode以及测试chaincode(JAVA)