fabric網絡搭建指南-容器定義

第一部分:容器定義

部署目錄:dirPath
基礎服務目錄路徑:{dirPath}/basenode

1. peer-base.yaml

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

version: '2'

services:
  peer-base:
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      # 接下來的設置是在相同的橋接網絡啓動鏈碼容器做爲peers
      # https://docs.docker.com/compose/networking/
      # Compose 默認爲你的應用設置一個單一的網絡,對於一個服務的每一個容器來講加入
      # 默認網絡便可與網絡中的其餘容器相通,也能夠經過主機名做爲容器名稱標識被其餘容器發現。
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_byfn
      #- CORE_LOGGING_LEVEL=ERROR
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start

2. kafka-base.yaml

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

version: '2'

services:

  zookeeper:
    image: hyperledger/fabric-zookeeper
    environment:
      #
      # server.x=[hostname]:nnnnn[:nnnnn]
      # The list of servers that make up the ZK ensemble. The list that is used
      # by the clients must match the list of ZooKeeper servers that each ZK
      # server has. There are two port numbers `nnnnn`. The first is what
      # followers use to connect to the leader, while the second is for leader
      # election.
      - ZOO_SERVERS=server.1=zookeeper0.example.com:2888:3888 server.2=zookeeper1.example.com:2888:3888 server.3=zookeeper2.example.com:2888:3888 
      - quorumListenOnAllIPs=true
    restart: always

  kafka:
    image: hyperledger/fabric-kafka
    restart: always
    environment:
      - KAFKA_MESSAGE_MAX_BYTES=103809024 # 99 * 1024 * 1024 B
      - KAFKA_REPLICA_FETCH_MAX_BYTES=103809024 # 99 * 1024 * 1024 B
      - KAFKA_LOG_RETENTION_MS=-1      
      - KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
      - KAFKA_MIN_INSYNC_REPLICAS=2
      - KAFKA_DEFAULT_REPLICATION_FACTOR=3
      - KAFKA_ADVERTISED_PORT=9092
    ports:
      - '9092'

3. orderer-base.yaml

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

version: '2'

services:

  orderer-base:
    image: hyperledger/fabric-orderer
    environment:
      - ORDERER_GENERAL_LOGLEVEL=debug
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_LISTENPORT=7050
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
      # enabled TLS
      - ORDERER_GENERAL_TLS_ENABLED=true
      - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      # kafka
      - ORDERER_KAFKA_RETRY_LONGINTERVAL=10s
      - ORDERER_KAFKA_RETRY_LONGTOTAL=100s
      - ORDERER_KAFKA_RETRY_SHORTINTERVAL=1s
      - ORDERER_KAFKA_RETRY_SHORTTOTAL=30s
      - ORDERER_KAFKA_VERBOSE=true
      - ORDERER_KAFKA_BROKERS=[kafka0.example.com:9092,kafka1.example.com:9092,kafka2.example.com:9092,kafka3.example.com:9092]
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: orderer
    ports:
      - 7050:7050

4. docker-compose-base.yaml

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

version: '2'

services:

  orderer0.example.com:
    container_name: orderer0.example.com
    extends:
      file: orderer-base.yaml
      service: orderer-base
    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
      - ../crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/tls/:/var/hyperledger/orderer/tls
    ports:
      - 7050:7050

  orderer1.example.com:
    container_name: orderer1.example.com
    extends:
      file: orderer-base.yaml
      service: orderer-base
    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
      - ../crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/:/var/hyperledger/orderer/tls
    ports:
      - 8050:8050

  orderer2.example.com:
    container_name: orderer2.example.com
    extends:
      file: orderer-base.yaml
      service: orderer-base
    volumes:
      - ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
      - ../crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/msp:/var/hyperledger/orderer/msp
      - ../crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/:/var/hyperledger/orderer/tls
    ports:
      - 9050:9050

  peer0.org1.example.com:
    container_name: peer0.org1.example.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer0.org1.example.com
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.example.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
    ports:
      - 7051:7051
      - 7053:7053

  peer1.org1.example.com:
    container_name: peer1.org1.example.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer1.org1.example.com
      - CORE_PEER_ADDRESS=peer1.org1.example.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:7051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls
    ports:
      - 8051:7051
      - 8053:7053

  peer0.org2.example.com:
    container_name: peer0.org2.example.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer0.org2.example.com
      - CORE_PEER_ADDRESS=peer0.org2.example.com:7051
      #- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:7051
      #- CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.example.com:7051
      - CORE_PEER_LOCALMSPID=Org2MSP
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls
    ports:
      - 9051:7051
      - 9053:7053

  peer0.org3.example.com:
    container_name: peer0.org3.example.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer0.org3.example.com
      - CORE_PEER_ADDRESS=peer0.org3.example.com:7051
      #- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org3.example.com:7051
      #- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org3.example.com:7051
      - CORE_PEER_LOCALMSPID=Org3MSP
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls:/etc/hyperledger/fabric/tls
    ports:
      - 10051:7051
      - 19053:7053
  zookeeper0.example.com:
    container_name: zookeeper0.example.com
    extends:
      file: kafka-base.yaml
      service: zookeeper
    environment:
      - ZOO_MY_ID=1
    ports:
      - 2181:2181
      - 2888:2888
      - 3888:3888

  zookeeper1.example.com:
    container_name: zookeeper1.example.com
    extends:
      file: kafka-base.yaml
      service: zookeeper
    environment:
      - ZOO_MY_ID=2
    ports:
      - 32181:2181
      - 32888:2888
      - 33888:3888

  zookeeper2.example.com:
    container_name: zookeeper2.example.com
    extends:
      file: kafka-base.yaml
      service: zookeeper
    environment:
      - ZOO_MY_ID=3
    ports:
      - 22181:2181
      - 22888:2888
      - 23888:3888

  kafka0.example.com:
    container_name: kafka0.example.com
    extends:
      file: kafka-base.yaml
      service: kafka
    environment:
      - KAFKA_BROKER_ID=10
      - KAFKA_LISTENERS=PLAINTEXT://kafka0.example.com:9092
      - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka0.example.com:9092
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper0.example.com:2181,zookeeper1.example.com:2181,zookeeper2.example.com:2181
    ports:
      - 9092:9092
      - 9093:9093

  kafka1.example.com:
    container_name: kafka1.example.com
    extends:
      file: kafka-base.yaml
      service: kafka
    environment:
      - KAFKA_BROKER_ID=11
      - KAFKA_LISTENERS=PLAINTEXT://kafka1.example.com:9092
      - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka1.example.com:9092
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper0.example.com:2181,zookeeper1.example.com:2181,zookeeper2.example.com:2181
    ports:
      - 10092:9092
      - 10093:9093

  kafka2.example.com:
    container_name: kafka2.example.com
    extends:
      file: kafka-base.yaml
      service: kafka
    environment:
      - KAFKA_BROKER_ID=2
    ports:
      - 11092:9092
      - 11093:9093

  kafka3.example.com:
    container_name: kafka3.example.com
    extends:
      file: kafka-base.yaml
      service: kafka
    environment:
      - KAFKA_BROKER_ID=3
    ports:
      - 12092:9092
      - 12093:9093
相關文章
相關標籤/搜索