Fabric多Orderer服务配置求助:创建多Orderer时遇连接超时
Hey there! Let's fix that multi-orderer setup issue you're hitting. That "context deadline exceeded" error almost always stems from misconfigured network endpoints, missing service definitions, or nodes not being able to resolve each other in the Docker network. Below’s a complete, tested multi-orderer Fabric network example you can copy and adapt, plus key tips to avoid that connectivity error.
We’ll set up a network with 2 orderer nodes (orderer0, orderer1) under example.com, 1 peer node (peer0.org1.example.com), and all necessary components for a working setup.
1. Docker Compose File (docker-compose.yaml)
This file defines all our services and ensures they’re on the same network:
version: '2' networks: byfn: name: byfn services: ca.example.com: image: hyperledger/fabric-ca:latest environment: - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server - FABRIC_CA_SERVER_CA_NAME=ca.example.com - FABRIC_CA_SERVER_TLS_ENABLED=false - FABRIC_CA_SERVER_PORT=7054 ports: - "7054:7054" command: sh -c 'fabric-ca-server start -b admin:adminpw' volumes: - ./crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config networks: - byfn orderer0.example.com: image: hyperledger/fabric-orderer:latest environment: - ORDERER_GENERAL_LOGLEVEL=info - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 - ORDERER_GENERAL_GENESISMETHOD=file - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block - ORDERER_GENERAL_LOCALMSPID=OrdererMSP - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp - ORDERER_GENERAL_TLS_ENABLED=false working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer command: orderer ports: - "7050:7050" volumes: - ./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block - ./crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/msp:/var/hyperledger/orderer/msp networks: - byfn orderer1.example.com: image: hyperledger/fabric-orderer:latest environment: - ORDERER_GENERAL_LOGLEVEL=info - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 - ORDERER_GENERAL_GENESISMETHOD=file - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block - ORDERER_GENERAL_LOCALMSPID=OrdererMSP - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp - ORDERER_GENERAL_TLS_ENABLED=false - ORDERER_GENERAL_LISTENPORT=8050 working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer command: orderer ports: - "8050:8050" volumes: - ./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block - ./crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/msp:/var/hyperledger/orderer/msp networks: - byfn peer0.org1.example.com: image: hyperledger/fabric-peer:latest environment: - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock - CORE_PEER_ID=peer0.org1.example.com - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051 - CORE_PEER_LOCALMSPID=Org1MSP - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/ - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=byfn - CORE_LOGGING_LEVEL=info - CORE_PEER_TLS_ENABLED=false working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: peer node start ports: - "7051:7051" - "7053:7053" volumes: - /var/run/:/host/var/run/ - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/msp/peer - ./crypto-config/peerOrganizations/org1.example.com/users:/etc/hyperledger/msp/users networks: - byfn cli: image: hyperledger/fabric-tools:latest tty: true environment: - GOPATH=/opt/gopath - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock - CORE_LOGGING_LEVEL=info - CORE_PEER_ID=cli - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 - CORE_PEER_LOCALMSPID=Org1MSP - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=byfn working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: /bin/bash volumes: - /var/run/:/host/var/run/ - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto networks: - byfn
2. Configtx.yaml (For Genesis Block & Channel Creation)
This file defines our orderer organization with multiple nodes and peer organization:
Organizations: - &OrdererOrg Name: OrdererMSP ID: OrdererMSP MSPDir: crypto-config/ordererOrganizations/example.com/msp OrdererEndpoints: - orderer0.example.com:7050 - orderer1.example.com:8050 - &Org1 Name: Org1MSP ID: Org1MSP MSPDir: crypto-config/peerOrganizations/org1.example.com/msp AnchorPeers: - Host: peer0.org1.example.com Port: 7051 Orderer: &OrdererDefaults OrdererType: solo Addresses: - orderer0.example.com:7050 - orderer1.example.com:8050 BatchTimeout: 2s BatchSize: MaxMessageCount: 10 AbsoluteMaxBytes: 99 MB PreferredMaxBytes: 512 KB Organizations: Application: &ApplicationDefaults Organizations: Profiles: TwoOrgsOrdererGenesis: Orderer: <<: *OrdererDefaults Organizations: - *OrdererOrg Consortiums: SampleConsortium: Organizations: - *Org1 TwoOrgsChannel: Consortium: SampleConsortium Application: <<: *ApplicationDefaults Organizations: - *Org1
3. Step-by-Step Setup Instructions
Run these commands in order to spin up the network:
Generate Crypto Material
cryptogen generate --config=./crypto-config.yaml(Make sure your
crypto-config.yamldefines both orderer0 and orderer1 under the OrdererOrg)Generate Genesis Block
configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.blockGenerate Channel Configuration Transaction
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannelStart the Network
docker-compose up -dCreate Channel & Join Peer
Exec into the cli container:docker exec -it cli bashThen run:
peer channel create -o orderer0.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx peer channel join -b mychannel.block
4. Critical Fixes for Your "Context Deadline Exceeded" Error
- Ensure All Services Share the Same Network: Every service in the docker-compose must be in the
byfnnetwork (or whatever name you use). Docker DNS resolves container names only within the same network. - Correct Endpoint Configuration: The
OrdererEndpointsin configtx.yaml must match the container names and ports defined in docker-compose (e.g.,orderer1.example.com:8050). - Avoid Localhost in Endpoints: Use container names (like
peer0.org1.example.com) instead oflocalhostin peer/orderer environment variables—localhost resolves to the container itself, not the target service. - Check Port Availability: Make sure ports 7050, 8050, 7051 aren’t being used by other processes on your host machine.
内容的提问来源于stack exchange,提问作者Sudharasan D

