You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Hyperledger Fabric v1.0跨两台机器部署balance transfer示例步骤咨询

Deploying Hyperledger Fabric v1.0 Balance Transfer Across Two Machines

Got it, let's walk through how to get your balance transfer sample up and running on two separate machines. I’ve worked through this exact setup before, so here’s a detailed, step-by-step breakdown tailored to your scenario:

1. Prepare Both Machines

  • First, ensure both machines meet Hyperledger Fabric v1.0’s prerequisites: Docker (1.12+), Docker Compose (1.8+), Go (1.7+), and have the fabric-samples repo cloned with the release/balance-transfer branch checked out.
  • Confirm the two machines are on the same network (e.g., local LAN) and can ping each other. Note their IPs—let’s call Machine A (hosts orderer + Org1 peers) 192.168.1.100 and Machine B (hosts Org2 peers) 192.168.1.101.
  • Sync the base directory structure (crypto-config, configtx, channel-artifacts) between both machines to keep configurations consistent.

2. Update Crypto & Channel Configs

  • Modify crypto-config.yaml: Split node ownership between machines. For example:
    • Assign OrdererOrg’s nodes to Machine A
    • Assign PeerOrg1’s peer0 to Machine A, PeerOrg2’s peer0 to Machine B
    • Update the SANS field for each node to include the target machine’s IP (e.g., SANS: ["peer0.org2.example.com", "192.168.1.101"] for Org2’s peer)
  • Regenerate crypto materials: Run cryptogen generate --config=./crypto-config.yaml on Machine A, then copy the entire crypto-config directory to Machine B (use scp or a shared drive).
  • Update configtx.yaml: Set the Orderer address to Machine A’s IP (OrdererAddresses: - orderer.example.com:7050). Then add host mappings to both machines’ /etc/hosts files:
    192.168.1.100 orderer.example.com peer0.org1.example.com
    192.168.1.101 peer0.org2.example.com
    
  • Generate channel artifacts: On Machine A, run:
    configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
    configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
    
    Copy the channel-artifacts directory to Machine B.

3. Start Orderer & Org1 Peer on Machine A

  • Trim docker-compose-cli.yaml: Remove services for Org2 peers, keeping only orderer.example.com, peer0.org1.example.com, and cli. Add extra_hosts to each service to map Machine B’s nodes:
    extra_hosts:
      - "peer0.org2.example.com:192.168.1.101"
    
  • Start services: Run:
    docker-compose -f docker-compose-cli.yaml up -d orderer.example.com peer0.org1.example.com cli
    
  • Verify with docker ps—all three services should be running without errors.

4. Start Org2 Peer on Machine B

  • Create a simplified docker-compose-peer2.yaml: Define only the peer0.org2.example.com service. Set environment variables to point to Machine A’s orderer:
    environment:
      - ORDERER_ADDRESS=orderer.example.com:7050
    
    Add extra_hosts to map Machine A’s nodes:
    extra_hosts:
      - "orderer.example.com:192.168.1.100"
      - "peer0.org1.example.com:192.168.1.100"
    
  • Start the peer: Run:
    docker-compose -f docker-compose-peer2.yaml up -d peer0.org2.example.com
    
  • Check logs with docker logs peer0.org2.example.com to confirm it connects to the orderer successfully.

5. Create Channel & Join Peers

  • Create the channel on Machine A: Enter the cli container and run:
    docker exec -it cli bash
    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
    
  • Sync channel block to Machine B: Copy the generated mychannel.block from the cli container to your local Machine A, then send it to Machine B:
    docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/mychannel.block .
    scp mychannel.block user@192.168.1.101:/path/to/fabric-samples/balance-transfer/
    
  • Join peers to the channel:
    • On Machine A (cli container): peer channel join -b mychannel.block
    • On Machine B (enter peer0.org2 container): peer channel join -b /path/to/mychannel.block

6. Install & Instantiate Chaincode

  • Install chaincode on both machines:
    • Machine A (cli container):
      peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
      
    • Machine B (peer0.org2 container):
      peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
      
  • Instantiate chaincode on Machine A: From the cli container, run:
    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 -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer')"
    

7. Test Cross-Machine Balance Transfer

  • Query balance on Machine A: In the cli container:
    peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
    
    You should get 100 as the result.
  • Initiate transfer: Still on Machine A:
    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 -c '{"Args":["invoke","a","b","10"]}'
    
  • Verify sync on Machine B: In the peer0.org2 container:
    peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
    
    You should now see 90, confirming the transaction synced across machines.

内容的提问来源于stack exchange,提问作者user12345

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:15:44