基于Kafka的网络中的多订购者冗余

时间:2018-10-02 10:48:19

标签: apache-kafka hyperledger-fabric hyperledger

我们一直在基于3个组织(每个组织1个对等方和2个基于kafka的订购者)配置光纤网络。对于kafka订购,我们使用4个kafka节点和3个动物园管理员。它已按如下所示部署在某些AWS ec2实例上:

1:Org1

2:组织2

3:Org3

4:orderer0,orderer1,kafka0,kafka1,kafka2,kafka3,zookeeper0,zookeeper1,zookeeper2

出于连接方面的原因,整个订购节点以及kafka群集都位于同一台计算机中(请阅读它们必须位于同一台计算机中的某个位置,以避免出现这些问题)

在测试期间,我们尝试取下第一个订购者(orderer0)进行docker stop冗余测试。我们希望该网络可以继续通过orderer1工作,但是它会死掉并停止工作。

看对等控制台,我可以看到一些错误。

  

无法连接到任何端点:[orderer0.example.com:7050,orderer1.example.com:8050]

查找附件中与系统配置相关的文件的内容。

订购者+ kafka + zk

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

services:

  zookeeper0.example.com:
    container_name: zookeeper0.example.com
    extends:
      file: docker-compose-base.yaml
      service: zookeeper0.example.com
    logging:
     driver: "json-file"
     options:
      max-size: "1m"
      max-file: "3"

  zookeeper1.example.com:
    container_name: zookeeper1.example.com
    extends:
      file: docker-compose-base.yaml
      service: zookeeper1.example.com
    logging:
     driver: "json-file"
     options:
      max-size: "1m"
      max-file: "3"

  zookeeper2.example.com:
    container_name: zookeeper2.example.com
    extends:
      file: docker-compose-base.yaml
      service: zookeeper2.example.com
    logging:
     driver: "json-file" 
     options:
      max-size: "1m"
      max-file: "3"

  kafka0.example.com:
    container_name: kafka0.example.com
    extends:
      file: docker-compose-base.yaml
      service: kafka0.example.com
    depends_on:
      - zookeeper0.example.com
      - zookeeper1.example.com
      - zookeeper2.example.com
      - orderer0.example.com
      - orderer1.example.com
    logging:
     driver: "json-file"
     options:
      max-size: "1m"
      max-file: "3"

  kafka1.example.com:
    container_name: kafka1.example.com
    extends:
      file: docker-compose-base.yaml
      service: kafka1.example.com
    depends_on:
      - zookeeper0.example.com
      - zookeeper1.example.com
      - zookeeper2.example.com
      - orderer0.example.com
      - orderer1.example.com
    logging:
     driver: "json-file"
     options:
      max-size: "1m"
      max-file: "3"

  kafka2.example.com:
    container_name: kafka2.example.com
    extends:
      file: docker-compose-base.yaml
      service: kafka2.example.com
    depends_on:
      - zookeeper0.example.com
      - zookeeper1.example.com
      - zookeeper2.example.com
      - orderer0.example.com
      - orderer1.example.com
    logging:
     driver: "json-file"
     options:
      max-size: "1m"
      max-file: "3"

  kafka3.example.com:
    container_name: kafka3.example.com
    extends:
      file: docker-compose-base.yaml
      service: kafka3.example.com        
    depends_on:
      - zookeeper0.example.com
      - zookeeper1.example.com
      - zookeeper2.example.com
      - orderer0.example.com
      - orderer1.example.com
    logging:
     driver: "json-file"
     options:
      max-size: "1m"
      max-file: "3"

  orderer0.example.com:
    container_name: orderer0.example.com
    image: hyperledger/fabric-orderer:x86_64-1.1.0
    environment:
      - ORDERER_GENERAL_LOGLEVEL=debug
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_LISTEN_PORT=7050
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/etc/hyperledger/configtx/genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/crypto/orderer/msp
      - ORDERER_GENERAL_TLS_ENABLED=true
      - ORDERER_GENERAL_TLS_PRIVATEKEY=/etc/hyperledger/crypto/orderer/tls/server.key
      - ORDERER_GENERAL_TLS_CERTIFICATE=/etc/hyperledger/crypto/orderer/tls/server.crt
      - ORDERER_GENERAL_TLS_ROOTCAS=[/etc/hyperledger/crypto/orderer/tls/ca.crt, /etc/hyperledger/crypto/peerOrg1/tls/ca.crt, /etc/hyperledger/crypto/peerOrg2/tls/ca.crt, /etc/hyperledger/crypto/peerOrg3/tls/ca.crt]
    logging:
     driver: "json-file"
     options:
      max-size: "1m"
      max-file: "3"
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderers
    command: orderer
    ports:
      - 7050:7050
    volumes:
        - ./channel:/etc/hyperledger/configtx
        - ./channel/crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/:/etc/hyperledger/crypto/orderer
        - ./channel/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/:/etc/hyperledger/crypto/peerOrg1
        - ./channel/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/:/etc/hyperledger/crypto/peerOrg2
        - ./channel/crypto-config/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/:/etc/hyperledger/crypto/peerOrg3
    depends_on:
        - kafka0.example.com
        - kafka1.example.com
        - kafka2.example.com
        - kafka3.example.com

  orderer1.example.com:
    container_name: orderer1.example.com
    image: hyperledger/fabric-orderer:x86_64-1.1.0
    environment:
      - ORDERER_GEN ERAL_LOGLEVEL=debug
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_LISTEN_PORT=8050
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/etc/hyperledger/configtx/genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/crypto/orderer/msp
      - ORDERER_GENERAL_TLS_ENABLED=true
      - ORDERER_GENERAL_TLS_PRIVATEKEY=/etc/hyperledger/crypto/orderer/tls/server.key
      - ORDERER_GENERAL_TLS_CERTIFICATE=/etc/hyperledger/crypto/orderer/tls/server.crt
      - ORDERER_GENERAL_TLS_ROOTCAS=[/etc/hyperledger/crypto/orderer/tls/ca.crt, /etc/hyperledger/crypto/peerOrg1/tls/ca.crt, /etc/hyperledger/crypto/peerOrg2/tls/ca.crt, /etc/hyperledger/crypto/peerOrg3/tls/ca.crt]
    logging:
     driver: "json-file"
     options:
      max-size: "1m"
      max-file: "3"
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/orderers
    command: orderer
    ports:
      - 8050:7050
    volumes:
        - ./channel:/etc/hyperledger/configtx
        - ./channel/crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/:/etc/hyperledger/crypto/orderer
        - ./channel/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/:/etc/hyperledger/crypto/peerOrg1
        - ./channel/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/:/etc/hyperledger/crypto/peerOrg2
        - ./channel/crypto-config/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/:/etc/hyperledger/crypto/peerOrg3
    depends_on:
        - kafka0.example.com
        - kafka1.example.com
        - kafka2.example.com
        - kafka3.example.com

Org2中的Pe和Ca

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

services:

  ca.org2.example.com:
    image: hyperledger/fabric-ca:x86_64-1.1.0
    environment:
      - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
      - FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org2.example.com-cert.pem
      - FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/efa7d0819b7083f6c06eb34da414acbcde79f607b9ce26fb04dee60cf79a389a_sk
      - FABRIC_CA_SERVER_TLS_ENABLED=true
      - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org2.example.com-cert.pem
      - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/efa7d0819b7083f6c06eb34da414acbcde79f607b9ce26fb04dee60cf79a389a_sk
    ports:
      - "8054:7054"
    command: sh -c 'fabric-ca-server start -b admin:adminpw -d'
    volumes:
      - ./channel/crypto-config/peerOrganizations/org2.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
    container_name: ca_peerOrg2

  peer0.org2.example.com:
    container_name: peer0.org2.example.com
    extends:
      file:   base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer0.org2.example.com
      - CORE_PEER_LOCALMSPID=Org2MSP
      - CORE_PEER_ADDRESS=peer0.org2.example.com:7051
    ports:
      - 8051:7051
      - 8053:7053
    volumes:
        - ./channel/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/:/etc/hyperledger/crypto/peer
    logging:
     driver: "json-file"
     options:
      max-size: "1m"
      max-file: "3"
    extra_hosts:
      - "orderer0.example.com:xxx.xxx.xxx.xxx"
      - "orderer1.example.com:xxx.xxx.xxx.xxx"
      - "kafka0.example.com:xxx.xxx.xxx.xxx"
      - "kafka1.example.com:xxx.xxx.xxx.xxx"
      - "kafka2.example.com:xxx.xxx.xxx.xxx"
      - "kafka3.example.com:xxx.xxx.xxx.xxx"

订购者基础

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

version: '2'

services:

  orderer-base:
    image: hyperledger/fabric-orderer:$IMAGE_TAG
    environment:
      - ORDERER_GENERAL_LOGLEVEL=error
      - 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]
      # kafka
      - CONFIGTX_ORDERER_ORDERERTYPE=kafka
      - CONFIGTX_ORDERER_KAFKA_BROKERS=[kafka0.example.com,kafka1.example.com,kafka2.example.com,kafka3.example.com]
      - ORDERER_KAFKA_RETRY_SHORTINTERVAL=1s
      - ORDERER_KAFKA_RETRY_SHORTTOTAL=30s
      - ORDERER_KAFKA_VERBOSE=true
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: orderer

卡夫卡基地

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

version: '2'

services:

  zookeeper:
    image: hyperledger/fabric-zookeeper
    environment:
      - ZOO_SERVERS=server.1=zookeeper0.example.com:2888:3888 server.2=zookeeper1.example.com:2888:3888 server.3=zookeeper2.example.com:2888:3888
    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_UNCLEAN_LEADER_ELECTION_ENABLE=false
      - KAFKA_MIN_INSYNC_REPLICAS=2
      - KAFKA_DEFAULT_REPLICATION_FACTOR=3
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper0.example.com:2181,zookeeper1.example.com:2181,zookeeper2.example.com:2181
    logging:
     driver: "json-file"
     options:
      max-size: "1m"
      max-file: "3"

configtx.yaml

Organizations:


    - &OrdererOrg

        Name: OrdererMSP


        ID: OrdererMSP


        MSPDir: crypto-config/ordererOrganizations/example.com/msp

    - &Org1

        Name: Org1MSP


        ID: Org1MSP

        MSPDir: crypto-config/peerOrganizations/org1.example.com/msp

        AnchorPeers:

            - Host: peer0.org1.example.com
              Port: 7051

    - &Org2

        Name: Org2MSP

        ID: Org2MSP

        MSPDir: crypto-config/peerOrganizations/org2.example.com/msp

        AnchorPeers:

            - Host: peer0.org2.example.com
              Port: 7051

    - &Org3

        Name: Org3MSP


        ID: Org3MSP

        MSPDir: crypto-config/peerOrganizations/org3.example.com/msp

        AnchorPeers:

            - Host: peer0.org3.example.com
              Port: 7051



################################################################################
Orderer: &OrdererDefaults


    OrdererType: kafka

    Addresses:
        - orderer0.example.com:7050
        - orderer1.example.com:7050


    BatchTimeout: 2s


    BatchSize:

        MaxMessageCount: 10

        AbsoluteMaxBytes: 98 MB

        PreferredMaxBytes: 512 KB

    Kafka:
        Brokers:
            - kafka0.example.com:9092
            - kafka1.example.com:9092
            - kafka2.example.com:9092
            - kafka3.example.com:9092

    Organizations:


################################################################################
Application: &ApplicationDefaults

    Organizations:


################################################################################
Profiles:

    ThreeOrgsOrdererGenesis:
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *Org1
                    - *Org2
                    - *Org3
    ThreeOrgsChannel:
        Consortium: SampleConsortium
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org1
                - *Org2
                - *Org3

可能是配置错误?连接问题几乎被丢弃,因为在本地计算机上运行相同的网络会得到相同的结果。

预先感谢 问候

2 个答案:

答案 0 :(得分:2)

最终使它运行平稳。原来问题不是在docker-compose文件中,而是在用于Web服务的fabric sdk版本中。我在版本1.1上都使用了 fabric-client fabric-ca-client ,直到1.2都没有。 (更多信息https://jira.hyperledger.org/browse/FABN-90

请澄清一下,由于两个订购者之间的相互联系,我能够看到它们之间发生了交易,但是我只是在攻击第一个订购者。当该订购者发生故障时,网络就会变黑。

我了解结构处理订购者的方式,它指向列表中的第一个订购者,如果它掉落或无法访问,则将其移至列表的底部并定位下一个。这是从1.2开始发生的事情,在较早的版本中,您必须编写自己的错误控制器,以使其更改为下一个订购者。

答案 1 :(得分:0)

我不确定,但这可能是因为网络层不同。由于它是一个不同的撰写文件,因此docker会为每个撰写者创建不同的网络层。

此外,我在yaml文件中看不到网络。

请使用“ docker network list”检查网络层列表。