Hyperledger Fabric 2.x 单机部署多etcdraft共识节点多peer节点网络


前言

本文主要记录搭建一个3orderer节点、4个组织,其中每个组织各2个peer节点的fabric区块链网络,共识算法是使用的etcdraft。


一、相关环境的安装与准备

这里的环境主要包括以下内容:

  • go
  • git
  • docker
  • docker-compose
  • jq
  • fabric、fabric-ca以及fabric-sample相关docker镜像和相关二进制文件

详情可以参考另一篇文章:fabric基础网络环境准备与搭建

注:下面的操作都是基于上面文章里面的软件版本来进行操作,请尽量确保版本一致,否则可能会出现不一样的错误。

二、生成相关的证书材料

1.建立项目目录

[root@dmtsai ~]# mkdir raft-test  
[root@dmtsai ~]# cd raft-test/

2.编写配置文件

在raft-test目录下,新建crypto-config.yaml文件。文件内容如下面所示。

crypto-config.yaml文件内容

# ---------------------------------------------------------------------------
# "OrdererOrgs" - Definition of organizations managing orderer nodes
# ---------------------------------------------------------------------------
OrdererOrgs:
  # ---------------------------------------------------------------------------
  # Orderer
  # ---------------------------------------------------------------------------
  - Name: Orderer
    Domain: example.com
    EnableNodeOUs: true

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

# ---------------------------------------------------------------------------
# "PeerOrgs" - Definition of organizations managing peer nodes
# ---------------------------------------------------------------------------
PeerOrgs:
  # ---------------------------------------------------------------------------
  # Org1
  # ---------------------------------------------------------------------------
  - Name: Org1
    Domain: org1.supervisor.com
    EnableNodeOUs: true

    # ---------------------------------------------------------------------------
    # "CA"
    # ---------------------------------------------------------------------------
    # Uncomment this section to enable the explicit definition of the CA for this
    # organization.  This entry is a Spec.  See "Specs" section below for details.
    # ---------------------------------------------------------------------------
    # CA:
    #    Hostname: ca # implicitly ca.org1.example.com
    #    Country: US
    #    Province: California
    #    Locality: San Francisco
    #    OrganizationalUnit: Hyperledger Fabric
    #    StreetAddress: address for org # default nil
    #    PostalCode: postalCode for org # default nil

    # ---------------------------------------------------------------------------
    # "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.
    #   - SANS:       (Optional) Specifies one or more Subject Alternative Names
    #                 to be set in the resulting x509. Accepts template
    #                 variables {
    
    {.Hostname}}, {
    
    {.Domain}}, {
    
    {.CommonName}}. IP
    #                 addresses provided here will be properly recognized. Other
    #                 values will be taken as DNS names.
    #                 NOTE: Two implicit entries are created for you:
    #                     - {
    
    { .CommonName }}
    #                     - {
    
    { .Hostname }}
    # ---------------------------------------------------------------------------
    # Specs:
    #   - Hostname: foo # implicitly "foo.org1.example.com"
    #     CommonName: foo27.org5.example.com # overrides Hostname-based FQDN set above
    #     SANS:
    #       - "bar.{
    
    {.Domain}}"
    #       - "altfoo.{
    
    {.Domain}}"
    #       - "{
    
    {.Hostname}}.org6.net"
    #       - 172.16.10.31
    #   - 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
      # SANS:
      #   - "{
    
    {.Hostname}}.alt.{
    
    {.Domain}}"

    # ---------------------------------------------------------------------------
    # "Users"
    # ---------------------------------------------------------------------------
    # Count: The number of user accounts _in addition_ to Admin
    # ---------------------------------------------------------------------------
    Users:
      Count: 1

  # ---------------------------------------------------------------------------
  # Org2: See "Org1" for full specification
  # ---------------------------------------------------------------------------
  - Name: Org2
    Domain: org2.build.com
    EnableNodeOUs: true
    Template:
      Count: 2
    Users:
      Count: 1

  - Name: Org3
    Domain: org3.supplier.com
    EnableNodeOUs: true
    Template:
      Count: 2
    Users:
      Count: 1

  - Name: Org4
    Domain: org4.logistics.com
    EnableNodeOUs: true
    Template:
      Count: 2
    Users:
      Count: 1

3.生成证书

根据配置文件crypto-config.yaml来生成证书,请确保已经将生成的fabric二进制命令所在的bin目录加到环境变量,否则无法执行下面的命令。执行完后生成的证书放在了./crypto-config/

[root@dmtsai raft-test]# cryptogen generate --config=crypto-config.yaml
org1.supervisor.com
org2.build.com
org3.supplier.com
org4.logistics.com
[root@dmtsai raft-test]# ll
总用量 12
drwxr-xr-x. 4 root root 4096 55 19:24 crypto-config
-rw-r--r--. 1 root root 5760 55 19:23 crypto-config.yaml

三、生成相关的通道配置文件

1.编辑配置文件

在raft-test目录下,新建configtx.yaml文件。文件内容如下面所示。

configtx.yaml文件内容

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

---
################################################################################
#
#   Section: Organizations
#
#   - This section defines the different organizational identities which will
#   be referenced later in the configuration.
#
################################################################################
Organizations:

    # SampleOrg defines an MSP using the sampleconfig.  It should never be used
    # in production but may be used as a template for other definitions
    - &OrdererOrg
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: OrdererOrg

        # ID to load the MSP definition as
        ID: OrdererMSP

        # MSPDir is the filesystem path which contains the MSP configuration
        MSPDir: crypto-config/ordererOrganizations/example.com/msp

        # Policies defines the set of policies at this level of the config tree
        # For organization policies, their canonical path is usually
        #   /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Writers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Admins:
                Type: Signature
                Rule: "OR('OrdererMSP.admin')"

    - &Org1
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: Org1MSP

        # ID to load the MSP definition as
        ID: Org1MSP

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

        # Policies defines the set of policies at this level of the config tree
        # For organization policies, their canonical path is usually
        #   /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Org1MSP.admin', 'Org1MSP.peer', 'Org1MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Org1MSP.admin', 'Org1MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Org1MSP.admin')"
            Endorsement:
                Type: Signature
                Rule: "OR('Org1MSP.peer')"

        # leave this flag set to true.
        AnchorPeers:
            # AnchorPeers defines the location of peers which can be used
            # for cross org gossip communication.  Note, this value is only
            # encoded in the genesis block in the Application section context
            - Host: peer0.org1.supervisor.com
              Port: 7051

    - &Org2
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: Org2MSP

        # ID to load the MSP definition as
        ID: Org2MSP

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

        # Policies defines the set of policies at this level of the config tree
        # For organization policies, their canonical path is usually
        #   /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Org2MSP.admin', 'Org2MSP.peer', 'Org2MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Org2MSP.admin', 'Org2MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Org2MSP.admin')"
            Endorsement:
                Type: Signature
                Rule: "OR('Org2MSP.peer')"

        AnchorPeers:
            # AnchorPeers defines the location of peers which can be used
            # for cross org gossip communication.  Note, this value is only
            # encoded in the genesis block in the Application section context
            - Host: peer0.org2.build.com
              Port: 9051

    - &Org3
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: Org3MSP

        # ID to load the MSP definition as
        ID: Org3MSP

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

        # Policies defines the set of policies at this level of the config tree
        # For organization policies, their canonical path is usually
        #   /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Org3MSP.admin', 'Org3MSP.peer', 'Org3MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Org3MSP.admin', 'Org3MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Org3MSP.admin')"
            Endorsement:
                Type: Signature
                Rule: "OR('Org3MSP.peer')"

        AnchorPeers:
            # AnchorPeers defines the location of peers which can be used
            # for cross org gossip communication.  Note, this value is only
            # encoded in the genesis block in the Application section context
            - Host: peer0.org3.supplier.com
              Port: 11051

    - &Org4
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: Org4MSP

        # ID to load the MSP definition as
        ID: Org4MSP

        MSPDir: crypto-config/peerOrganizations/org4.logistics.com/msp

        # Policies defines the set of policies at this level of the config tree
        # For organization policies, their canonical path is usually
        #   /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Org4MSP.admin', 'Org4MSP.peer', 'Org4MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Org4MSP.admin', 'Org4MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Org4MSP.admin')"
            Endorsement:
                Type: Signature
                Rule: "OR('Org4MSP.peer')"

        AnchorPeers:
            # AnchorPeers defines the location of peers which can be used
            # for cross org gossip communication.  Note, this value is only
            # encoded in the genesis block in the Application section context
            - Host: peer0.org4.logistics.com
              Port: 13051

################################################################################
#
#   SECTION: Capabilities
#
#   - This section defines the capabilities of fabric network. This is a new
#   concept as of v1.1.0 and should not be utilized in mixed networks with
#   v1.0.x peers and orderers.  Capabilities define features which must be
#   present in a fabric binary for that binary to safely participate in the
#   fabric network.  For instance, if a new MSP type is added, newer binaries
#   might recognize and validate the signatures from this type, while older
#   binaries without this support would be unable to validate those
#   transactions.  This could lead to different versions of the fabric binaries
#   having different world states.  Instead, defining a capability for a channel
#   informs those binaries without this capability that they must cease
#   processing transactions until they have been upgraded.  For v1.0.x if any
#   capabilities are defined (including a map with all capabilities turned off)
#   then the v1.0.x peer will deliberately crash.
#
################################################################################
Capabilities:
    # Channel capabilities apply to both the orderers and the peers and must be
    # supported by both.
    # Set the value of the capability to true to require it.
    Channel: &ChannelCapabilities
        # V2_0 capability ensures that orderers and peers behave according
        # to v2.0 channel capabilities. Orderers and peers from
        # prior releases would behave in an incompatible way, and are therefore
        # not able to participate in channels at v2.0 capability.
        # Prior to enabling V2.0 channel capabilities, ensure that all
        # orderers and peers on a channel are at v2.0.0 or later.
        V2_0: true

    # Orderer capabilities apply only to the orderers, and may be safely
    # used with prior release peers.
    # Set the value of the capability to true to require it.
    Orderer: &OrdererCapabilities
        # V2_0 orderer capability ensures that orderers behave according
        # to v2.0 orderer capabilities. Orderers from
        # prior releases would behave in an incompatible way, and are therefore
        # not able to participate in channels at v2.0 orderer capability.
        # Prior to enabling V2.0 orderer capabilities, ensure that all
        # orderers on channel are at v2.0.0 or later.
        V2_0: true

    # Application capabilities apply only to the peer network, and may be safely
    # used with prior release orderers.
    # Set the value of the capability to true to require it.
    Application: &ApplicationCapabilities
        # V2_0 application capability ensures that peers behave according
        # to v2.0 application capabilities. Peers from
        # prior releases would behave in an incompatible way, and are therefore
        # not able to participate in channels at v2.0 application capability.
        # Prior to enabling V2.0 application capabilities, ensure that all
        # peers on channel are at v2.0.0 or later.
        V2_0: true

################################################################################
#
#   SECTION: Application
#
#   - This section defines the values to encode into a config transaction or
#   genesis block for application related parameters
#
################################################################################
Application: &ApplicationDefaults

    # Organizations is the list of orgs which are defined as participants on
    # the application side of the network
    Organizations:

    # Policies defines the set of policies at this level of the config tree
    # For Application policies, their canonical path is
    #   /Channel/Application/<PolicyName>
    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
        LifecycleEndorsement:
            Type: ImplicitMeta
            Rule: "MAJORITY Endorsement"
        Endorsement:
            Type: ImplicitMeta
            Rule: "MAJORITY Endorsement"

    Capabilities:
        <<: *ApplicationCapabilities
################################################################################
#
#   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
    OrdererType: etcdraft
    
    # Addresses used to be the list of orderer addresses that clients and peers
    # could connect to.  However, this does not allow clients to associate orderer
    # addresses and orderer organizations which can be useful for things such
    # as TLS validation.  The preferred way to specify orderer addresses is now
    # to include the OrdererEndpoints item in your org definition
    Addresses:
        - orderer0.example.com:7050
        - orderer1.example.com:8050
        - orderer2.example.com:9050

    EtcdRaft:
        Consenters:
        - Host: orderer0.example.com
          Port: 7050
          ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
          ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt

    # 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

    # Organizations is the list of orgs which are defined as participants on
    # the orderer side of the network
    Organizations:

    # Policies defines the set of policies at this level of the config tree
    # For Orderer policies, their canonical path is
    #   /Channel/Orderer/<PolicyName>
    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
        # BlockValidation specifies what signatures must be included in the block
        # from the orderer for the peer to validate it.
        BlockValidation:
            Type: ImplicitMeta
            Rule: "ANY Writers"

################################################################################
#
#   CHANNEL
#
#   This section defines the values to encode into a config transaction or
#   genesis block for channel related parameters.
#
################################################################################
Channel: &ChannelDefaults
    # Policies defines the set of policies at this level of the config tree
    # For Channel policies, their canonical path is
    #   /Channel/<PolicyName>
    Policies:
        # Who may invoke the 'Deliver' API
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        # Who may invoke the 'Broadcast' API
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        # By default, who may modify elements at this config level
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"

    # Capabilities describes the channel level capabilities, see the
    # dedicated Capabilities section elsewhere in this file for a full
    # description
    Capabilities:
        <<: *ChannelCapabilities

################################################################################
#
#   Profile
#
#   - Different configuration profiles may be encoded here to be specified
#   as parameters to the configtxgen tool
#
################################################################################
Profiles:

    FourOrgsOrdererGenesis:
        <<: *ChannelDefaults
        Orderer:
            <<: *OrdererDefaults
            OrdererType: etcdraft
            EtcdRaft:
                Consenters:
                - Host: orderer0.example.com
                  Port: 7050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/tls/server.crt
                - Host: orderer1.example.com
                  Port: 8050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer1.example.com/tls/server.crt
                - Host: orderer2.example.com
                  Port: 9050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
            Addresses:
                - orderer0.example.com:7050
                - orderer1.example.com:8050
                - orderer2.example.com:9050
            Organizations:
                - *OrdererOrg
            Capabilities:
                <<: *OrdererCapabilities
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *Org1
                    - *Org2
                    - *Org3
                    - *Org4

    FourOrgsChannel:
        Consortium: SampleConsortium
        <<: *ChannelDefaults
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org1
                - *Org2
                - *Org3
                - *Org4
            Capabilities:
                <<: *ApplicationCapabilities

2.生成创世区块文件

[root@dmtsai raft-test]# configtxgen -profile FourOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block -channelID fabric-channel
2022-05-05 19:41:32.066 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
2022-05-05 19:41:32.110 CST 0002 INFO [common.tools.configtxgen.localconfig] completeInitialization -> orderer type: etcdraft
2022-05-05 19:41:32.110 CST 0003 INFO [common.tools.configtxgen.localconfig] completeInitialization -> Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216 
2022-05-05 19:41:32.110 CST 0004 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: configtx.yaml
2022-05-05 19:41:32.124 CST 0005 INFO [common.tools.configtxgen] doOutputBlock -> Generating genesis block
2022-05-05 19:41:32.124 CST 0006 INFO [common.tools.configtxgen] doOutputBlock -> Creating system channel genesis block
2022-05-05 19:41:32.125 CST 0007 INFO [common.tools.configtxgen] doOutputBlock -> Writing genesis block

3.生成通道文件

[root@dmtsai raft-test]# configtxgen -profile FourOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
2022-05-05 19:42:40.543 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
2022-05-05 19:42:40.589 CST 0002 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: configtx.yaml
2022-05-05 19:42:40.589 CST 0003 INFO [common.tools.configtxgen] doOutputChannelCreateTx -> Generating new channel configtx
2022-05-05 19:42:40.605 CST 0004 INFO [common.tools.configtxgen] doOutputChannelCreateTx -> Writing new channel tx

4.创建一个更新锚节点的配置更新

由于4个组织,所以本例中需要对每个组织分别调用一次

[root@dmtsai raft-test]# configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
2022-05-05 19:43:15.352 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
2022-05-05 19:43:15.389 CST 0002 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: configtx.yaml
2022-05-05 19:43:15.389 CST 0003 INFO [common.tools.configtxgen] doOutputAnchorPeersUpdate -> Generating anchor peer update
2022-05-05 19:43:15.403 CST 0004 INFO [common.tools.configtxgen] doOutputAnchorPeersUpdate -> Writing anchor peer update

[root@dmtsai raft-test]# configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP

[root@dmtsai raft-test]# configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org3MSPanchors.tx -channelID mychannel -asOrg Org3MSP

[root@dmtsai raft-test]# configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org4MSPanchors.tx -channelID mychannel -asOrg Org4MSP

5.查看是否成功

[root@dmtsai raft-test]# cd channel-artifacts/
[root@dmtsai channel-artifacts]# ll
总用量 56
-rw-r-----. 1 root root   499 55 19:42 channel.tx
-rw-r-----. 1 root root 34445 55 19:41 genesis.block
-rw-r-----. 1 root root   315 55 19:43 Org1MSPanchors.tx
-rw-r-----. 1 root root   310 55 19:44 Org2MSPanchors.tx
-rw-r-----. 1 root root   313 55 19:44 Org3MSPanchors.tx
-rw-r-----. 1 root root   314 55 19:45 Org4MSPanchors.tx

四、生成docker-compose.yaml的启动文件

1.编辑配置文件

在raft-test目录下,新建docker-compose.yaml文件。文件内容如下面所示。

docker-compose.yaml文件内容

version: '3.7'

volumes:
  orderer0.example.com:
  orderer1.example.com:
  orderer2.example.com:
  peer0.org1.supervisor.com:
  peer1.org1.supervisor.com:
  peer0.org2.build.com:
  peer1.org2.build.com:
  peer0.org3.supplier.com:
  peer1.org3.supplier.com:
  peer0.org4.logistics.com:
  peer1.org4.logistics.com:

networks:
  test:
    name: ordersFabric_test

services:

  orderer0.example.com:
    container_name: orderer0.example.com
    image: hyperledger/fabric-orderer:latest
    labels:
      service: hyperledger-fabric
    environment:
      - FABRIC_LOGGING_SPEC=INFO
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_LISTENPORT=7050
      - 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_TOPIC_REPLICATIONFACTOR=1
      - ORDERER_KAFKA_VERBOSE=true
      - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
      - ORDERER_CHANNELPARTICIPATION_ENABLED=true
      - ORDERER_ADMIN_TLS_ENABLED=true
      - ORDERER_ADMIN_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_ADMIN_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_ADMIN_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_ADMIN_TLS_CLIENTROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_ADMIN_LISTENADDRESS=0.0.0.0:7053
    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
      - 7053:7053
    networks:
      - test

  orderer1.example.com:
    container_name: orderer1.example.com
    image: hyperledger/fabric-orderer:latest
    labels:
      service: hyperledger-fabric
    environment:
      - FABRIC_LOGGING_SPEC=INFO
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_LISTENPORT=8050
      - 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_TOPIC_REPLICATIONFACTOR=1
      - ORDERER_KAFKA_VERBOSE=true
      - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
      - ORDERER_CHANNELPARTICIPATION_ENABLED=true
      - ORDERER_ADMIN_TLS_ENABLED=true
      - ORDERER_ADMIN_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_ADMIN_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_ADMIN_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_ADMIN_TLS_CLIENTROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_ADMIN_LISTENADDRESS=0.0.0.0:7053
    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/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
      - 7054:7053
    networks:
      - test

  orderer2.example.com:
    container_name: orderer2.example.com
    image: hyperledger/fabric-orderer:latest
    labels:
      service: hyperledger-fabric
    environment:
      - FABRIC_LOGGING_SPEC=INFO
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_LISTENPORT=9050
      - 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_TOPIC_REPLICATIONFACTOR=1
      - ORDERER_KAFKA_VERBOSE=true
      - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
      - ORDERER_CHANNELPARTICIPATION_ENABLED=true
      - ORDERER_ADMIN_TLS_ENABLED=true
      - ORDERER_ADMIN_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_ADMIN_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_ADMIN_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_ADMIN_TLS_CLIENTROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_ADMIN_LISTENADDRESS=0.0.0.0:7053
    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/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
      - 7055:7053
    networks:
      - test

  peer0.org1.supervisor.com:
    container_name: peer0.org1.supervisor.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      #Generic peer variables
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=ordersFabric_test
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - 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
      # Peer specific variabes
      - CORE_PEER_ID=peer0.org1.supervisor.com
      - CORE_PEER_ADDRESS=peer0.org1.supervisor.com:7051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:7051
      - CORE_PEER_CHAINCODEADDRESS=peer0.org1.supervisor.com:7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.supervisor.com:8051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.supervisor.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:
      - /var/run/docker.sock:/host/var/run/docker.sock
      - ./crypto-config/peerOrganizations/org1.supervisor.com/peers/peer0.org1.supervisor.com/msp:/etc/hyperledger/fabric/msp
      - ./crypto-config/peerOrganizations/org1.supervisor.com/peers/peer0.org1.supervisor.com/tls:/etc/hyperledger/fabric/tls
      - /var/run/:/host/var/run/
      - ./:/etc/hyperledger/channel/
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 7051:7051
    networks:
      - test

  peer1.org1.supervisor.com:
    container_name: peer1.org1.supervisor.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      #Generic peer variables
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=ordersFabric_test
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - 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
      # Peer specific variabes
      - CORE_PEER_ID=peer1.org1.supervisor.com
      - CORE_PEER_ADDRESS=peer1.org1.supervisor.com:8051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:8051
      - CORE_PEER_CHAINCODEADDRESS=peer1.org1.supervisor.com:8052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.supervisor.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.supervisor.com:8051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:
      - /var/run/docker.sock:/host/var/run/docker.sock
      - ./crypto-config/peerOrganizations/org1.supervisor.com/peers/peer1.org1.supervisor.com/msp:/etc/hyperledger/fabric/msp
      - ./crypto-config/peerOrganizations/org1.supervisor.com/peers/peer1.org1.supervisor.com/tls:/etc/hyperledger/fabric/tls
      - /var/run/:/host/var/run/
      - ./:/etc/hyperledger/channel/
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 8051:8051
    networks:
      - test

  peer0.org2.build.com:
    container_name: peer0.org2.build.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      #Generic peer variables
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=ordersFabric_test
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - 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
      # Peer specific variabes
      - CORE_PEER_ID=peer0.org2.build.com
      - CORE_PEER_ADDRESS=peer0.org2.build.com:9051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:9051
      - CORE_PEER_CHAINCODEADDRESS=peer0.org2.build.com:9052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:9052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.build.com:10051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.build.com:9051
      - CORE_PEER_LOCALMSPID=Org2MSP
    volumes:
      - /var/run/docker.sock:/host/var/run/docker.sock
      - ./crypto-config/peerOrganizations/org2.build.com/peers/peer0.org2.build.com/msp:/etc/hyperledger/fabric/msp
      - ./crypto-config/peerOrganizations/org2.build.com/peers/peer0.org2.build.com/tls:/etc/hyperledger/fabric/tls
      - /var/run/:/host/var/run/
      - ./:/etc/hyperledger/channel/
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 9051:9051
    networks:
      - test

  peer1.org2.build.com:
    container_name: peer1.org2.build.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      #Generic peer variables
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=ordersFabric_test
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - 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
      # Peer specific variabes
      - CORE_PEER_ID=peer1.org2.build.com
      - CORE_PEER_ADDRESS=peer1.org2.build.com:10051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:10051
      - CORE_PEER_CHAINCODEADDRESS=peer1.org2.build.com:10052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:10052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.build.com:9051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.build.com:10051
      - CORE_PEER_LOCALMSPID=Org2MSP
    volumes:
      - /var/run/docker.sock:/host/var/run/docker.sock
      - ./crypto-config/peerOrganizations/org2.build.com/peers/peer1.org2.build.com/msp:/etc/hyperledger/fabric/msp
      - ./crypto-config/peerOrganizations/org2.build.com/peers/peer1.org2.build.com/tls:/etc/hyperledger/fabric/tls
      - /var/run/:/host/var/run/
      - ./:/etc/hyperledger/channel/
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 10051:10051
    networks:
      - test

  peer0.org3.supplier.com:
    container_name: peer0.org3.supplier.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      #Generic peer variables
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=ordersFabric_test
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - 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
      # Peer specific variabes
      - CORE_PEER_ID=peer0.org3.supplier.com
      - CORE_PEER_ADDRESS=peer0.org3.supplier.com:11051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:11051
      - CORE_PEER_CHAINCODEADDRESS=peer0.org3.supplier.com:11052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:11052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org3.supplier.com:12051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org3.supplier.com:11051
      - CORE_PEER_LOCALMSPID=Org3MSP
    volumes:
      - /var/run/docker.sock:/host/var/run/docker.sock
      - ./crypto-config/peerOrganizations/org3.supplier.com/peers/peer0.org3.supplier.com/msp:/etc/hyperledger/fabric/msp
      - ./crypto-config/peerOrganizations/org3.supplier.com/peers/peer0.org3.supplier.com/tls:/etc/hyperledger/fabric/tls
      - /var/run/:/host/var/run/
      - ./:/etc/hyperledger/channel/
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 11051:11051
    networks:
      - test

  peer1.org3.supplier.com:
    container_name: peer1.org3.supplier.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      #Generic peer variables
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=ordersFabric_test
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - 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
      # Peer specific variabes
      - CORE_PEER_ID=peer1.org3.supplier.com
      - CORE_PEER_ADDRESS=peer1.org3.supplier.com:12051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:12051
      - CORE_PEER_CHAINCODEADDRESS=peer1.org3.supplier.com:12052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:12052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org3.supplier.com:11051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org3.supplier.com:12051
      - CORE_PEER_LOCALMSPID=Org3MSP
    volumes:
      - /var/run/docker.sock:/host/var/run/docker.sock
      - ./crypto-config/peerOrganizations/org3.supplier.com/peers/peer1.org3.supplier.com/msp:/etc/hyperledger/fabric/msp
      - ./crypto-config/peerOrganizations/org3.supplier.com/peers/peer1.org3.supplier.com/tls:/etc/hyperledger/fabric/tls
      - /var/run/:/host/var/run/
      - ./:/etc/hyperledger/channel/
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 12051:12051
    networks:
      - test

  peer0.org4.logistics.com:
    container_name: peer0.org4.logistics.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      #Generic peer variables
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=ordersFabric_test
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - 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
      # Peer specific variabes
      - CORE_PEER_ID=peer0.org4.logistics.com
      - CORE_PEER_ADDRESS=peer0.org4.logistics.com:13051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:13051
      - CORE_PEER_CHAINCODEADDRESS=peer0.org4.logistics.com:13052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:13052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org4.logistics.com:14051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org4.logistics.com:13051
      - CORE_PEER_LOCALMSPID=Org4MSP
    volumes:
      - /var/run/docker.sock:/host/var/run/docker.sock
      - ./crypto-config/peerOrganizations/org4.logistics.com/peers/peer0.org4.logistics.com/msp:/etc/hyperledger/fabric/msp
      - ./crypto-config/peerOrganizations/org4.logistics.com/peers/peer0.org4.logistics.com/tls:/etc/hyperledger/fabric/tls
      - /var/run/:/host/var/run/
      - ./:/etc/hyperledger/channel/
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 13051:13051
    networks:
      - test

  peer1.org4.logistics.com:
    container_name: peer1.org4.logistics.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      #Generic peer variables
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=ordersFabric_test
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - 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
      # Peer specific variabes
      - CORE_PEER_ID=peer1.org4.logistics.com
      - CORE_PEER_ADDRESS=peer1.org4.logistics.com:14051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:14051
      - CORE_PEER_CHAINCODEADDRESS=peer1.org4.logistics.com:14052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:14052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org4.logistics.com:13051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org4.logistics.com:14051
      - CORE_PEER_LOCALMSPID=Org4MSP
    volumes:
      - /var/run/docker.sock:/host/var/run/docker.sock
      - ./crypto-config/peerOrganizations/org4.logistics.com/peers/peer1.org4.logistics.com/msp:/etc/hyperledger/fabric/msp
      - ./crypto-config/peerOrganizations/org4.logistics.com/peers/peer1.org4.logistics.com/tls:/etc/hyperledger/fabric/tls
      - /var/run/:/host/var/run/
      - ./:/etc/hyperledger/channel/
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 14051:14051
    networks:
      - test

  cli1:
    container_name: cli1
    image: hyperledger/fabric-tools:latest
    tty: true
    stdin_open: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - FABRIC_LOGGING_SPEC=INFO
      - CORE_PEER_ID=cli1
      - CORE_PEER_ADDRESS=peer0.org1.supervisor.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/org1.supervisor.com/peers/peer0.org1.supervisor.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.supervisor.com/peers/peer0.org1.supervisor.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.supervisor.com/peers/peer0.org1.supervisor.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.supervisor.com/users/[email protected]/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
      - /var/run/:/host/var/run/
      - ./chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go
      - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
      - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    networks:
      - test

  cli2:
    container_name: cli2
    image: hyperledger/fabric-tools:latest
    tty: true
    stdin_open: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - FABRIC_LOGGING_SPEC=INFO
      - CORE_PEER_ID=cli2
      - CORE_PEER_ADDRESS=peer0.org2.build.com:9051
      - CORE_PEER_LOCALMSPID=Org2MSP
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.build.com/peers/peer0.org2.build.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.build.com/peers/peer0.org2.build.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.build.com/peers/peer0.org2.build.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.build.com/users/[email protected]/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
      - /var/run/:/host/var/run/
      - ./chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go
      - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
      - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    networks:
      - test

  cli3:
    container_name: cli3
    image: hyperledger/fabric-tools:latest
    tty: true
    stdin_open: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - FABRIC_LOGGING_SPEC=INFO
      - CORE_PEER_ID=cli3
      - CORE_PEER_ADDRESS=peer0.org3.supplier.com:11051
      - CORE_PEER_LOCALMSPID=Org3MSP
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.supplier.com/peers/peer0.org3.supplier.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.supplier.com/peers/peer0.org3.supplier.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.supplier.com/peers/peer0.org3.supplier.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.supplier.com/users/[email protected]/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
      - /var/run/:/host/var/run/
      - ./chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go
      - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
      - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    networks:
      - test

  cli4:
    container_name: cli4
    image: hyperledger/fabric-tools:latest
    tty: true
    stdin_open: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - FABRIC_LOGGING_SPEC=INFO
      - CORE_PEER_ID=cli4
      - CORE_PEER_ADDRESS=peer0.org4.logistics.com:13051
      - CORE_PEER_LOCALMSPID=Org4MSP
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org4.logistics.com/peers/peer0.org4.logistics.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org4.logistics.com/peers/peer0.org4.logistics.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org4.logistics.com/peers/peer0.org4.logistics.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org4.logistics.com/users/[email protected]/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
      - /var/run/:/host/var/run/
      - ./chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go
      - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
      - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    networks:
      - test

2.利用docker-compose命令生成镜像

利用docker-compose命令来生成镜像:

[root@dmtsai raft-test]# docker-compose up -d
[root@dmtsai raft-test]# docker ps -a

如果在后面需要删除镜像可以使用以下命令:

[root@dmtsai raft-test]# docker rm $(docker ps -a -q)
[root@dmtsai raft-test]# docker-compose up -d

五、通道相关配置操作

1.创建通道,生成配置文件

  • 进入cli1容器
[root@dmtsai raft-test]# docker exec -it cli1 bash
bash-5.1# peer channel create -o orderer0.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/msp/tlscacerts/tlsca.example.com-cert.pem
2022-05-05 12:27:25.703 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-05-05 12:27:25.801 UTC 0002 INFO [cli.common] readBlock -> Expect block, but got status: &{
    
    NOT_FOUND}
2022-05-05 12:27:25.890 UTC 0003 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-05-05 12:27:26.093 UTC 0004 INFO [cli.common] readBlock -> Expect block, but got status: &{
    
    SERVICE_UNAVAILABLE}
2022-05-05 12:27:26.108 UTC 0005 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-05-05 12:27:26.310 UTC 0006 INFO [cli.common] readBlock -> Expect block, but got status: &{
    
    SERVICE_UNAVAILABLE}
2022-05-05 12:27:26.337 UTC 0007 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-05-05 12:27:26.540 UTC 0008 INFO [cli.common] readBlock -> Expect block, but got status: &{
    
    SERVICE_UNAVAILABLE}
2022-05-05 12:27:26.550 UTC 0009 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-05-05 12:27:26.753 UTC 000a INFO [cli.common] readBlock -> Expect block, but got status: &{
    
    SERVICE_UNAVAILABLE}
2022-05-05 12:27:26.761 UTC 000b INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-05-05 12:27:26.969 UTC 000c INFO [cli.common] readBlock -> Received block: 0
bash-5.1# ls
  • 将通道文件复制到项目路径下,复制到容器内,方便加入通道
[root@dmtsai raft-test]# docker cp cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/mychannel.block ./
[root@dmtsai raft-test]# docker cp mychannel.block cli2:/opt/gopath/src/github.com/hyperledger/fabric/peer
[root@dmtsai raft-test]# docker cp mychannel.block cli3:/opt/gopath/src/github.com/hyperledger/fabric/peer
[root@dmtsai raft-test]# docker cp mychannel.block cli4:/opt/gopath/src/github.com/hyperledger/fabric/peer

2.加入通道与更新锚点

  • cli1容器操作
[root@dmtsai raft-test]# docker exec -it cli1 bash
bash-5.1# peer channel join -b mychannel.block
2022-05-05 12:46:48.684 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-05-05 12:46:49.026 UTC 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channel
bash-5.1# peer channel update -o orderer0.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
2022-05-05 12:48:15.636 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-05-05 12:48:15.691 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel update
bash-5.1# exit
exit
  • cli2容器操作
[root@dmtsai raft-test]# docker exec -it cli2 bash
bash-5.1# peer channel join -b mychannel.block
2022-05-05 12:49:41.337 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-05-05 12:49:41.433 UTC 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channel
bash-5.1# peer channel update -o orderer0.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
2022-05-05 12:49:49.914 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-05-05 12:49:49.979 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel update
bash-5.1# exit
exit
  • cli3容器操作
[root@dmtsai raft-test]# docker exec -it cli3 bash
bash-5.1# peer channel join -b mychannel.block
2022-05-05 12:52:10.421 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-05-05 12:52:10.577 UTC 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channel
bash-5.1# peer channel update -o orderer0.example.com:7050 -c mychannel -f ./channel-artifacts/Org3MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
2022-05-05 12:52:17.947 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-05-05 12:52:17.994 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel update
bash-5.1# exit
exit
  • cli4容器操作
[root@dmtsai raft-test]# docker exec -it cli4 bash
bash-5.1# peer channel join -b mychannel.block
2022-05-05 12:53:18.612 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-05-05 12:53:18.711 UTC 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channel
bash-5.1# peer channel update -o orderer0.example.com:7050 -c mychannel -f ./channel-artifacts/Org4MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
2022-05-05 12:53:30.511 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-05-05 12:53:30.573 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel update
bash-5.1# exit
exit

六、链码调用

1.复制官方链码

注意:这里的sacc.go文件目录取决于自己本地中的文件

[root@dmtsai raft-test]# cp /var/goproject/src/github.com/kdhelloa/fabric/scripts/fabric-samples/chaincode/sacc/sacc.go ./chaincode/go/

2.安装go依赖并打包链码

[root@dmtsai raft-test]# docker exec -it cli1 bash
bash-5.1# cd /opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go/
bash-5.1# ls
sacc.go
bash-5.1# go env -w GOPROXY=https://goproxy.cn,direct
bash-5.1# go env -w GO111MODULE=auto
bash-5.1#  go mod init
go: creating new go.mod: module github.com/hyperledger/fabric-cluster/chaincode/go
go: to add module requirements and sums:
	go mod tidy
bash-5.1# go mod vendor
go: finding module for package github.com/hyperledger/fabric-protos-go/peer
go: finding module for package github.com/hyperledger/fabric-chaincode-go/shim
go: downloading github.com/hyperledger/fabric-chaincode-go v0.0.0-20220131132609-1476cf1d3206
go: downloading github.com/hyperledger/fabric-protos-go v0.0.0-20220315113721-7dc293e117f7
go: found github.com/hyperledger/fabric-chaincode-go/shim in github.com/hyperledger/fabric-chaincode-go v0.0.0-20220131132609-1476cf1d3206
go: found github.com/hyperledger/fabric-protos-go/peer in github.com/hyperledger/fabric-protos-go v0.0.0-20220315113721-7dc293e117f7
go: downloading github.com/golang/protobuf v1.3.2
go: downloading google.golang.org/grpc v1.23.0
go: downloading google.golang.org/genproto v0.0.0-20180831171423-11092d34479b
go: downloading golang.org/x/net v0.0.0-20190522155817-f3200d17e092
go: downloading golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542
go: downloading golang.org/x/text v0.3.0
bash-5.1# ls
go.mod   go.sum   sacc.go  vendor
bash-5.1# peer lifecycle chaincode package sacc.tar.gz \
  --path github.com/hyperledger/fabric-cluster/chaincode/go/ \
  --label sacc_1
bash-5.1# ls
go.mod       go.sum       sacc.go      sacc.tar.gz  vendor
bash-5.1# echo $PWD
/opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go
bash-5.1# exit
exit

3.将打包好的链码复制到四个cli

[root@dmtsai raft-test]# docker exec -it cli1 bash
bash-5.1# cd /opt/gopath/src/github.com/hyperledger/fabric/peer/
bash-5.1# ls
channel-artifacts  crypto             mychannel.block
bash-5.1# cp /opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go/sacc.tar.gz /opt/gopath/src/github.com/hyperledger/fabric/peer/
bash-5.1# exit
exit
[root@dmtsai raft-test]# docker cp cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/sacc.tar.gz ./
[root@dmtsai raft-test]# ls
chaincode  channel-artifacts  configtx.yaml  crypto-config  crypto-config.yaml  docker-compose.yaml  mychannel.block  sacc.tar.gz
[root@dmtsai raft-test]# docker cp sacc.tar.gz cli2:/opt/gopath/src/github.com/hyperledger/fabric/peer/
[root@dmtsai raft-test]# docker cp sacc.tar.gz cli3:/opt/gopath/src/github.com/hyperledger/fabric/peer/
[root@dmtsai raft-test]# docker cp sacc.tar.gz cli4:/opt/gopath/src/github.com/hyperledger/fabric/peer/

4.安装链码、批准链码、查看链码

在批准链码时,–package-id 的值需要与安装生成的package identifier:值一致

  • cli容器操作
[root@dmtsai raft-test]# docker exec -it cli1 bash
bash-5.1# peer lifecycle chaincode install sacc.tar.gz
2022-05-05 13:20:15.541 UTC 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response:<status:200 payload:"\nGsacc_1:44213cad421c117cc7ba9311e9cb8bb9f4dc6d9c6307e8d4cc5c48b49d79c55d\022\006sacc_1" > 
2022-05-05 13:20:15.544 UTC 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: sacc_1:44213cad421c117cc7ba9311e9cb8bb9f4dc6d9c6307e8d4cc5c48b49d79c55d
bash-5.1# peer lifecycle chaincode approveformyorg --channelID mychannel --name sacc --version 1.0 --init-required --package-id sacc_1:44213cad421c117cc7ba9311e9cb8bb9f4dc6d9c6307e8d4cc5c48b49d79c55d --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
2022-05-05 13:22:11.182 UTC 0001 INFO [cli.lifecycle.chaincode] setOrdererClient -> Retrieved channel (mychannel) orderer endpoint: orderer0.example.com:7050
2022-05-05 13:22:13.425 UTC 0002 INFO [chaincodeCmd] ClientWait -> txid [fcee8d805933e7c12aa8ad55ae5c28f7fd999404f2f178cd13f8225c40296361] committed with status (VALID) at peer0.org1.supervisor.com:7051
bash-5.1# peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name sacc --version 1.0 --init-required --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --output json
{
    
    
	"approvals": {
    
    
		"Org1MSP": true,
		"Org2MSP": false,
		"Org3MSP": false,
		"Org4MSP": false
	}
}
bash-5.1# exit
exit
  • 在cli2、cli3、cli4容器中的操作与上面类似,所以自行依次来进行执行

5.提交链码

  • cli1容器下来进行提交
[root@dmtsai raft-test]# docker exec -it cli1 bash
bash-5.1# peer lifecycle chaincode commit -o orderer0.example.com:7050 --channelID mychannel --name sacc --version 1.0 --sequence 1 --init-required --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses peer0.org1.supervisor.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.supervisor.com/peers/peer0.org1.supervisor.com/tls/ca.crt --peerAddresses peer0.org2.build.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.build.com/peers/peer0.org2.build.com/tls/ca.crt --peerAddresses peer0.org3.supplier.com:11051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.supplier.com/peers/peer0.org3.supplier.com/tls/ca.crt --peerAddresses peer0.org4.logistics.com:13051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org4.logistics.com/peers/peer0.org4.logistics.com/tls/ca.crt
2022-05-05 13:31:31.916 UTC 0001 INFO [chaincodeCmd] ClientWait -> txid [a3bf6a75a25b9616236fad5659b6533dc583b01ed56189dc56b80cccbe64e9d0] committed with status (VALID) at peer0.org3.supplier.com:11051
2022-05-05 13:31:32.488 UTC 0002 INFO [chaincodeCmd] ClientWait -> txid [a3bf6a75a25b9616236fad5659b6533dc583b01ed56189dc56b80cccbe64e9d0] committed with status (VALID) at peer0.org4.logistics.com:13051
2022-05-05 13:31:32.805 UTC 0003 INFO [chaincodeCmd] ClientWait -> txid [a3bf6a75a25b9616236fad5659b6533dc583b01ed56189dc56b80cccbe64e9d0] committed with status (VALID) at peer0.org1.supervisor.com:7051
2022-05-05 13:31:33.032 UTC 0004 INFO [chaincodeCmd] ClientWait -> txid [a3bf6a75a25b9616236fad5659b6533dc583b01ed56189dc56b80cccbe64e9d0] committed with status (VALID) at peer0.org2.build.com:9051

6.链码初始化

接着上面的命令进行执行

bash-5.1# peer chaincode invoke -o orderer0.example.com:7050 --isInit --ordererTLSHostnameOverride orderer0.example.com --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n sacc --peerAddresses peer0.org1.supervisor.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.supervisor.com/peers/peer0.org1.supervisor.com/tls/ca.crt --peerAddresses peer0.org2.build.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.build.com/peers/peer0.org2.build.com/tls/ca.crt --peerAddresses peer0.org3.supplier.com:11051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.supplier.com/peers/peer0.org3.supplier.com/tls/ca.crt --peerAddresses peer0.org4.logistics.com:13051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org4.logistics.com/peers/peer0.org4.logistics.com/tls/ca.crt -c '{"Args":["a","bb"]}' 
2022-05-05 13:32:49.211 UTC 0001 INFO [chaincodeCmd] chaincodeInvokeOrQuery -> Chaincode invoke successful. result: status:200

7.查询数据

bash-5.1# peer chaincode query -C mychannel -n sacc -c '{"Args":["query","a"]}'
bb

8.调用链码

bash-5.1# peer chaincode invoke -o orderer0.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n sacc --peerAddresses peer0.org1.supervisor.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.supervisor.com/peers/peer0.org1.supervisor.com/tls/ca.crt --peerAddresses peer0.org2.build.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.build.com/peers/peer0.org2.build.com/tls/ca.crt --peerAddresses peer0.org3.supplier.com:11051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.supplier.com/peers/peer0.org3.supplier.com/tls/ca.crt --peerAddresses peer0.org4.logistics.com:13051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org4.logistics.com/peers/peer0.org4.logistics.com/tls/ca.crt -c '{"Args":["set","a","cc"]}'
2022-05-05 13:33:08.061 UTC 0001 INFO [chaincodeCmd] chaincodeInvokeOrQuery -> Chaincode invoke successful. result: status:200 payload:"cc"

9.再次查询链码

bash-5.1# peer chaincode query -C mychannel -n sacc -c '{"Args":["query","a"]}'
cc

10.关闭删除镜像

到这里一个完整的网络就搭建并测试成功了,所以就可以关闭并删除镜像了

[root@dmtsai raft-test]# docker stop $(docker ps -a -q)
[root@dmtsai raft-test]# docker rm $(docker ps -a -q)

总结

以上就是全部的安装测试过程,希望大家安装测试成功。
参考资料:

猜你喜欢

转载自blog.csdn.net/khahad/article/details/124595129