Hyperledger fabric multihost setup for first-network example

hyperledger fabric network setup
how can i set up hyperledger fabric with multiple hosts using docker
multi host hyperledger fabric
hyperledger fabric network design & setup
hyperledger fabric production deployment
how to deploy hyperledger fabric network
hyperledger fabric multiple organizations
hyperledger fabric orderer configuration

I am trying to setup first-network example on a Multihost environment using docker swarm with below configuration to begin with:

HOST1

  • Orderer
  • Org1-pee0
  • Org1-peer1
  • CLI

HOST2

  • Org2-pee0
  • Org2-pee1

I have only changed the docker-compose-cli.yaml to make it compatible with swarm(code given below). I am not able to add the Host2 / Org2 peers to channel.

Executing the below steps in order:

  • byfn -m generate
  • docker stack deploy --compose-file docker-compose-cli.yaml overnet
  • Enter the CLI docker and execute ./scripts/script.sh mychannel

I keep getting the below error

2017-08-15 02:42:49.512 UTC [msp] GetDefaultSigningIdentity -> DEBU 006 Obtaining default signing identity Error: Error getting endorser client channel: PER:404 - Error trying to connect to local peer /opt/gopath/src/github.com/hyperledger/fabric/peer/common/common.go:116 github.com/hyperledger/fabric/peer/common.GetEndorserClient /opt/gopath/src/github.com/hyperledger/fabric/peer/channel/channel.go:149 github.com/hyperledger/fabric/peer/channel.InitCmdFactory /opt/gopath/src/github.com/hyperledger/fabric/peer/channel/join.go:138 github.com/hyperledger/fabric/peer/channel.join /opt/gopath/src/github.com/hyperledger/fabric/peer/channel/join.go:42 github.com/hyperledger/fabric/peer/channel.joinCmd.func1 /opt/gopath/src/github.com/hyperledger/fabric/vendor/github.com/spf13/cobra/command.go:599 github.com/hyperledger/fabric/vendor/github.com/spf13/cobra.(*Command).execute /opt/gopath/src/github.com/hyperledger/fabric/vendor/github.com/spf13/cobra/command.go:689 github.com/hyperledger/fabric/vendor/github.com/spf13/cobra.(*Command).ExecuteC /opt/gopath/src/github.com/hyperledger/fabric/vendor/github.com/spf13/cobra/command.go:648 github.com/hyperledger/fabric/vendor/github.com/spf13/cobra.(*Command).Execute /opt/gopath/src/github.com/hyperledger/fabric/peer/main.go:118 main.main /opt/go/src/runtime/proc.go:192 runtime.main /opt/go/src/runtime/asm_amd64.s:2087 runtime.goexit Caused by: x509: certificate is valid for peer0.org1.example.com, peer0, not peer0.org2.example.com

docker-compose-cli.yaml

Orderer

version: '3'
networks:
  overnet:

services:

  orderer_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]
    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/orderer.example.com/msp:/var/hyperledger/orderer/msp
    - ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
    ports:
      - 7050:7050
#      - 7049:7049
    networks:
      - overnet
    deploy:
       replicas: 1
       placement:
          constraints: [node.role == manager]

Org1 Peers

  peer0_org1_example_com:
    image: hyperledger/fabric-peer
    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
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      # the following setting starts chaincode containers on the same
      # bridge network as the peers
      # https://docs.docker.com/compose/networking/
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=overnet
      - 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
      - CORE_PEER_ID=peer0.org1.example.com
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    networks:
      - overnet
    deploy:
       replicas: 1
       placement:
          constraints: [node.role == manager]

Org2 Peers

  peer0_org2_example_com:
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      # the following setting starts chaincode containers on the same
      # bridge network as the peers
      # https://docs.docker.com/compose/networking/
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=overnet
      - 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
      - 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_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
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    networks:
      - overnet
    deploy:
       mode: replicated
       replicas: 1
       placement:
          constraints: [node.role == worker]

CLI

  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.org2.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org4.example.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.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/:/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:
      - orderer_example_com
      - peer0_org1_example_com
      - peer1_org1_example_com
      - peer0_org2_example_com
      - peer1_org2_example_com
    networks:
      - overnet
    deploy:
       replicas: 1
       placement:
          constraints: [node.role == manager]

crypto-config.yaml (Did not make any changes this file, however attaching here for reference)

OrdererOrgs:
  # ------------------------------------------------------------------
  # Orderer
  # ------------------------------------------------------------------ 

  - Name: Orderer
    Domain: example.com
    # ----------------------------------------------------------------
    # "Specs" - See PeerOrgs below for complete description
    # ----------------------------------------------------------------
    Specs:
      - Hostname: orderer
# --------------------------------------------------------------------
# "PeerOrgs" - Definition of organizations managing peer nodes
# --------------------------------------------------------------------
PeerOrgs:
# ------------------------------------------------------------------
  # Org1
  # ------------------------------------------------------------------
  - Name: Org1
    Domain: org1.example.com
    # ----------------------------------------------------------------
    # "Specs"
    # ----------------------------------------------------------------
    # Uncomment this section to enable the explicit definition of hosts in your
# configuration.  Most users will want to use Template, below
#
# Specs is an array of Spec entries.  Each Spec entry consists of two fields:
#   - Hostname:   (Required) The desired hostname, sans the domain.
#   - CommonName: (Optional) Specifies the template or explicit override for
#                 the CN.  By default, this is the template:
#
#                              "{{.Hostname}}.{{.Domain}}"
#
#                 which obtains its values from the Spec.Hostname and
#                 Org.Domain, respectively.
# ---------------------------------------------------------------------------
# Specs:
#   - Hostname: foo # implicitly "foo.org2.example.com"
#     CommonName: foo27.org5.example.com # overrides Hostname-based FQDN set above
#   - Hostname: bar
#   - Hostname: baz
# ---------------------------------------------------------------------------
# "Template"
# ---------------------------------------------------------------------------
# Allows for the definition of 1 or more hosts that are created sequentially
# from a template. By default, this looks like "peer%d" from 0 to Count-1.
# You may override the number of nodes (Count), the starting index (Start)
# or the template used to construct the name (Hostname).
#
# Note: Template and Specs are not mutually exclusive.  You may define both
# sections and the aggregate nodes will be created for you.  Take care with
# name collisions
# ---------------------------------------------------------------------------
Template:
  Count: 2
  # Start: 5
  # Hostname: {{.Prefix}}{{.Index}} # default
# ---------------------------------------------------------------------------
# "Users"
# ---------------------------------------------------------------------------
# Count: The number of user accounts _in addition_ to Admin
# ---------------------------------------------------------------------------
Users:
  Count: 1
  # ------------------------------------------------------------------
  # Org2: See "Org1" for full specification
  # ------------------------------------------------------------------
  - Name: Org2
    Domain: org2.example.com
    Template:
      Count: 2
    Users:
      Count: 1

I was able to host hyperledger fabric network on multiple machines using docker swarm mode. Swarm mode provides a network across multiple hosts/machines for the communication of the fabric network components.

This post explains the deployment process.It creates a swarm network and all the other machines join the network. https://medium.com/@wahabjawed/hyperledger-fabric-on-multiple-hosts-a33b08ef24f

Hyperledger fabric multihost setup for first-network example - html, I am trying to setup first-network example on a Multihost environment using docker swarm with below configuration to begin with: HOST1 Orderer Org1-pee0​  First Network Deployed in Local Host. These components inside First Network, when deployed in a local host, are implemented as containers. The docker images are pre-built by Hyperledger Fabric.

First of all, I think that you don't have to

Enter the CLI docker and execute ./scripts/script.sh mychannel

Or have you commented the docker compose file like is described in the "Start the network" step?

On the other hand, I tell you that I have achieved to setting up a Multihost environment using docker. However, instead of defining the network overlay, I defined the network_mode: host for all the docker containers that I'm going to start up.

Could you show the logs that are appearing in the Peer and in the Orderer?

Hyperledger Fabric on Multiple Hosts - Abdul Wahab, This tutorial requires you to first follow Build You First Network from the You will also need to download and install the Hyperledger Fabric Samples. The scripts utilizes the files in the “Build-Multi-Host-Network-Hyperledger” folder and will  The Build your first network (BYFN) tutorial has been deprecated. If you are getting started with Hyperledger Fabric and would like to deploy a basic network, see Using the Fabric test network. If you are deploying Fabric in production, see the guide for Deploying a production network.

I have set up the mutlihost setup of fabric network. My orderer and one peer is on one host and one peer is on 2nd host. For this we need to make changed in configtx.yml file for orderer section:

Profiles:
    CommonOrgsOrdererGenesis:
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
        Consortiums:
            SampleConsortiumJA:
                Organizations:
                    - *test
                    - *mch
                    - *test2
                    - *test3
    CommonOrgChannel:
        Consortium: SampleConsortiumJA
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *test
                - *mch
                - *test2
                - *test3    
    MJAOrgsOrdererGenesis:
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
        Consortiums:
            SampleConsortiumJA:
                Organizations:
                    - *test
                    - *mch
                    - *test2
    MJAOrgChannel:
        Consortium: SampleConsortiumJA
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *test
                - *mch
                - *test2
    MABOrgsOrdererGenesis:
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
        Consortiums:
            SampleConsortiumAB:
                Organizations:
                    - *test2
                    - *mch
                    - *test3
    MABOrgChannel:
        Consortium: SampleConsortiumAB
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *test
                - *mch
                - *test3
    MBJOrgsOrdererGenesis:
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
        Consortiums:
            SampleConsortiumBJ:
                Organizations:
                    - *test3
                    - *mch
                    - *test
    MBJOrgChannel:
        Consortium: SampleConsortiumBJ
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *test3
                - *mch
                - *test


Organizations:

    - &OrdererOrg

        Name: OrdererOrg

        # ID to load the MSP definition as
        ID: OrdererMSP

        MSPDir: crypto-config/ordererOrganizations/mch.test/msp

    - &test
          Name: test

        # ID to load the MSP definition as
        ID: testMSP

        MSPDir: crypto-config/peerOrganizations/test.test/msp

        AnchorPeers:

            - Host: peer0.test.test
              Port: 7054
    - &airtel
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: airtel

        # ID to load the MSP definition as
        ID: test2MSP

        MSPDir: crypto-config/peerOrganizations/test2.test/msp

        Anc
            - Host: peer0.test2.test
              Port: 7055
    - &bsnl
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: test3

        # ID to load the MSP definition as
        ID: test3MSP

        MSPDir: crypto-config/peerOrganizations/test3.test/msp

        AnchorPeers:
                 - Host: peer0.test3.test
              Port: 7059
    - &mch

        Name: mch

        # ID to load the MSP definition as
        ID: mchMSP

        MSPDir: crypto-config/peerOrganizations/mch.test/msp

        AnchorPeers:
             - Host: peer0.mch.test
              Port: 7051          

Orderer: &OrdererDefaults

    OrdererType: solo

    Addresses:
        - 10.64.253.213: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:

        MaxMessageCount: 10


        AbsoluteMaxBytes: 99 MB


        PreferredMaxBytes: 512 KB

    Kafka:

        Brokers:
            - 127.0.0.1:9092


    Organizations:


Application: &ApplicationDefaults

    Organizations:

===============================================================


after this pull up the orderer and peer1 on one server and peer2 on different server. Create channel using IP of orderer instead of name then copy the channel file to other peer also and join both peers one at a time. Install chaincode on two peers. You are good to go.

Hyperledger Fabric “Building Your First Network” Tutorial, Hyperledger Fabric “Building Your First Network” Tutorial — Part 3 Join Peer nodes into the channel; Install the Smart Contract (Chaincode) in Peer nodes  Tutorial: Set up Multi Org Hyperledger Fabric Network A course that will help you get your Fabric Application Deployed in a multi-org Fabric Setup Locally | Cloud 3.6 (182 ratings)

You have to use Docker-swarm to implement MultiHost Hyperledger fabric Blockchain Network. Read the steps from the Following URL.

https://github.com/chudsonsolomon/Block-chain-Swarm-Multi-Host

Building Your First Network - Hyperledger Fabric Docs, Docker images and the pre-compiled setup utilities within the supplied tar file. your first network (BYFN) scenario provisions a sample Hyperledger Fabric  Well in my previous post I showed how to setup a Hyperledger Fabric in muliple physical machines, if you don’t see it you can take a look here. It’s kind of important to have the same

Building Your First Network - Hyperledger Fabric docs, The Build your first network (BYFN) tutorial has been deprecated. If you are getting started with Hyperledger Fabric and would like to deploy a basic network, see Using the You will also need to Install Samples, Binaries and Docker Images. Setup the Fabric Node. Step 1: Make a fabric node by installing the prerequisite tools and all software related to Hyperledger Fabric. I am using release 1.4.3 in this demonstration.

Deploying to a multi-organization Hyperledger Fabric, This tutorial provides an insight into the process for configuring a blockchain We are using the Building Your First Network Fabric sample network for this  This is the third part of my hyperledger fabric blog series -Happyledgerblog series :). In this post I’m gonna cover how to deploy hyperledger fabric cluster on multi host environment. In

Deploying a Multi-Node Hyperledger Fabric Network in 5 Steps , Deploying a Multi-Node Hyperledger Fabric Network in 5 Steps In his presentation, Vitaliy set up his environment on Amazon Web Services (AWS). In case updates are needed, the First, get Fabric Starter from GitHub. $ git clone Monolithic Architectures: Pros, Cons + CF Examples. Download now! Optionally, specify a version for fabric, fabric-ca and thirdparty images. If versions are not passed, the latest available versions will be downloaded. The script will also clone fabric-samples repository using the version tag that is aligned with the Fabric version.

Comments
  • Can you please paste a gist or pastebin of your crypto-config.yaml that was used to generate the certificates using cryptogen?
  • @christo4ferris I have added the crypto-config.yaml file here, however I did not make any changes to this file, I am using the original file provided in the example codebase of first-network
  • and you did not change the script.sh either?
  • Yes, I didn't change script.sh either. Also here I have share the configuration for only peer0 of both the orgs, however I am using peer1 too, I wanted to save the space here that's why I only pasted the peer0 config values here.
  • what is this config in the CLI container? - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org4.example.com/tls/ca.crt
  • I have searched around and only found single org examples in swarm mode. I am guessing adding Org2 adds more complexity and this is the only query in stackoverflow on Org2 with Swarm