编程知识 cdmana.com

Hyperledger fabric consensus mechanism Kafka cluster (5)

Hyperledger fabric Consensus mechanism -Kafka Cluster ( 5、 ... and )

1、 preparation

The smallest kafka Cluster network configuration

In order to achieve machine reusability , Different types of nodes can be deployed to the same server , Nodes of the same type need to be deployed in different servers .

zookeeper The server : An odd number , And the minimum is 3 platform , At most 7 platform

kafka The server : Minimum 4 platform

orderer node : Minimum 3 individual

name Hostname IP Address
zk1 zookeeper1 1
zk2 zookeeper2 2
zk3 zookeeper3 3
kafka1 kafka1 1
kafka2 kafka2 2
kafka3 kafka3 3
kafka4 kafka4 4
orderer0 orderer0.example.com 1
orderer1 orderer1.example.com 2
orderer2 orderer2.example.com 3

In order to ensure the normal operation of the whole cluster , You need to set the working directory for each node in the cluster , We must ensure that the working directory of each node is the same

mkdir ~/kafka

2、 Generate certificate file

modify crypto-config.yaml file , add to 2 individual orderer node

OrdererOrgs:
  # ---------------------------------------------------------------------------
  # Orderer
  # ---------------------------------------------------------------------------
  - Name: Orderer
    Domain: test.com
    EnableNodeOUs: true

    # ---------------------------------------------------------------------------
    # "Specs" - See PeerOrgs below for complete description
    # ---------------------------------------------------------------------------
    Specs:
      - Hostname: orderer0
      - Hostname: orderer1
      - Hostname: orderer2

3、 Generate creation block file and channel file

modify configtx.yaml file , The first thing you need to do is Orderer.Addresses In a statement 3 individual orderer Node information , take Orderer.OrdererType The value of is determined by the default solo It is amended as follows kafka, stay Orderer.Kafka.Brokers Add Kafka Configuration information of cluster server .

Orderer: &OrdererDefaults

    # Orderer Type: The orderer implementation to start
    # Available types are "solo","kafka"  and "etcdraft"
    OrdererType: kafka

    Addresses:
        - orderer0.test.com:7050
        - orderer1.test.com:7050
        - orderer2.test.com:7050

    # Batch Timeout: The amount of time to wait before creating a batch
    BatchTimeout: 2s

    # Batch Size: Controls the number of messages batched into a block
    BatchSize:

        # Max Message Count: The maximum number of messages to permit in a batch
        MaxMessageCount: 10

        # Absolute Max Bytes: The absolute maximum number of bytes allowed for
        # the serialized messages in a batch.
        AbsoluteMaxBytes: 99 MB

        # Preferred Max Bytes: The preferred maximum number of bytes allowed for
        # the serialized messages in a batch. A message larger than the preferred
        # max bytes will result in a batch larger than preferred max bytes.
        PreferredMaxBytes: 512 KB

    Kafka:
        # Brokers: A list of Kafka brokers to which the orderer connects
        # NOTE: Use IP:port notation
        Brokers:
            - kafka0:9092
            - kafka1:9092
            - kafka2:9092
            - kafka3:9092

4、 To configure docker-compose.yml file

4.1、 To configure zookeeper The server

ZooKeeper part :( If it is multi machine and multi node , Then this part is a separate one zookeeper.yaml file )

version: '2'

services:
  zookeeper1:
    container_name: zookeeper1
    hostname:zookeeper1
    image: hyperledger/fabric-zookeeper:latest
    #restart:always
    environment:
    #ID Must be unique in the set and should have a value , stay 1-255 Between ( The current location of the server in the cluster zookeerper Server node's ID)
      -  ZOO_MY_ID=1
      #server.x = hostname:port1:port2
      -  ZOO_SERVERS=server.1=zookeeper1:2888:3888 server.2=zookeeper2:2888:3888 server.3=zookeeper3:2888:3888
    port:
      - '2181'
      - '2888'
      - '3888'
      extra_hosts:
        - "zookeeper1:192.168.1.1"
        - "zookeeper2:192.168.1.2"
        - "zookeeper3:192.168.1.3"
        - "kafka1:127.0.0.1"
        - "kafka2:127.0.0.2"
        - "kafka1:127.0.0.3"
        - "kafka2:127.0.0.4"
        
   zookeeper2:
    container_name: zookeeper2
    hostname:zookeeper2
    environment:
    #ID Must be unique in the set and should have a value , stay 1-255 Between ( The current location of the server in the cluster zookeerper Server node's ID)
      -  ZOO_MY_ID=2
 

Configuration item explanation :

ZOO_SERVERS:

  • zookeeper List of cluster servers
  • Two port numbers
    • first : Followers are used to connect leader Use
    • the second : User election leader

Three ports port:

  • visit zookeeper The port of :2181
  • zookeeper Followers in the cluster connect leader The port of :2888
  • zookeeper Election in a cluster leader The port of :3888

4.2、kafka Cluster configuration and orderer node

#
# Copyright IBM Corp All Rights Reserved
#
# SPDX-License-Identifier: Apache-2.0
#
version: '2'

networks:
  default:

services:
  ca.innovation.com:
    image: hyperledger/fabric-ca
    environment:
      - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
      - FABRIC_CA_SERVER_CA_NAME=ca.innovation.com
      - FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org1.innovation.com-cert.pem
      - FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/fc0d22c49db02855470082d05e7933353bb06cf3c1b899164843b0e2de1e674e_sk
      - FABRIC_CA_SERVER_TLS_ENABLED=true
      - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org1.innovation.com-cert.pem
      - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/fc0d22c49db02855470082d05e7933353bb06cf3c1b899164843b0e2de1e674e_sk
    ports:
      - "7054:7054"
    command: sh -c 'fabric-ca-server start -b admin:adminpw'
    volumes:
      - ./crypto-config/peerOrganizations/org1.innovation.com/ca/:/etc/hyperledger/fabric-ca-server-config
    container_name: ca.innovation.com
    networks:
      default:
        aliases:
          - ca.innovation.com

  orderer1.innovation.com:
    container_name: orderer1.innovation.com
    image: hyperledger/fabric-orderer
    environment:
      - ORDERER_GENERAL_LOGLEVEL=debug
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_LISTENPORT=7050
      - ORDERER_GENERAL_GENESISPROFILE=business
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
      #kafka
      - CONFIGTX_ORDERER_ORDERERTYPE=kafka
      - CONFIGTX_ORDERER_KAFKA_BROKERS=[kafka:9092,kafka1:9092,kafka2:9092,kafka3:9092]
      # The first stage 
      #orderer Node connection kafka May fail ,ORDERER_KAFKA_RETRY_SHORTINTERVAL For the interval between retries 
      - ORDERER_KAFKA_RETRY_SHORTINTERVAL=1s
      # Total time to try again 
      - ORDERER_KAFKA_RETRY_SHORTTOTAL=30s
      # The second stage 
      # interval ORDERER_KAFKA_RETRY_LONGINTERVAL Start trying to connect again 
      - ORDERER_KAFKA_RETRY_LONGINTERVAL=10s
      # Total time to try 
      -ORDERER_KAFKA_RETRY_LONGTOTAL=100s
      - ORDERER_KAFKA_VERBOSE=true
      #TLS
      - 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]
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
    command: orderer
    depends_on:
      - kafka0
      - kafka1
      - kafka2
      - kafka3
    ports:
      - 7050:7050
    volumes:
        - ./channel-artifacts/genesis.block:/var/hyperledger/orderer/genesis.block
        - ./crypto-config/ordererOrganizations/innovation.com/orderers/orderer.innovation.com/msp:/var/hyperledger/orderer/msp
        - ./crypto-config/ordererOrganizations/innovation.com/orderers/orderer.innovation.com/tls:/var/hyperledger/orderer/tls
    networks:
      default:
        aliases:
          - orderer1.innovation.com

  orderer2.innovation.com:
    container_name: orderer2.innovation.com
    image: hyperledger/fabric-orderer
    environment:
      - ORDERER_GENERAL_LOGLEVEL=debug
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_LISTENPORT=7050
      - ORDERER_GENERAL_GENESISPROFILE=business
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
      #kafka
      - CONFIGTX_ORDERER_ORDERERTYPE=kafka
      - CONFIGTX_ORDERER_KAFKA_BROKERS=[kafka:9092,kafka1:9092,kafka2:9092,kafka3:9092]
      - ORDERER_KAFKA_RETRY_SHORTINTERVAL=1s
      - ORDERER_KAFKA_RETRY_SHORTTOTAL=30s
      - ORDERER_KAFKA_VERBOSE=true
      #TLS
      - 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]
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
    command: orderer
    depends_on:
      - kafka0
      - kafka1
      - kafka2
      - kafka3
    ports:
      - 7050:7050
    volumes:
      - ./channel-artifacts/genesis.block:/var/hyperledger/orderer/genesis.block
      - ./crypto-config/ordererOrganizations/innovation.com/orderers/orderer.innovation.com/msp:/var/hyperledger/orderer/msp
      - ./crypto-config/ordererOrganizations/innovation.com/orderers/orderer.innovation.com/tls:/var/hyperledger/orderer/tls
    networks:
      default:
        aliases:
          - orderer2.innovation.com

  orderer0.innovation.com:
    container_name: orderer0.innovation.com
    image: hyperledger/fabric-orderer
    environment:
      - ORDERER_GENERAL_LOGLEVEL=debug
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_LISTENPORT=7050
      - ORDERER_GENERAL_GENESISPROFILE=business
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
      #kafka
      - CONFIGTX_ORDERER_ORDERERTYPE=kafka
      - CONFIGTX_ORDERER_KAFKA_BROKERS=[kafka:9092,kafka1:9092,kafka2:9092,kafka3:9092]
      - ORDERER_KAFKA_RETRY_SHORTINTERVAL=1s
      - ORDERER_KAFKA_RETRY_SHORTTOTAL=30s
      - ORDERER_KAFKA_VERBOSE=true
      #TLS
      - 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]
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
    command: orderer
    depends_on:
      - kafka0
      - kafka1
      - kafka2
      - kafka3
    ports:
      - 7050:7050
    volumes:
      - ./channel-artifacts/genesis.block:/var/hyperledger/orderer/genesis.block
      - ./crypto-config/ordererOrganizations/innovation.com/orderers/orderer.innovation.com/msp:/var/hyperledger/orderer/msp
      - ./crypto-config/ordererOrganizations/innovation.com/orderers/orderer.innovation.com/tls:/var/hyperledger/orderer/tls
    networks:
      default:
        aliases:
          - orderer0.innovation.com

  peer0.org1.innovation.com:
    container_name: peer0.org1.innovation.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_ATTACHSTDOUT=true
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_CHAINCODE_LOGGING_LEVEL=info
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_NETWORKID=business
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/var/hyperledger/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/var/hyperledger/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/var/hyperledger/tls/ca.crt
      - CORE_PEER_ID=peer0.org1.innovation.com
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_PEER_ADDRESS=peer0.org1.innovation.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.innovation.com:7051
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
      - CORE_PEER_LOCALMSPID=org1.innovation.com
      - CORE_PEER_MSPCONFIGPATH=/var/hyperledger/msp
      - CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer0.org1.innovation.com
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
    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.innovation.com/peers/peer0.org1.innovation.com/msp:/var/hyperledger/msp
        - ./crypto-config/peerOrganizations/org1.innovation.com/peers/peer0.org1.innovation.com/tls:/var/hyperledger/tls
    depends_on:
      - orderer.innovation.com
      - couchdb
    networks:
      default:
        aliases:
          - peer0.org1.innovation.com

  peer1.org1.innovation.com:
    container_name: peer1.org1.innovation.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_ATTACHSTDOUT=true
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_CHAINCODE_LOGGING_LEVEL=info
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_NETWORKID=business
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/var/hyperledger/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/var/hyperledger/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/var/hyperledger/tls/ca.crt
      - CORE_PEER_ID=peer1.org1.innovation.com
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_PEER_ADDRESS=peer1.org1.innovation.com:7151
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.innovation.com:7151
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
      - CORE_PEER_LOCALMSPID=org1.innovation.com
      - CORE_PEER_MSPCONFIGPATH=/var/hyperledger/msp
      - CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer1.org1.innovation.com
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 7151:7151
      - 7153:7153
    volumes:
        - /var/run/:/host/var/run/
        - ./crypto-config/peerOrganizations/org1.innovation.com/peers/peer1.org1.innovation.com/msp:/var/hyperledger/msp
        - ./crypto-config/peerOrganizations/org1.innovation.com/peers/peer1.org1.innovation.com/tls:/var/hyperledger/tls
    depends_on:
      - orderer.innovation.com
      - couchdb
    networks:
      default:
        aliases:
          - peer1.org1.innovation.com


  peer0.org2.innovation.com:
    container_name: peer0.org2.innovation.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_ATTACHSTDOUT=true
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_CHAINCODE_LOGGING_LEVEL=info
      - CORE_PEER_LOCALMSPID=Org2MSP
      - CORE_PEER_NETWORKID=business
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/var/hyperledger/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/var/hyperledger/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/var/hyperledger/tls/ca.crt
      - CORE_PEER_ID=peer0.org2.innovation.com
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_PEER_ADDRESS=peer0.org2.innovation.com:7251
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.innovation.com:7251
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
      - CORE_PEER_LOCALMSPID=org2.innovation.com
      - CORE_PEER_MSPCONFIGPATH=/var/hyperledger/msp
      - CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer0.org2.innovation.com
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 7251:7251
      - 7253:7253
    volumes:
        - /var/run/:/host/var/run/
        - ./crypto-config/peerOrganizations/org2.innovation.com/peers/peer0.org2.innovation.com/msp:/var/hyperledger/msp
        - ./crypto-config/peerOrganizations/org2.innovation.com/peers/peer0.org2.innovation.com/tls:/var/hyperledger/tls
    depends_on:
      - orderer.innovation.com
      - couchdb
    networks:
      default:
        aliases:
          - peer0.org2.innovation.com

  peer1.org2.innovation.com:
    container_name: peer1.org2.innovation.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_ATTACHSTDOUT=true
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_CHAINCODE_LOGGING_LEVEL=info
      - CORE_PEER_LOCALMSPID=Org2MSP
      - CORE_PEER_NETWORKID=business
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/var/hyperledger/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/var/hyperledger/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/var/hyperledger/tls/ca.crt
      - CORE_PEER_ID=peer1.org2.innovation.com
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_PEER_ADDRESS=peer1.org2.innovation.com:7351
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.innovation.com:7351
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
      - CORE_PEER_LOCALMSPID=org2.innovation.com
      - CORE_PEER_MSPCONFIGPATH=/var/hyperledger/msp
      - CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer1.org2.innovation.com
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 7351:7351
      - 7353:7353
    volumes:
        - /var/run/:/host/var/run/
        - ./crypto-config/peerOrganizations/org2.innovation.com/peers/peer1.org2.innovation.com/msp:/var/hyperledger/msp
        - ./crypto-config/peerOrganizations/org2.innovation.com/peers/peer1.org2.innovation.com/tls:/var/hyperledger/tls
    depends_on:
      - orderer.innovation.com
      - couchdb
    networks:
      default:
        aliases:
          - peer1.org2.innovation.com

  couchdb:
    container_name: couchdb
    image: hyperledger/fabric-couchdb
    # Populate the COUCHDB_USER and COUCHDB_PASSWORD to set an admin user and password
    # for CouchDB.  This will prevent CouchDB from operating in an "Admin Party" mode.
    environment:
      - COUCHDB_USER=
      - COUCHDB_PASSWORD=
    ports:
      - 5984:5984


  zookeeper1:
    container_name: zookeeper1
    environment:
      - ZOO_MY_ID=1
      - ZOO_SERVERS=server.1=zookeeper1:2888:3888 server.2=zookeeper2:2888:3888 server.3=zookeeper3:2888:3888
    ports:
    - '2181'
    - '2888'
    - '3888'
    networks:
      default:
        - aliases:
            - zookeeper1

  zookeeper2:
    container_name: zookeeper2
    environment:
      - ZOO_MY_ID=2
      - ZOO_SERVERS=server.1=zookeeper1:2888:3888 server.2=zookeeper2:2888:3888 server.3=zookeeper3:2888:3888
    ports:
      - '2181'
      - '2888'
      - '3888'
    networks:
      default:
        - aliases:
            - zookeeper2

  zookeeper3:
    container_name: zookeeper3
    environment:
      - ZOO_MY_ID=3
      - ZOO_SERVERS=server.1=zookeeper1:2888:3888 server.2=zookeeper2:2888:3888 server.3=zookeeper3:2888:3888
    ports:
      - '2181'
      - '2888'
      - '3888'
    networks:
      default:
        - aliases:
            - zookeeper3


  kafka0:
    container_name: kafka0
    environment:
    # At present kafka The server is in the cluster ID, Nonnegative number , Can't repeat 
      - KAFKA_BROKER_ID=0
      # identification log Log retention time , The official default is off , by -1
      - KAFKA_LOG_RETENTION_MS=-1
      # The maximum number of bytes of the message , and configtx.yaml Medium Orderer.BatchSize.AbsoluteMaxBytes Corresponding 
      # Because messages have headers , So it's a little higher than this , much 1M That's enough 
      - KAFKA_MESSAGE_MAX_BYTES=103809024
      # Maximum number of bytes copies , For each channel The number of bytes of the message obtained 
      #AbsoluteMaxBytes<KAFKA_REPLICA_FETCH_MAX_BYTES<= KAFKA_MESSAGE_MAX_BYTES
      - KAFKA_REPLICA_FETCH_MAX_BYTES=103809024
      # Choose the leader node without consensus , Set to false: Take a consensus selection leader node 
      - KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
      # Minimum synchronous backup , The value should be less than the environment variable KAFKA_DEFAULT_REPLICATION_FACTOR
      - KAFKA_MIN_INSYNC_REPLICAS=2
      # Default synchronous backup , The value is less than kafka Number of clusters 
      - KAFKA_DEFAULT_REPLICATION_FACTOR=3
      # Point to zookeeper Set of nodes 
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper1:2181,zookeeper2:2181,zookeeper3:2181
    depends_on:
      - zookeeper1
      - zookeeper2
      - zookeeper3
    ports:
    - '9092'
    networks:
      default:
        - aliases:
            - kafka0


  kafka1:
    container_name: kafka1
    environment:
      - KAFKA_BROKER_ID=0
      - KAFKA_LOG_RETENTION_MS=-1
      - KAFKA_MESSAGE_MAX_BYTES=103809024
      - KAFKA_REPLICA_FETCH_MAX_BYTES=103809024
      - KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
      - KAFKA_MIN_INSYNC_REPLICAS=2
      - KAFKA_DEFAULT_REPLICATION_FACTOR=3
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper1:2181,zookeeper2:2181,zookeeper3:2181
    depends_on:
      - zookeeper1
      - zookeeper2
      - zookeeper3
    ports:
      - '9092'
    networks:
      default:
        - aliases:
            - kafka1

  kafka2:
    container_name: kafka2
    environment:
      - KAFKA_BROKER_ID=0
      - KAFKA_LOG_RETENTION_MS=-1
      - KAFKA_MESSAGE_MAX_BYTES=103809024
      - KAFKA_REPLICA_FETCH_MAX_BYTES=103809024
      - KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
      - KAFKA_MIN_INSYNC_REPLICAS=2
      - KAFKA_DEFAULT_REPLICATION_FACTOR=3
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper1:2181,zookeeper2:2181,zookeeper3:2181
    depends_on:
      - zookeeper1
      - zookeeper2
      - zookeeper3
    ports:
      - '9092'
    networks:
      default:
        - aliases:
            - kafka2

  kafka3:
    container_name: kafka3
    environment:
      - KAFKA_BROKER_ID=0
      - KAFKA_LOG_RETENTION_MS=-1
      - KAFKA_MESSAGE_MAX_BYTES=103809024
      - KAFKA_REPLICA_FETCH_MAX_BYTES=103809024
      - KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
      - KAFKA_MIN_INSYNC_REPLICAS=2
      - KAFKA_DEFAULT_REPLICATION_FACTOR=3
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper1:2181,zookeeper2:2181,zookeeper3:2181
    depends_on:
      - zookeeper1
      - zookeeper2
      - zookeeper3
    ports:
      - '9092'
    networks:
      default:
        - aliases:
            - kafka3

Configuration item explanation

kafka0:
    container_name: kafka0
    environment:
    # At present kafka The server is in the cluster ID, Nonnegative number , Can't repeat 
      - KAFKA_BROKER_ID=0
      # identification log Log retention time , The official default is off , by -1
      - KAFKA_LOG_RETENTION_MS=-1
      # The maximum number of bytes of the message , and configtx.yaml Medium Orderer.BatchSize.AbsoluteMaxBytes Corresponding 
      # Because messages have headers , So it's a little higher than this , much 1M That's enough 
      - KAFKA_MESSAGE_MAX_BYTES=103809024
      # Maximum number of bytes copies , For each channel The number of bytes of the message obtained 
      #AbsoluteMaxBytes<KAFKA_REPLICA_FETCH_MAX_BYTES<= KAFKA_MESSAGE_MAX_BYTES
      - KAFKA_REPLICA_FETCH_MAX_BYTES=103809024
      # Choose the leader node without consensus , Set to false: Take a consensus selection leader node 
      - KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
      # Minimum synchronous backup , The value should be less than the environment variable KAFKA_DEFAULT_REPLICATION_FACTOR
      - KAFKA_MIN_INSYNC_REPLICAS=2
      # Default synchronous backup , The value is less than kafka Number of clusters 
      - KAFKA_DEFAULT_REPLICATION_FACTOR=3
      # Point to zookeeper Set of nodes 
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper1:2181,zookeeper2:2181,zookeeper3:2181
    depends_on:
      - zookeeper1
      - zookeeper2
      - zookeeper3
    ports:
    - '9092'
    networks:
      default:
        - aliases:
            - kafka0
            
            
            
orderer1.innovation.com:
    container_name: orderer1.innovation.com
    image: hyperledger/fabric-orderer
    environment:
      - ORDERER_GENERAL_LOGLEVEL=debug
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_LISTENPORT=7050
      - ORDERER_GENERAL_GENESISPROFILE=business
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
      #kafka
      - CONFIGTX_ORDERER_ORDERERTYPE=kafka
      - CONFIGTX_ORDERER_KAFKA_BROKERS=[kafka:9092,kafka1:9092,kafka2:9092,kafka3:9092]
      # The first stage 
      #orderer Node connection kafka May fail ,ORDERER_KAFKA_RETRY_SHORTINTERVAL For the interval between retries 
      - ORDERER_KAFKA_RETRY_SHORTINTERVAL=1s
      # Total time to try again 
      - ORDERER_KAFKA_RETRY_SHORTTOTAL=30s
      # The second stage 
      # interval ORDERER_KAFKA_RETRY_LONGINTERVAL Start trying to connect again 
      - ORDERER_KAFKA_RETRY_LONGINTERVAL=10s
      # Total time to try 
      -ORDERER_KAFKA_RETRY_LONGTOTAL=100s
      #orderer And kafka Write correspondence or not log journal 
      - ORDERER_KAFKA_VERBOSE=true
      #TLS
      - 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]
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderer
    command: orderer
    depends_on:
      - kafka0
      - kafka1
      - kafka2
      - kafka3
    ports:
      - 7050:7050
    volumes:
        - ./channel-artifacts/genesis.block:/var/hyperledger/orderer/genesis.block
        - ./crypto-config/ordererOrganizations/innovation.com/orderers/orderer.innovation.com/msp:/var/hyperledger/orderer/msp
        - ./crypto-config/ordererOrganizations/innovation.com/orderers/orderer.innovation.com/tls:/var/hyperledger/orderer/tls
    networks:
      default:
        aliases:
          - orderer1.innovation.com

5、 Cluster startup

Startup sequence :zookeeper colony ,kafka colony ,orderer colony

The starting sequence should not be wrong , During startup, you can check whether the node log is started successfully , For example, view zookeeper1

docker logs zookeeper1

5.1、zookeeper Cluster start

  • zookeeper1

1、 Enter the working directory of the current node ,~/kafka

2、 Deploy the written configuration file to the current host ~/kafka Catalog zookeeper.yaml

3、 start-up docker-compose

docker-compose -f zookeeper1.yaml up -d

  • zookeeper2

1、 Enter the working directory of the current node ,~/kafka

2、 Deploy the written configuration file to the current host ~/kafka Catalog zookeeper.yaml

3、 start-up docker-compose

docker-compose -f zookeeper2.yaml up -d

  • zookeeper3

1、 Enter the working directory of the current node ,~/kafka

2、 Deploy the written configuration file to the current host ~/kafka Catalog zookeeper.yaml

3、 start-up docker-compose

docker-compose -f zookeeper3.yaml up -d

5.2、kafka Cluster start

The first kafka, And then it starts in turn

1、 Enter the working directory of the current node ,~/kafka

2、 Deploy the written configuration file to the current host ~/kafka Catalog kafka0.yaml

3、 start-up docker-compose

docker-compose -f kafka0.yaml up -d

5.3、orderer Cluster start

  • orderer0

    1、 Enter the working directory of the current node ,~/kafka

    2、 Deploy the written configuration file to the current host ~/kafka Catalog kafka0.yaml

    3、 First, deploy the creation block and the certificate to the host file

    4、 start-up docker-compose

    docker-compose -f orderer0.yaml up -d

版权声明
本文为[The wind and clouds are proud of the sky]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201225110220283g.html

Scroll to Top