1. 程式人生 > >Fabric多機環境搭建,測試通過

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"]}'