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

  • hyperledger fabric 网络操作基本操作和概念
  • 1. cryptogen 操作
    • 1.1 cryptogen 生成证书文件
      • 1.1.1 生成证书文件模板
        • 1.1.1.1 排序节点OrdererOrgs配置
        • 1.1.1.2 普通节点PeerOrgs配置
        • 1.1.1.3 Template 配置
        • 1.1.1.4 Users用户配置
        • 1.1.1.5 crypto-config.yaml
      • 1.1.2 生成密钥材料
    • 1.2 cryptogen.yaml 创建通道配置
      • 1.2.1 configx.yaml
    • 1.3 网络初始化
  • 2. docker compose
    • 2.1 docker-compose.yaml
  • 3 问题解决记录
  • 4 启动区块链docker节点
    • 4.1 常用docker命令
  • 5 fabric-node-sdk后台搭建

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

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

1. cryptogen 操作

1.1 cryptogen 生成证书文件

1.1.1 生成证书文件模板

# 打印模板到终端cryptogen showtemplate# 打印模板到配置文件crypto-config.yamlcryptogen 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 descriptionSpecs:- 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 AdminUsers:Count: 1
1.1.1.5 crypto-config.yaml

Order组织节点定义

OrdererOrgs:# ---------------------------------------------------------------------------# Orderer# ---------------------------------------------------------------------------- Name: OrdererDomain: trace.comSpecs:- Hostname: ordererPeerOrgs:# ---------------------------------------------------------------------------# Org1# ---------------------------------------------------------------------------- Name: Org1Domain: org1.trace.comTemplate:Count: 1Users:Count: 1 # ---------------------------------------------------------------------------# Org2# ---------------------------------------------------------------------------- Name: Org2Domain: org2.trace.comTemplate:Count: 1Users:Count: 1 # ---------------------------------------------------------------------------# Org3# ---------------------------------------------------------------------------- Name: Org3Domain: org3.trace.comTemplate:Count: 1Users:Count: 1 # ---------------------------------------------------------------------------# Org4# ---------------------------------------------------------------------------- Name: Org4Domain: org4.trace.comTemplate:Count: 1Users:Count: 1# ---------------------------------------------------------------------------# Org5# ---------------------------------------------------------------------------- Name: Org5Domain: org5.trace.comTemplate:Count: 1Users:Count: 1

1.1.2 生成密钥材料

cryptogen generate --config=crypto-config.yaml

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 environmentName: OrdererOrg# ID to load the MSP definition asID: OrdererMSP# MSPDir is the filesystem path which contains the MSP configurationMSPDir: crypto-config/ordererOrganizations/trace.com/msp- &Org1# DefaultOrg defines the organization which is used in the sampleconfig# of the fabric.git development environmentName: Org1MSP# ID to load the MSP definition asID: Org1MSPMSPDir: crypto-config/peerOrganizations/org1.trace.com/mspAnchorPeers:# 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.comPort: 7051- &Org2# DefaultOrg defines the organization which is used in the sampleconfig# of the fabric.git development environmentName: Org2MSP# ID to load the MSP definition asID: Org2MSPMSPDir: crypto-config/peerOrganizations/org2.trace.com/mspAnchorPeers:# 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.comPort: 7051- &Org3# DefaultOrg defines the organization which is used in the sampleconfig# of the fabric.git development environmentName: Org3MSP# ID to load the MSP definition asID: Org3MSPMSPDir: crypto-config/peerOrganizations/org3.trace.com/mspAnchorPeers:# 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.comPort: 7051- &Org4# DefaultOrg defines the organization which is used in the sampleconfig# of the fabric.git development environmentName: Org4MSP# ID to load the MSP definition asID: Org4MSPMSPDir: crypto-config/peerOrganizations/org4.trace.com/mspAnchorPeers:# 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.comPort: 7051- &Org5# DefaultOrg defines the organization which is used in the sampleconfig# of the fabric.git development environmentName: Org5MSP# ID to load the MSP definition asID: Org5MSPMSPDir: crypto-config/peerOrganizations/org5.trace.com/mspAnchorPeers:# 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.comPort: 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 whichwould 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 networkOrganizations:################################################################################## 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: soloAddresses:- orderer.trace.com:7050# Batch Timeout: The amount of time to wait before creating a batchBatchTimeout: 2s# Batch Size: Controls the number of messages batched into a blockBatchSize:# Max Message Count: The maximum number of messages to permit in a batchMaxMessageCount: 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 KBKafka:# Brokers: A list of Kafka brokers to which the orderer connects# NOTE: Use IP:port notationBrokers:- 127.0.0.1:9092# Organizations is the list of orgs which are defined as participants on# the orderer side of the networkOrganizations:################################################################################## Profile## - Different configuration profiles may be encoded here to be specified# as parameters to the configtxgen tool#################################################################################Profiles:FiveOrgsOrdererGenesis:Capabilities:<<: *ChannelCapabilitiesOrderer:<<: *OrdererDefaultsOrganizations:- *OrdererOrgCapabilities:<<: *OrdererCapabilitiesConsortiums:SampleConsortium:Organizations:- *Org1- *Org2- *Org3- *Org4- *Org5FiveOrgsChannel:Consortium: SampleConsortiumApplication:<<: *ApplicationDefaultsOrganizations:- *Org1- *Org2- *Org3- *Org4- *Org5Capabilities:<<: *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-caenvironment:- 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_skports:- 7054:7054command: sh -c 'fabric-ca-server start -b admin:adminpw -d'volumes:- ./crypto-config/peerOrganizations/org1.trace.com/ca/:/etc/hyperledger/fabric-ca-server-configcontainer_name: ca.trace.comnetworks:- basicorderer.trace.com:container_name: orderer.trace.comimage: hyperledger/fabric-ordererenvironment:- 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/fabriccommand: orderervolumes:- ./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/ordererports:- 7050:7050networks:- basicpeer0.org1.trace.com:container_name: peer0.org1.trace.comimage: hyperledger/fabric-peerenvironment:- 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:7051working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peercommand: peer node start#command: peer node start --peer-chaincodedev=trueports:- 7051:7051#- 7052:7052- 7053:7053volumes:- /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/productiondepends_on:- orderer.trace.com- couchdbnetworks:- basicpeer0.org2.trace.com:container_name: peer0.org2.trace.comimage: hyperledger/fabric-peerenvironment:- 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:7051working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peercommand: peer node start#command: peer node start --peer-chaincodedev=trueports:- 8051:7051#- 8052:7052- 8053:7053volumes:- /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/productiondepends_on:- orderer.trace.com- couchdbnetworks:- basicpeer0.org3.trace.com:container_name: peer0.org3.trace.comimage: hyperledger/fabric-peerenvironment:- 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:7051working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peercommand: peer node start#command: peer node start --peer-chaincodedev=trueports:- 9051:7051- 9053:7053volumes:- /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/productiondepends_on:- orderer.trace.com- couchdbnetworks:- basicpeer0.org4.trace.com:container_name: peer0.org4.trace.comimage: hyperledger/fabric-peerenvironment:- 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:7051working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peercommand: peer node start#command: peer node start --peer-chaincodedev=trueports:- 10051:7051- 10053:7053volumes:- /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/productiondepends_on:- orderer.trace.com- couchdbnetworks:- basicpeer0.org5.trace.com:container_name: peer0.org5.trace.comimage: hyperledger/fabric-peerenvironment:- 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:7051working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peercommand: peer node start#command: peer node start --peer-chaincodedev=trueports:- 11051:7051- 11053:7053volumes:- /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/productiondepends_on:- orderer.trace.com- couchdbnetworks:- basiccouchdb:container_name: couchdbimage: 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:5984networks:- basiccli:container_name: cliimage: hyperledger/fabric-toolstty: truestdin_open: trueenvironment:- 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.crtworking_dir: /opt/gopath/src/github.com/hyperledger/fabric/peercommand: /bin/bashvolumes:- /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-artifactsdepends_on:- orderer.trace.com- peer0.org1.trace.com- peer0.org2.trace.com- peer0.org3.trace.com- peer0.org4.trace.com- peer0.org5.trace.comnetworks:- 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

按: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.7docker tag hyperledger/fabric-peer:1.4.7 hyperledger/fabric-peer:latestdocker pull hyperledger/fabric-orderer:1.4.7docker tag hyperledger/fabric-orderer:1.4.7 hyperledger/fabric-orderer:latestdocker pull hyperledger/fabric-tools:1.4.7docker tag hyperledger/fabric-tools:1.4.7 hyperledger/fabric-tools:latestdocker pull hyperledger/fabric-ccenv:1.4.7docker tag hyperledger/fabric-ccenv:1.4.7 hyperledger/fabric-ccenv:latestdocker pull hyperledger/fabric-ca:1.4.7docker tag hyperledger/fabric-ca:1.4.7 hyperledger/fabric-ca:latest## 2) 数据库与消息队列镜像docker pull hyperledger/fabric-baseos:0.4.15docker tag hyperledger/fabric-baseos:0.4.15 hyperledger/fabric-baseos:latestdocker pull hyperledger/fabric-couchdb:0.4.15docker tag hyperledger/fabric-couchdb:0.4.15 hyperledger/fabric-couchdb:latestdocker pull hyperledger/fabric-kafka:0.4.15docker tag hyperledger/fabric-kafka:0.4.15 hyperledger/fabric-kafka:latestdocker 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.0docker tag hyperledger/fabric-peer:1.2.0 hyperledger/fabric-peer:latestdocker pull hyperledger/fabric-orderer:1.2.0docker tag hyperledger/fabric-orderer:1.2.0 hyperledger/fabric-orderer:latestdocker pull hyperledger/fabric-tools:1.2.0docker tag hyperledger/fabric-tools:1.2.0 hyperledger/fabric-tools:latestdocker pull hyperledger/fabric-ccenv:1.2.0docker tag hyperledger/fabric-ccenv:1.2.0 hyperledger/fabric-ccenv:latestdocker pull hyperledger/fabric-ca:1.2.0docker tag hyperledger/fabric-ca:1.2.0 hyperledger/fabric-ca:latest## 2) 数据库与消息队列镜像docker pull hyperledger/fabric-baseos:0.4.10docker tag hyperledger/fabric-baseos:0.4.10 hyperledger/fabric-baseos:latestdocker pull hyperledger/fabric-couchdb:0.4.10docker tag hyperledger/fabric-couchdb:0.4.10 hyperledger/fabric-couchdb:latestdocker pull hyperledger/fabric-kafka:0.4.10docker tag hyperledger/fabric-kafka:0.4.10 hyperledger/fabric-kafka:latestdocker 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

执行

source ~/.bashrc

下载node依赖

nvm install 12.13.1rm -rf node_modulesrm -rf hfc-key-storenvm use 12.13.1npm installnvm use 12.13.1npm rebuildnpm install fabric-clientnpm install fabric-ca-clientnode enrollAdmin.jsnode registerUser.jsnpm install expressnpm install body-parsernpm install influxnpm install forever -gforever start app.js

访问http://xxx.xxx.xxx:5984/_utils/#查看区块链的couchdb

node sdk后台查看

docker节点查看