hyperledger fabric 网络操作基本操作和概念

这篇具有很好参考价值的文章主要介绍了hyperledger fabric 网络操作基本操作和概念。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

hyperledger fabric 网络操作基本操作和概念

在搭建好hyperledger fabric环境后,继续进行网络搭建操作
新建文件夹twonodes(与github.com同级)

1. cryptogen 操作

1.1 cryptogen 生成证书文件

1.1.1 生成证书文件模板

# 打印模板到终端
cryptogen showtemplate
# 打印模板到配置文件crypto-config.yaml
cryptogen showtemplate > crypto-config.yaml

生成模板配置文件说明

1.1.1.1 排序节点OrdererOrgs配置
OrdererOrgs:
  - Name: Orderer # 排序节点名称
    Domain: example.com # 排序节点域名
    EnableNodeOUs: false # 是否使用OU配置(OU表示组织单元即每个组织下面很多节点,可以将一些节点作为一个部门)
    # "Specs" - See PeerOrgs below for complete description
    Specs:
      - Hostname: orderer
1.1.1.2 普通节点PeerOrgs配置
PeerOrgs:
  # Org1 组织1
  - Name: Org1 #组织1名称
    Domain: org1.example.com #组织1域名
    EnableNodeOUs: true
1.1.1.3 Template 配置
Template:
      Count: 1 # 组织节点个数,节点名称顺序排列
      # Start: 5
      # Hostname: {{.Prefix}}{{.Index}} # default
      # SANS:
      #   - "{{.Hostname}}.alt.{{.Domain}}"

    #
1.1.1.4 Users用户配置

(user和peer区别,user可以理解为终端,指人,而peer是节点,只是一台运行的机器或集群的一个节点)

    # "Users"
    # Count: The number of user accounts _in addition_ to Admin
    Users:
      Count: 1
1.1.1.5 crypto-config.yaml

Order组织节点定义

OrdererOrgs:
  # ---------------------------------------------------------------------------
  # Orderer
  # ---------------------------------------------------------------------------
  - Name: Orderer
    Domain: trace.com
    Specs:
      - Hostname: orderer

PeerOrgs:
  # ---------------------------------------------------------------------------
  # Org1
  # ---------------------------------------------------------------------------
  - Name: Org1
    Domain: org1.trace.com
    Template:
      Count: 1
    Users:
      Count: 1
 # ---------------------------------------------------------------------------
  # Org2
  # ---------------------------------------------------------------------------
  - Name: Org2
    Domain: org2.trace.com
    Template:
      Count: 1
    Users:
      Count: 1
 # ---------------------------------------------------------------------------
  # Org3
  # ---------------------------------------------------------------------------
  - Name: Org3
    Domain: org3.trace.com
    Template:
      Count: 1
    Users:
      Count: 1
 # ---------------------------------------------------------------------------
  # Org4
  # ---------------------------------------------------------------------------
  - Name: Org4
    Domain: org4.trace.com
    Template:
      Count: 1
    Users:
      Count: 1

# ---------------------------------------------------------------------------
  # Org5
  # ---------------------------------------------------------------------------
  - Name: Org5
    Domain: org5.trace.com
    Template:
      Count: 1
    Users:
      Count: 1

1.1.2 生成密钥材料

cryptogen generate --config=crypto-config.yaml

hyperledger fabric网络操作基本操作和概念,深入探索hyperledger fabric联盟链搭建,fabric,网络,区块链

1.2 cryptogen.yaml 创建通道配置

拷贝/hyperledger/fabric-samples/test-network/configtx/configx.yaml 到目录下
修改msp配置文件(成员服务提供者 (MSP)及相关证书配置
因为Fabric是一个认证性的网络, 所以区块链参与者需要一种向网络中的其他参与者证实自己身份的机制从而在网络中进行交易
证书机构通过生成可以用来证实身份的由公钥和私钥形成的键值对来发放认证信息。因为一个私钥永远不会被公开,所以引入了一种可以证实身份的机制即MSP。例如,一个peer节点用它的私钥进行数字签名或背书交易。接着排序节点包含的该peer节点的公钥会被用来验证交易携带的签名是否合法。私钥被用作生成交易信息上的,只有与私钥相对应的且作为MSP一部分的公钥可以匹配的签名。因此,MSP是一个可让身份被信任和被网络中其他参与者公认的,而不需要暴露成员的私钥的机制。

MSPDir: ../organizations/ordererOrganizations/example.com/msp
# 改为
MSPDir: crypto-config/ordererOrganizations/example.com/msp

1.2.1 configx.yaml

#
# 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/trace.com/msp

    - &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.trace.com/msp

        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.trace.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.trace.com/msp

        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.trace.com
              Port: 7051

    - &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.trace.com/msp

        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.trace.com
              Port: 7051


    - &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.trace.com/msp

        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.trace.com
              Port: 7051

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

        # ID to load the MSP definition as
        ID: Org5MSP

        MSPDir: crypto-config/peerOrganizations/org5.trace.com/msp

        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.org5.trace.com
              Port: 7051

################################################################################
#
#   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.
    Global: &ChannelCapabilities
        # V1.1 for Global is a catchall flag for behavior which has been
        # determined to be desired for all orderers and peers running v1.0.x,
        # but the modification of which would cause incompatibilities.  Users
        # should leave this flag set to true.
        V1_1: true

    # Orderer capabilities apply only to the orderers, and may be safely
    # manipulated without concern for upgrading peers.  Set the value of the
    # capability to true to require it.
    Orderer: &OrdererCapabilities
        # V1.1 for Order is a catchall flag for behavior which has been
        # determined to be desired for all orderers running v1.0.x, but the
        # modification of which  would cause incompatibilities.  Users should
        # leave this flag set to true.
        V1_1: true

    # Application capabilities apply only to the peer network, and may be safely
    # manipulated without concern for upgrading orderers.  Set the value of the
    # capability to true to require it.
    Application: &ApplicationCapabilities
        # V1.2 for Application is a catchall flag for behavior which has been
        # determined to be desired for all peers running v1.0.x, but the
        # modification of which would cause incompatibilities.  Users should
        # leave this flag set to true.
        V1_2: 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:

################################################################################
#
#   SECTION: Orderer
#
#   - This section defines the values to encode into a config transaction or
#   genesis block for orderer related parameters
#
################################################################################
Orderer: &OrdererDefaults

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

    Addresses:
        - orderer.trace.com:7050
    # Batch Timeout: The amount of time to wait before creating a batch
    BatchTimeout: 2s

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

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

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

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

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

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

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

    FiveOrgsOrdererGenesis:
        Capabilities:
            <<: *ChannelCapabilities
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
            Capabilities:
                <<: *OrdererCapabilities
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *Org1
                    - *Org2
                    - *Org3
                    - *Org4
                    - *Org5
    FiveOrgsChannel:
        Consortium: SampleConsortium
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org1
                - *Org2
                - *Org3
                - *Org4
                - *Org5
            Capabilities:
                <<: *ApplicationCapabilities
  

1.3 网络初始化

configtxgen -profile SampleMultiNodeEtcdRaft -channelID systemchannel -outputBlock ./channel-artifacts/genesis.block
# 生成系统文件的创世块
configtxgen -profile Thr eeOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID testchannel
# 生成用于创建应用通道的通道文件
configtxgen -profile ThreeOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID appchannel -asOrg Org1MSP
# 生成Org1进行锚节点更新的文件
configtxgen -profile ThreeOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID appchannel -asOrg Org2MSP
# 生成Org2进行锚节点更新的文件
configtxgen -profile ThreeOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org3MSPanchors.tx -channelID appchannel -asOrg Org3MSP
# 生成Org3进行锚节点更新的文件

2. docker compose

区块链docker节点集群搭建(基于docker compose)

2.1 docker-compose.yaml

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

volumes:
  orderer.trace.com:
  peer0.org1.trace.com:
  peer0.org2.trace.com:
  peer0.org3.trace.com:
  peer0.org4.trace.com:
  peer0.org5.trace.com:

networks:
  basic:

services:
  ca.trace.com:
    image: hyperledger/fabric-ca
    environment:
      - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
      - FABRIC_CA_SERVER_CA_NAME=ca.trace.com
      - FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org1.trace.com-cert.pem
      - FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/38495dada2d3a879981547003d601ed405cde661e55e568cce718a6618360d79_sk
      
    ports:
      - 7054:7054
    command: sh -c 'fabric-ca-server start -b admin:adminpw -d'
    volumes:
      - ./crypto-config/peerOrganizations/org1.trace.com/ca/:/etc/hyperledger/fabric-ca-server-config
    container_name: ca.trace.com
    networks:
      - basic

  orderer.trace.com:
    container_name: orderer.trace.com
    image: hyperledger/fabric-orderer
    environment:
      - ORDERER_GENERAL_LOGLEVEL=INFO
      - 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/trace.com/orderers/orderer.trace.com/msp:/var/hyperledger/orderer/msp
    - ./crypto-config/ordererOrganizations/trace.com/orderers/orderer.trace.com/tls/:/var/hyperledger/orderer/tls
    - orderer.trace.com:/var/hyperledger/production/orderer
    ports:
      - 7050:7050
    networks:
      - basic


  peer0.org1.trace.com:
    container_name: peer0.org1.trace.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_PEER_ID=peer0.org1.trace.com
      - CORE_LOGGING_PEER=info
      - CORE_CHAINCODE_LOGGING_LEVEL=info
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
      - CORE_PEER_ADDRESS=peer0.org1.trace.com:7051
      # # 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=basic-network_basic
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
      # The CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME and CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD
      # provide the credentials for ledger to connect to CouchDB.  The username and password must
      # match the username and password set for the associated CouchDB.
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
      # enabled TLS
#      - 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

    #  - CORE_PEER_GOSSIP_USELEADERELECTION=true
     # - CORE_PEER_GOSSIP_ORGLEADER=false
     # - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.trace.com:7051
     # - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.trace.com:7051
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    #command: peer node start --peer-chaincodedev=true
    ports:
      - 7051:7051
#      - 7052:7052
      - 7053:7053
    volumes:
        - /var/run/:/host/var/run/
        - ./crypto-config/peerOrganizations/org1.trace.com/peers/peer0.org1.trace.com/msp:/etc/hyperledger/msp/peer
        - ./crypto-config/peerOrganizations/org1.trace.com/users:/etc/hyperledger/msp/users
        - ./config:/etc/hyperledger/configtx
#        - ./crypto-config/peerOrganizations/org1.trace.com/peers/peer0.org1.trace.com/msp:/etc/hyperledger/fabric/msp
#        - ./crypto-config/peerOrganizations/org1.trace.com/peers/peer0.org1.trace.com/tls:/etc/hyperledger/fabric/tls
        - peer0.org1.trace.com:/var/hyperledger/production
    depends_on:
      - orderer.trace.com
      - couchdb
    networks:
      - basic


  peer0.org2.trace.com:
    container_name: peer0.org2.trace.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_PEER_ID=peer0.org2.trace.com
      - CORE_LOGGING_PEER=info
      - CORE_CHAINCODE_LOGGING_LEVEL=info
      - CORE_PEER_LOCALMSPID=Org2MSP
      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
      - CORE_PEER_ADDRESS=peer0.org2.trace.com:7051
      # # 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=basic-network_basic
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
      # The CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME and CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD
      # provide the credentials for ledger to connect to CouchDB.  The username and password must
      # match the username and password set for the associated CouchDB.
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
      # enabled TLS
#      - 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
      
      #- CORE_PEER_GOSSIP_USELEADERELECTION=true
      #- CORE_PEER_GOSSIP_ORGLEADER=false
      #- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.trace.com:7051
      #- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.trace.com:7051

    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    #command: peer node start --peer-chaincodedev=true
    ports:
      - 8051:7051
#      - 8052:7052
      - 8053:7053
    volumes:
        - /var/run/:/host/var/run/
        - ./crypto-config/peerOrganizations/org2.trace.com/peers/peer0.org2.trace.com/msp:/etc/hyperledger/msp/peer
        - ./crypto-config/peerOrganizations/org2.trace.com/users:/etc/hyperledger/msp/users
        - ./config:/etc/hyperledger/configtx
#        - ./crypto-config/peerOrganizations/org2.trace.com/peers/peer0.org2.trace.com/msp:/etc/hyperledger/fabric/msp
#        - ./crypto-config/peerOrganizations/org2.trace.com/peers/peer0.org2.trace.com/tls:/etc/hyperledger/fabric/tls
        - peer0.org2.trace.com:/var/hyperledger/production
    depends_on:
      - orderer.trace.com
      - couchdb
    networks:
      - basic


  peer0.org3.trace.com:
    container_name: peer0.org3.trace.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_PEER_ID=peer0.org3.trace.com
      - CORE_LOGGING_PEER=info
      - CORE_CHAINCODE_LOGGING_LEVEL=info
      - CORE_PEER_LOCALMSPID=Org3MSP
      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
      - CORE_PEER_ADDRESS=peer0.org3.trace.com:7051
      # # 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=basic-network_basic
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
      # The CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME and CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD
      # provide the credentials for ledger to connect to CouchDB.  The username and password must
      # match the username and password set for the associated CouchDB.
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
      # enabled TLS
#      - 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

      #- CORE_PEER_GOSSIP_USELEADERELECTION=true
      #- CORE_PEER_GOSSIP_ORGLEADER=false
      #- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org3.trace.com:7051
      #- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org3.trace.com:7051
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    #command: peer node start --peer-chaincodedev=true
    ports:
      - 9051:7051
      - 9053:7053
    volumes:
        - /var/run/:/host/var/run/
        - ./crypto-config/peerOrganizations/org3.trace.com/peers/peer0.org3.trace.com/msp:/etc/hyperledger/msp/peer
        - ./crypto-config/peerOrganizations/org3.trace.com/users:/etc/hyperledger/msp/users
        - ./config:/etc/hyperledger/configtx
#        - ./crypto-config/peerOrganizations/org3.trace.com/peers/peer0.org3.trace.com/msp:/etc/hyperledger/fabric/msp
#        - ./crypto-config/peerOrganizations/org3.trace.com/peers/peer0.org3.trace.com/tls:/etc/hyperledger/fabric/tls
        - peer0.org3.trace.com:/var/hyperledger/production
    depends_on:
      - orderer.trace.com
      - couchdb
    networks:
      - basic


  peer0.org4.trace.com:
    container_name: peer0.org4.trace.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_PEER_ID=peer0.org4.trace.com
      - CORE_LOGGING_PEER=info
      - CORE_CHAINCODE_LOGGING_LEVEL=info
      - CORE_PEER_LOCALMSPID=Org4MSP
      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
      - CORE_PEER_ADDRESS=peer0.org4.trace.com:7051
      # # 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=basic-network_basic
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
      # The CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME and CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD
      # provide the credentials for ledger to connect to CouchDB.  The username and password must
      # match the username and password set for the associated CouchDB.
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
      # enabled TLS
 #     - 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

      #- CORE_PEER_GOSSIP_USELEADERELECTION=true
      #- CORE_PEER_GOSSIP_ORGLEADER=false
      #- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org4.trace.com:7051
      #- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org4.trace.com:7051
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    #command: peer node start --peer-chaincodedev=true
    ports:
      - 10051:7051
      - 10053:7053
    volumes:
        - /var/run/:/host/var/run/
        - ./crypto-config/peerOrganizations/org4.trace.com/peers/peer0.org4.trace.com/msp:/etc/hyperledger/msp/peer
        - ./crypto-config/peerOrganizations/org4.trace.com/users:/etc/hyperledger/msp/users
        - ./config:/etc/hyperledger/configtx
 #       - ./crypto-config/peerOrganizations/org4.trace.com/peers/peer0.org4.trace.com/msp:/etc/hyperledger/fabric/msp
 #       - ./crypto-config/peerOrganizations/org4.trace.com/peers/peer0.org4.trace.com/tls:/etc/hyperledger/fabric/tls
        - peer0.org4.trace.com:/var/hyperledger/production
    depends_on:
      - orderer.trace.com
      - couchdb
    networks:
      - basic

  peer0.org5.trace.com:
    container_name: peer0.org5.trace.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_PEER_ID=peer0.org4.trace.com
      - CORE_LOGGING_PEER=info
      - CORE_CHAINCODE_LOGGING_LEVEL=info
      - CORE_PEER_LOCALMSPID=Org5MSP
      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
      - CORE_PEER_ADDRESS=peer0.org5.trace.com:7051
      # # 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=basic-network_basic
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
      # The CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME and CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD
      # provide the credentials for ledger to connect to CouchDB.  The username and password must
      # match the username and password set for the associated CouchDB.
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
      # enabled TLS
#      - 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
 
      #- CORE_PEER_GOSSIP_USELEADERELECTION=true
      #- CORE_PEER_GOSSIP_ORGLEADER=false
      #- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org5.trace.com:7051
      #- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org5.trace.com:7051
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    #command: peer node start --peer-chaincodedev=true
    ports:
      - 11051:7051
      - 11053:7053
    volumes:
        - /var/run/:/host/var/run/
        - ./crypto-config/peerOrganizations/org5.trace.com/peers/peer0.org5.trace.com/msp:/etc/hyperledger/msp/peer
        - ./crypto-config/peerOrganizations/org5.trace.com/users:/etc/hyperledger/msp/users
        - ./config:/etc/hyperledger/configtx
#        - ./crypto-config/peerOrganizations/org5.trace.com/peers/peer0.org5.trace.com/msp:/etc/hyperledger/fabric/msp
#        - ./crypto-config/peerOrganizations/org5.trace.com/peers/peer0.org5.trace.com/tls:/etc/hyperledger/fabric/tls
        - peer0.org5.trace.com:/var/hyperledger/production
    depends_on:
      - orderer.trace.com
      - couchdb
    networks:
      - basic


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

  cli:
    container_name: cli
    image: hyperledger/fabric-tools
    tty: true
    stdin_open: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_LOGGING_LEVEL=info
      - CORE_PEER_ID=cli
      - CORE_PEER_ADDRESS=peer0.org1.trace.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.trace.com/users/Admin@org1.trace.com/msp
      - CORE_CHAINCODE_KEEPALIVE=10
#      - CORE_PEER_TLS_ENABLED=true
#      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.trace.com/peers/peer0.org1.trace.com/tls/server.crt
#      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.trace.com/peers/peer0.org1.trace.com/tls/server.key
#      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.trace.com/peers/peer0.org1.trace.com/tls/ca.crt
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
        - /var/run/:/host/var/run/
        - ./../chaincode/:/opt/gopath/src/github.com/chaincode
        - ./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.trace.com
      - peer0.org1.trace.com
      - peer0.org2.trace.com
      - peer0.org3.trace.com
      - peer0.org4.trace.com
      - peer0.org5.trace.com

    networks:
        - basic
    #depends_on:
    #  - orderer.example.com
    #  - peer0.org1.example.com
    #  - couchdb

3 问题解决记录

问题解决:

Error: error getting endorser client for channel: endorser client failed to connect to peer0.org1.trace.com:7051: failed to create new connection: connection error: desc = "transport: error while dialing: dial tcp 172.22.0.7:7051: connect: connection refused"
Error: error getting endorser client for channel: endorser client failed to connect to peer0.org1.trace.com:7051: failed to create new connection: context deadline exceeded

解决方法:

sudo vi /etc/resolv.conf

hyperledger fabric网络操作基本操作和概念,深入探索hyperledger fabric联盟链搭建,fabric,网络,区块链

按:wq!退出

4 启动区块链docker节点

4.1 常用docker命令

删除所有容器

# 1.停用全部运行中的容器:
docker stop $(docker ps -q)
# 2.删除全部容器:
docker rm $(docker ps -aq)

删除所有镜像

docker rmi -f $(docker images -qa)

删除数据卷

# 删除数据卷:
docker volume rm $(docker volume ls -q)
# 删除 network:
docker network rm $(docker network ls -q)

一键执行

docker stop $(docker ps -q)
docker rm $(docker ps -aq)
docker volume rm $(docker volume ls -q)
./start.sh

拉取对应版本镜像(包含区块链fabric1.4.7和1.2.0)

## 1) 基础镜像
docker pull hyperledger/fabric-peer:1.4.7
docker tag hyperledger/fabric-peer:1.4.7 hyperledger/fabric-peer:latest

docker pull hyperledger/fabric-orderer:1.4.7
docker tag hyperledger/fabric-orderer:1.4.7 hyperledger/fabric-orderer:latest

docker pull hyperledger/fabric-tools:1.4.7
docker tag hyperledger/fabric-tools:1.4.7 hyperledger/fabric-tools:latest

docker pull hyperledger/fabric-ccenv:1.4.7
docker tag hyperledger/fabric-ccenv:1.4.7 hyperledger/fabric-ccenv:latest

docker pull hyperledger/fabric-ca:1.4.7
docker tag hyperledger/fabric-ca:1.4.7 hyperledger/fabric-ca:latest

## 2) 数据库与消息队列镜像
docker pull hyperledger/fabric-baseos:0.4.15
docker tag hyperledger/fabric-baseos:0.4.15 hyperledger/fabric-baseos:latest

docker pull hyperledger/fabric-couchdb:0.4.15
docker tag hyperledger/fabric-couchdb:0.4.15 hyperledger/fabric-couchdb:latest

docker pull hyperledger/fabric-kafka:0.4.15
docker tag hyperledger/fabric-kafka:0.4.15 hyperledger/fabric-kafka:latest

docker pull hyperledger/fabric-zookeeper:0.4.15 
docker tag hyperledger/fabric-zookeeper:0.4.15 hyperledger/fabric-zookeeper:latest

## 3) Java语言包镜像(可选)
# docker pull hyperledger/fabric-javaenv:1.4.7
# docker tag hyperledger/fabric-javaenv:1.4.7 hyperledger/fabric-javaenv:latest

1.2 版本

## 1) 基础镜像
docker pull hyperledger/fabric-peer:1.2.0
docker tag hyperledger/fabric-peer:1.2.0 hyperledger/fabric-peer:latest

docker pull hyperledger/fabric-orderer:1.2.0
docker tag hyperledger/fabric-orderer:1.2.0 hyperledger/fabric-orderer:latest

docker pull hyperledger/fabric-tools:1.2.0
docker tag hyperledger/fabric-tools:1.2.0 hyperledger/fabric-tools:latest

docker pull hyperledger/fabric-ccenv:1.2.0
docker tag hyperledger/fabric-ccenv:1.2.0 hyperledger/fabric-ccenv:latest

docker pull hyperledger/fabric-ca:1.2.0
docker tag hyperledger/fabric-ca:1.2.0 hyperledger/fabric-ca:latest

## 2) 数据库与消息队列镜像
docker pull hyperledger/fabric-baseos:0.4.10
docker tag hyperledger/fabric-baseos:0.4.10 hyperledger/fabric-baseos:latest

docker pull hyperledger/fabric-couchdb:0.4.10
docker tag hyperledger/fabric-couchdb:0.4.10 hyperledger/fabric-couchdb:latest

docker pull hyperledger/fabric-kafka:0.4.10
docker tag hyperledger/fabric-kafka:0.4.10 hyperledger/fabric-kafka:latest

docker pull hyperledger/fabric-zookeeper:0.4.10 
docker tag hyperledger/fabric-zookeeper:0.4.10 hyperledger/fabric-zookeeper:latest

## 3) Java语言包镜像(可选)
# docker pull hyperledger/fabric-javaenv:1.2.0
# docker tag hyperledger/fabric-javaenv:1.2.0 hyperledger/fabric-javaenv:latest

5 fabric-node-sdk后台搭建

nodejs 后台搭建(在ubuntu 阿里云服务器)
安装nvm

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash

hyperledger fabric网络操作基本操作和概念,深入探索hyperledger fabric联盟链搭建,fabric,网络,区块链

执行

source ~/.bashrc

下载node依赖

nvm install 12.13.1
rm -rf node_modules
rm -rf hfc-key-store
nvm use 12.13.1
npm install
nvm use 12.13.1
npm rebuild
npm install fabric-client
npm install fabric-ca-client
node enrollAdmin.js
node registerUser.js
npm install express
npm install body-parser
npm install influx

npm install forever -g
forever start app.js

访问http://xxx.xxx.xxx:5984/_utils/#查看区块链的couchdb
hyperledger fabric网络操作基本操作和概念,深入探索hyperledger fabric联盟链搭建,fabric,网络,区块链
node sdk后台查看
hyperledger fabric网络操作基本操作和概念,深入探索hyperledger fabric联盟链搭建,fabric,网络,区块链
docker节点查看
hyperledger fabric网络操作基本操作和概念,深入探索hyperledger fabric联盟链搭建,fabric,网络,区块链文章来源地址https://www.toymoban.com/news/detail-796820.html

到了这里,关于hyperledger fabric 网络操作基本操作和概念的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 王道操作系统学习笔记(1)——操作系统基本概念

    本文介绍了操作系统的基本概念,文章中的内容来自B站王道考研操作系统课程,想要完整学习的可以到B站官方看完整版。 操作系统:系统资源的管理者(处理机管理、存储器管理、文件管理、设备管理) 交互式命令(在终端中输命令)和批处理命令(Shell脚本) 并发: 宏

    2024年02月10日
    浏览(52)
  • 栈的概念及其基本操作--详细(C++)

    基本概念及相关术语: 栈是只允许 在一端 进行插入和删除操作的 线性表 。 由此可见,栈也是线性表的一种,只是栈的操作受限制的线性表。 栈顶(top):线性表允许插入和删除的那一段。 值得注意的是,栈顶指针top的指向是有些两种方式的,一种是指向栈顶当前元素,

    2024年02月08日
    浏览(38)
  • 【数据结构】_7.二叉树概念与基本操作

    目录 1.树形结构 1.1 树的概念 1.2 树的相关概念 1.3 树的表示 1.4 树在实际中的应用—表示文件系统的目录树结构 ​编辑​2.二叉树 2.1 概念 2.2 特殊二叉树  2.3 二叉树的性质 2.4 二叉树的存储结构 2.4.1 顺序存储结构(数组存储结构) 2.4.2 链式存储结构 2.5 二叉树的基本操作 2

    2024年02月12日
    浏览(39)
  • 【linux】docker基本概念和基础指令操作(镜像、容器)

    docker 镜像 images xxxx(名称):xxxx(版本号) 每一个image可以生成若干个 容器 (container),所有用相同镜像生成的容器环境完全一样 每一个容器都是一个完全独立的云端服务器

    2024年02月01日
    浏览(55)
  • Docker - 基本概念、与虚拟机的区别、架构、镜像操作、容器操作、数据卷挂载

    目录 一、对 Docker  的理解 1、Docker 基本概念 2、Docker 与 虚拟机的区别 3、何为镜像和容器? 4、Docker 主要架构 二、Docker 基本操作 1、Docker 镜像操作 2、案例(镜像):去 DockerHub 搜索并拉取一个 Nginx 镜像,打包后删除镜像,重新加载 .tar 文件 3、Docker 容器操作 1.docker run(启

    2024年04月13日
    浏览(48)
  • Git 分布式版本控制系统基本概念和操作命令

    目录 Git 基本概念 功能特点 工作流程 操作命令 新建代码库 配置 增删文件 代码提交 分支 标签 查看信息 远程同步 撤销 其他 小结 Git 是一个开源的分布式版本控制系统,用于跟踪文件的变更历史。它最初由 Linux Torvalds 设计,用于 Linux 内核的开发,但由于其强大的功能和灵

    2024年03月27日
    浏览(65)
  • MySQL数据库概念、管理以及SQL语句的基本命令操作

    数据(data) 描述事物的符号记录 包括数字,文字、图形、图像、声音、档案记录等 以“记录”形式按统一格式进行存储(记录可以看成一条记录) 表 将不同的记录组织在一起 用来存储具体数据 记录:行 字段(属性):列 以行+列的形式就组成了表(数据存储在表中) 数

    2024年02月08日
    浏览(71)
  • K8S初级入门系列之三-Pod的基本概念和操作

           Pod的原意是豌豆荚的意思,一个豆荚里面包含了很多豆子。在K8S中,Pod也是类似的意思,只不过这里的豆子就是容器。在K8S初级入门系列之一-概述中,我们对Pod有个初步的了解。 1、Pod是K8S编排和调度的最小基础单元。         了解容器的同学会知道,容器之间通过

    2024年02月15日
    浏览(37)
  • Hyperledger Fabric网络快速启动

    目录 1、网络服务配置 2、关联的docker-compose-base.yaml 各Peer节点容器设置如下信息。 3、被关联的Peer-base.yaml 4、启动网络 2、完成通道的创建 2.1将节点加入应用通道  更新锚节点  2.为什么要创建节点并将其加入应用通道中?         由于要启动多个网络节点,Hyperledger Fa

    2024年02月12日
    浏览(39)
  • Git企业开发控制理论和实操-从入门到深入(二)|Git的基本操作

    那么这里博主先安利一些干货满满的专栏了! 首先是博主的高质量博客的汇总,这个专栏里面的博客,都是博主最最用心写的一部分,干货满满,希望对大家有帮助。 高质量博客汇总 https://blog.csdn.net/yu_cblog/category_12379430.html 然后就是博主最近最花信息的一个专栏《Git企业开

    2024年02月11日
    浏览(49)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包