手记

Fabric kafka多机部署总结

1.修改configtx.yaml

  • 将OrdererType修改成kafka

  • 修改Addresses,这里我是设置了三个orderer:orderer0、orderer1、orderer2

  • 修改Kafka的Brokers,这里我使用三台虚拟机运行kafka

##################################################################################   SECTION: Orderer##   - This section defines the values to encode into a config transaction or#   genesis block for orderer related parameters#################################################################################Orderer: &OrdererDefaults    # Orderer Type: The orderer implementation to start
    # Available types are "solo" and "kafka"
    OrdererType: kafka

    Addresses:
        - orderer0.example.com:7050
        - orderer1.example.com:7050
        - orderer2.example.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: 98 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. Edit
        # this list to identify the brokers of the ordering service.
        # NOTE: Use IP:port notation.
        Brokers:
            - 10.10.12.30:9092
            - 10.10.12.31:9092
            - 10.10.12.32:9092    # Organizations is the list of orgs which are defined as participants on
    # the orderer side of the network
    Organizations:

2.修改crypto-config.yaml

修改Specs,设置三个orderer:orderer0、orderer1、orderer2

# ---------------------------------------------------------------------------# "OrdererOrgs" - Definition of organizations managing orderer nodes# ---------------------------------------------------------------------------OrdererOrgs:  # ---------------------------------------------------------------------------
  # Orderer
  # ---------------------------------------------------------------------------
  - Name: Orderer
    Domain: example.com
    CA:
        Country: US
        Province: California
        Locality: San Francisco    # ---------------------------------------------------------------------------
    # "Specs" - See PeerOrgs below for complete description
    # ---------------------------------------------------------------------------
    Specs:
      - Hostname: orderer0
      - Hostname: orderer1
      - Hostname: orderer2# ---------------------------------------------------------------------------# "PeerOrgs" - Definition of organizations managing peer nodes# ---------------------------------------------------------------------------

3.生成channe-artifacts和crypto-config文件

在e2e_cli目录下,打开命令终端,执行如下命令:

./generateArtifacts.sh

执行完毕后,会在e2e_cli目录下生成channel-artifacts和crypto-config两个文件夹。内容分别如下:
channel-artifacts:


channel-artifacts.png

crypto-config/ordererOrgnizations/example.com/orderers目录如下:

orderers.png

生成的channel-artifacts和crypto-config文件夹要拷贝到其他节点,确保不同org使用同一套文件

4.配置zookeeper.yaml

  • 创建zookeeper.yaml(我创建了三个zookeeper节点zookeeper0、zookeeper1、zookeeper2,所以也创建了三个配置文件:zookeeper0.yaml、zookeeper1.yaml、zookeeper2.yaml),我们以zookeeper0.yaml为例说明

  • 修改service名称为zookeeper0

  • 修改container_namezookeeper0

  • 修改-ZOO_MY_ID等于1(此ID是zookeeper节点在集群中的唯一标识,不可重复,我定义的是1 、 2 、3)

  • 修改extra_hosts中的zookeeper0映射的ip为0.0.0.0(同理zookeeper1/2.yaml文件中zookeeper1/2映射的ip为0.0.0.0

# Copyright IBM Corp. All Rights Reserved.## SPDX-License-Identifier: Apache-2.0## ZooKeeper的基本运转流程:# 1、选举Leader。# 2、同步数据。# 3、选举Leader过程中算法有很多,但要达到的选举标准是一致的。# 4、Leader要具有最高的执行ID,类似root权限。# 5、集群中大多数的机器得到响应并follow选出的Leader。version: '2'services:
  zookeeper0:                  #1. 三个配置文件中此处分别为zookeeper0、zookeeper1、zookeeper2
    container_name: zookeeper0         #2. 三个配置文件的container_name分别为zookeeper0、zookeeper1、zookeeper2
    image: hyperledger/fabric-zookeeper
    restart: always
    environment:
      - ZOO_MY_ID=1            #3. ZOO_MY_ID是zookeeper节点在集群中的唯一标识,不可重复,我分别定义成1 、 2 、3
      - ZOO_SERVERS=server.1=zookeeper0:2888:3888 server.2=zookeeper1:2888:3888 server.3=zookeeper2:2888:3888

    ports:
      - "2181:2181"
      - "2888:2888"
      - "3888:3888"
    extra_hosts:
      - "zookeeper0:0.0.0.0"   #zookeeper0.yaml文件中zookeeper0映射的ip改成0.0.0.0,
      - "zookeeper1:10.10.12.31"
      - "zookeeper2:10.10.12.32"
      - "kafka0:10.10.12.30"
      - "kafka1:10.10.12.31"
      - "kafka2:10.10.12.32"

5.修改kafka.yaml

  • 创建kafka.yaml文件(我创建了3个kafka节点kafka0、kafka1、kafka2,所以也创建了三个配置文件kafka0.yaml、kafka1.yaml、kafka2.yaml),以kafka0.yaml为例进行说明

  • service名称修改成kafka0

  • container_name名称修改成kafka0

  • 添加hostname,并将名称改为kafka0

  • 修改KAFKA_BROKER_ID=0(此ID为kafka节点在集群中的唯一标识,不可重复,我定义的是0\1\2)

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

  kafka0:
     container_name: kafka0
     hostname: kafka0
     image: hyperledger/fabric-kafka
     restart: always
     environment:
      - KAFKA_BROKER_ID=0
      - KAFKA_MIN_INSYNC_REPLICAS=2
      - KAFKA_DEFAULT_REPLICATION_FACTOR=3
      - KAFKA_ZOOKEEPER_CONNECT=10.10.12.30:2181,10.10.12.31:2181,10.10.12.32:2181
      - KAFKA_MESSAGE_MAX_BYTES=103809024 # 99 * 1024 * 1024 B
      - KAFKA_REPLICA_FETCH_MAX_BYTES=103809024 # 99 * 1024 * 1024 B
      - KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false

     ports:
       - "9092:9092"
     extra_hosts:
      - "zookeeper0:10.10.12.30"
      - "zookeeper1:10.10.12.31"
      - "zookeeper2:10.10.12.32"
      - "kafka0:10.10.12.30"
      - "kafka1:10.10.12.31"
      - "kafka2:10.10.12.32"

6.修改orderer.yaml

  • 创建orderer.yaml(我创建了三个orderer节点:orderer0、orderer1、orderer2,所以也创建了三个orderer配置文件:orderer0.yaml、orderer1.yaml、orderer2.yaml)。这里以orderer0.yaml为例进行说明

  • service名称改为orderer0.example.com

  • container_name名称改为orderer0.example.com

  • ORDERER_KAFKA_BROKERS集合改成[10.10.12.30:9092,10.10.12.31:9092,10.10.12.32:9092](此处为三个kafka节点的地址)

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

  orderer0.example.com:
    container_name: orderer0.example.com
    image: hyperledger/fabric-orderer
    environment:
      - ORDERER_GENERAL_LOGLEVEL=debug
      - 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      # 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]
      - ORDERER_KAFKA_RETRY_SHORTINTERVAL=1s
      - ORDERER_KAFKA_RETRY_SHORTTOTAL=30s
      - ORDERER_KAFKA_VERBOSE=true
      - ORDERER_KAFKA_BROKERS=[10.10.12.30:9092,10.10.12.31:9092,10.10.12.32:9092]
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: orderer
    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
    extra_hosts:
      - "kafka0:10.10.12.30"
      - "kafka1:10.10.12.31"
      - "kafka2:10.10.12.32"

7.修改peer.yaml

  • 创建peer.yaml(我创建了2个org,每个org有两个peer,所以相应地创建了四个peer.yaml文件:docker-compose-peer0org1.yaml、docker-compose-peer1org1.yaml、docker-compose-peer0org2.yaml、docker-compose-peer0org2.yaml)。这里以docker-compose-peer0org1.yaml为例进行说明

  • 需要特别说明的是,environment中的路径每个节点未必相同(peer0、peer1、org1、org2)

# Copyright IBM Corp. All Rights Reserved.## SPDX-License-Identifier: Apache-2.0#version: '2'services:
  peer0.org1.example.com:
    container_name: peer0.org1.example.com
    extends:
      file:  base/docker-compose-base.yaml
      service: peer0.org1.example.com
    extra_hosts:
      - "orderer0.example.com:10.10.12.30"
      - "orderer1.example.com:10.10.12.31"
      - "orderer2.example.com:10.10.12.32"
  cli:
    container_name: cli
    image: hyperledger/fabric-tools
    tty: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_ID=cli
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_LOCALMSPTYPE=bccsp
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer#    command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT'
    volumes:
        - /var/run/:/host/var/run/
        - ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
        - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
        - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
        - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    depends_on:
      - peer0.org1.example.com
    extra_hosts:
      - "orderer0.example.com:10.10.12.30"
      - "orderer1.example.com:10.10.12.31"
      - "orderer2.example.com:10.10.12.32"
      - "peer0.org1.example.com:10.10.12.30"
      - "peer1.org1.example.com:10.10.12.31"
      - "peer0.org2.example.com:10.10.12.32"
      - "peer1.org2.example.com:10.10.12.33"



作者:通若
链接:https://www.jianshu.com/p/e8ae5da6d21c


0人推荐
随时随地看视频
慕课网APP