Hyperledger多节点跨机部署:如何在第二节点访问链上数据?
Got it, let's walk through the steps to get your second node accessing the chain data. Since you already see inter-node communication in Docker logs, we just need to fix a few configuration gaps:
1. Verify the Node Has Joined the Channel
First, confirm your second peer is actually part of the channel. Jump into the second node's peer CLI container and run:
peer channel list
If your target channel isn't listed, you need to join it:
- Fetch the channel genesis block from the orderer (or copy it from the first node using
docker cp):peer channel fetch 0 mychannel.block -o <orderer-ip>:7050 -c mychannel - Join the channel with the block file:
peer channel join -b mychannel.block - Validate the join worked by checking the channel info:
peer channel getinfo -c mychannel
You should see the block height matching the first node—this means the peer is syncing blocks.
2. Install the Chaincode on the Second Peer
Even if the chaincode is already instantiated on the channel, every peer that needs to process transactions or queries must have the chaincode installed locally.
- Copy your chaincode files into the second node's CLI container (or use a mounted volume so the files are accessible).
- Run the install command (adjust the name, version, and path to match your chaincode):
peer chaincode install -n mychaincode -v 1.0 -p github.com/hyperledger/fabric/chaincode/your-chaincode-directory
Note: You don't need to re-instantiate the chaincode—only one peer in the channel needs to do that.
3. Configure Client Tools (Like Composer Playground)
If you want to use Composer Playground on the second node, you need to make sure it can connect to the right components:
- When deploying Playground on the second node, update its connection profile (
connection.json) to point to:- The local peer's address (
<second-node-ip>:7051) - The CA and orderer addresses from the first node (ensure these are reachable over the network—check firewall rules for ports 7050, 7054, etc.)
- The local peer's address (
- Make sure the Playground container has network access to all these components (if using Docker, they should be on the same overlay network or accessible via host IPs).
4. Test with the Peer CLI First
Before troubleshooting Playground, test directly with the peer CLI to confirm data access works:
- Set the necessary environment variables in the second node's CLI container:
export CORE_PEER_LOCALMSPID="YourOrgMSP" export CORE_PEER_ADDRESS=<second-peer-ip>:7051 export CORE_PEER_MSPCONFIGPATH=/path/to/your/msp/directory - Run a chaincode query to fetch data:
peer chaincode query -n mychaincode -c '{"Args":["query","your-key"]}' -c mychannel
If this returns the expected data, the peer is working correctly, and the issue is with Playground's configuration. If not, go back and double-check the channel join and chaincode install steps.
5. Check Peer Sync Logs
Take a look at the second peer's Docker logs to confirm blocks are being synced:
docker logs <second-peer-container-name> | grep "block committed"
You should see entries for each block being added to the peer's ledger. If the block height matches the first node, the data is already there—you just need to connect to it properly.
内容的提问来源于stack exchange,提问作者Auron

