文章目录

  • 一、搭建基础环境
  • 二、生成证书文件
    • 1、准备证书配置文件模板
    • 2、修改模板
    • 3、生成证书文件
  • 三、生成通道文件
    • 1、编写创世快文件
    • 2、生成创世块文件和通道文件
  • 三、配置各个节点
    • 1、编写docker-compose文件
    • 2、运行docker-compose文件
  • 四、通道操作
    • 1、创建通道
    • 2、加入通道
      • 1、peer0节点加入通道
      • 2、更新锚节点
  • 五、安装调用智能合约
    • 1、复制官方实例链码
    • 2、安装go依赖并打包链码
    • 3、将打包好的链码复制到cli2
    • 4、安装链码
    • 5、批准链码
    • 6、查看链码是否就绪
    • 7、提交链码
    • 8、链码初始化
    • 9、查询数据

一、搭建基础环境

二、生成证书文件

1、准备证书配置文件模板

[root@orderer ~]# mkdir twonodes
[root@orderer ~]# cd twonodes/
[root@orderer twonodes]# cryptogen showtemplate > crypto-config.yaml

2、修改模板

[root@orderer twonodes]# sed -i "s/false/true/g" crypto-config.yaml
[root@orderer twonodes]# cat crypto-config.yaml | grep ^[^#]
OrdererOrgs:# ---------------------------------------------------------------------------# Orderer# ---------------------------------------------------------------------------- Name: OrdererDomain: example.comEnableNodeOUs: true# ---------------------------------------------------------------------------# "Specs" - See PeerOrgs below for complete description# ---------------------------------------------------------------------------Specs:- Hostname: orderer
PeerOrgs:# ---------------------------------------------------------------------------# Org1# ---------------------------------------------------------------------------- Name: Org1Domain: org1.example.comEnableNodeOUs: 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: 1# 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: Org2Domain: org2.example.comEnableNodeOUs: trueTemplate:Count: 1Users:Count: 1

3、生成证书文件

[root@orderer twonodes]# cryptogen generate --config=crypto-config.yaml
org1.example.com
org2.example.com
[root@orderer twonodes]# tree
.
├── crypto-config
│   ├── ordererOrganizations
│   │   └── example.com
│   │       ├── ca
│   │       │   ├── ca.example.com-cert.pem
│   │       │   └── priv_sk
│   │       ├── msp
│   │       │   ├── admincerts
│   │       │   ├── cacerts
│   │       │   │   └── ca.example.com-cert.pem
│   │       │   ├── config.yaml
│   │       │   └── tlscacerts
│   │       │       └── tlsca.example.com-cert.pem
│   │       ├── orderers
│   │       │   └── orderer.example.com
│   │       │       ├── msp
│   │       │       │   ├── admincerts
│   │       │       │   ├── cacerts
│   │       │       │   │   └── ca.example.com-cert.pem
│   │       │       │   ├── config.yaml
│   │       │       │   ├── keystore
│   │       │       │   │   └── priv_sk
│   │       │       │   ├── signcerts
│   │       │       │   │   └── orderer.example.com-cert.pem
│   │       │       │   └── tlscacerts
│   │       │       │       └── tlsca.example.com-cert.pem
│   │       │       └── tls
│   │       │           ├── ca.crt
│   │       │           ├── server.crt
│   │       │           └── server.key
│   │       ├── tlsca
│   │       │   ├── priv_sk
│   │       │   └── tlsca.example.com-cert.pem
│   │       └── users
│   │           └── Admin@example.com
│   │               ├── msp
│   │               │   ├── admincerts
│   │               │   ├── cacerts
│   │               │   │   └── ca.example.com-cert.pem
│   │               │   ├── config.yaml
│   │               │   ├── keystore
│   │               │   │   └── priv_sk
│   │               │   ├── signcerts
│   │               │   │   └── Admin@example.com-cert.pem
│   │               │   └── tlscacerts
│   │               │       └── tlsca.example.com-cert.pem
│   │               └── tls
│   │                   ├── ca.crt
│   │                   ├── client.crt
│   │                   └── client.key
│   └── peerOrganizations
│       ├── org1.example.com
│       │   ├── ca
│       │   │   ├── ca.org1.example.com-cert.pem
│       │   │   └── priv_sk
│       │   ├── msp
│       │   │   ├── admincerts
│       │   │   ├── cacerts
│       │   │   │   └── ca.org1.example.com-cert.pem
│       │   │   ├── config.yaml
│       │   │   └── tlscacerts
│       │   │       └── tlsca.org1.example.com-cert.pem
│       │   ├── peers
│       │   │   └── peer0.org1.example.com
│       │   │       ├── msp
│       │   │       │   ├── admincerts
│       │   │       │   ├── cacerts
│       │   │       │   │   └── ca.org1.example.com-cert.pem
│       │   │       │   ├── config.yaml
│       │   │       │   ├── keystore
│       │   │       │   │   └── priv_sk
│       │   │       │   ├── signcerts
│       │   │       │   │   └── peer0.org1.example.com-cert.pem
│       │   │       │   └── tlscacerts
│       │   │       │       └── tlsca.org1.example.com-cert.pem
│       │   │       └── tls
│       │   │           ├── ca.crt
│       │   │           ├── server.crt
│       │   │           └── server.key
│       │   ├── tlsca
│       │   │   ├── priv_sk
│       │   │   └── tlsca.org1.example.com-cert.pem
│       │   └── users
│       │       ├── Admin@org1.example.com
│       │       │   ├── msp
│       │       │   │   ├── admincerts
│       │       │   │   ├── cacerts
│       │       │   │   │   └── ca.org1.example.com-cert.pem
│       │       │   │   ├── config.yaml
│       │       │   │   ├── keystore
│       │       │   │   │   └── priv_sk
│       │       │   │   ├── signcerts
│       │       │   │   │   └── Admin@org1.example.com-cert.pem
│       │       │   │   └── tlscacerts
│       │       │   │       └── tlsca.org1.example.com-cert.pem
│       │       │   └── tls
│       │       │       ├── ca.crt
│       │       │       ├── client.crt
│       │       │       └── client.key
│       │       └── User1@org1.example.com
│       │           ├── msp
│       │           │   ├── admincerts
│       │           │   ├── cacerts
│       │           │   │   └── ca.org1.example.com-cert.pem
│       │           │   ├── config.yaml
│       │           │   ├── keystore
│       │           │   │   └── priv_sk
│       │           │   ├── signcerts
│       │           │   │   └── User1@org1.example.com-cert.pem
│       │           │   └── tlscacerts
│       │           │       └── tlsca.org1.example.com-cert.pem
│       │           └── tls
│       │               ├── ca.crt
│       │               ├── client.crt
│       │               └── client.key
│       └── org2.example.com
│           ├── ca
│           │   ├── ca.org2.example.com-cert.pem
│           │   └── priv_sk
│           ├── msp
│           │   ├── admincerts
│           │   ├── cacerts
│           │   │   └── ca.org2.example.com-cert.pem
│           │   ├── config.yaml
│           │   └── tlscacerts
│           │       └── tlsca.org2.example.com-cert.pem
│           ├── peers
│           │   └── peer0.org2.example.com
│           │       ├── msp
│           │       │   ├── admincerts
│           │       │   ├── cacerts
│           │       │   │   └── ca.org2.example.com-cert.pem
│           │       │   ├── config.yaml
│           │       │   ├── keystore
│           │       │   │   └── priv_sk
│           │       │   ├── signcerts
│           │       │   │   └── peer0.org2.example.com-cert.pem
│           │       │   └── tlscacerts
│           │       │       └── tlsca.org2.example.com-cert.pem
│           │       └── tls
│           │           ├── ca.crt
│           │           ├── server.crt
│           │           └── server.key
│           ├── tlsca
│           │   ├── priv_sk
│           │   └── tlsca.org2.example.com-cert.pem
│           └── users
│               ├── Admin@org2.example.com
│               │   ├── msp
│               │   │   ├── admincerts
│               │   │   ├── cacerts
│               │   │   │   └── ca.org2.example.com-cert.pem
│               │   │   ├── config.yaml
│               │   │   ├── keystore
│               │   │   │   └── priv_sk
│               │   │   ├── signcerts
│               │   │   │   └── Admin@org2.example.com-cert.pem
│               │   │   └── tlscacerts
│               │   │       └── tlsca.org2.example.com-cert.pem
│               │   └── tls
│               │       ├── ca.crt
│               │       ├── client.crt
│               │       └── client.key
│               └── User1@org2.example.com
│                   ├── msp
│                   │   ├── admincerts
│                   │   ├── cacerts
│                   │   │   └── ca.org2.example.com-cert.pem
│                   │   ├── config.yaml
│                   │   ├── keystore
│                   │   │   └── priv_sk
│                   │   ├── signcerts
│                   │   │   └── User1@org2.example.com-cert.pem
│                   │   └── tlscacerts
│                   │       └── tlsca.org2.example.com-cert.pem
│                   └── tls
│                       ├── ca.crt
│                       ├── client.crt
│                       └── client.key
└── crypto-config.yaml

三、生成通道文件

1、编写创世快文件

[root@orderer twonodes]# vim 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 environmentName: OrdererOrg# ID to load the MSP definition asID: OrdererMSP# MSPDir is the filesystem path which contains the MSP configurationMSPDir: 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: SignatureRule: "OR('OrdererMSP.member')"Writers:Type: SignatureRule: "OR('OrdererMSP.member')"Admins:Type: SignatureRule: "OR('OrdererMSP.admin')"OrdererEndpoints:- orderer.example.com:7050- &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.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: SignatureRule: "OR('Org1MSP.admin', 'Org1MSP.peer', 'Org1MSP.client')"Writers:Type: SignatureRule: "OR('Org1MSP.admin', 'Org1MSP.client')"Admins:Type: SignatureRule: "OR('Org1MSP.admin')"Endorsement:Type: SignatureRule: "OR('Org1MSP.peer')"AnchorPeers:- Host: peer0.org1.example.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.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: SignatureRule: "OR('Org2MSP.admin', 'Org2MSP.peer', 'Org2MSP.client')"Writers:Type: SignatureRule: "OR('Org2MSP.admin', 'Org2MSP.client')"Admins:Type: SignatureRule: "OR('Org2MSP.admin')"Endorsement:Type: SignatureRule: "OR('Org2MSP.peer')"AnchorPeers:- Host: peer0.org2.example.comPort: 9051
################################################################################
#
#   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 networkOrganizations:# 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: ImplicitMetaRule: "ANY Readers"Writers:Type: ImplicitMetaRule: "ANY Writers"Admins:Type: ImplicitMetaRule: "MAJORITY Admins"LifecycleEndorsement:Type: ImplicitMetaRule: "MAJORITY Endorsement"Endorsement:Type: ImplicitMetaRule: "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 startOrdererType: 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 definitionAddresses:- orderer.example.com:7050EtcdRaft:Consenters:- Host: orderer.example.comPort: 7050ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crtServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt# 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 KB# Organizations is the list of orgs which are defined as participants on# the orderer side of the networkOrganizations:# 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: ImplicitMetaRule: "ANY Readers"Writers:Type: ImplicitMetaRule: "ANY Writers"Admins:Type: ImplicitMetaRule: "MAJORITY Admins"# BlockValidation specifies what signatures must be included in the block# from the orderer for the peer to validate it.BlockValidation:Type: ImplicitMetaRule: "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' APIReaders:Type: ImplicitMetaRule: "ANY Readers"# Who may invoke the 'Broadcast' APIWriters:Type: ImplicitMetaRule: "ANY Writers"# By default, who may modify elements at this config levelAdmins:Type: ImplicitMetaRule: "MAJORITY Admins"# Capabilities describes the channel level capabilities, see the# dedicated Capabilities section elsewhere in this file for a full# descriptionCapabilities:<<: *ChannelCapabilities################################################################################
#
#   Profile
#
#   - Different configuration profiles may be encoded here to be specified
#   as parameters to the configtxgen tool
#
################################################################################
Profiles:TwoOrgsOrdererGenesis:<<: *ChannelDefaultsOrderer:<<: *OrdererDefaultsOrganizations:- *OrdererOrgCapabilities:<<: *OrdererCapabilitiesConsortiums:SampleConsortium:Organizations:- *Org1- *Org2TwoOrgsChannel:Consortium: SampleConsortium<<: *ChannelDefaultsApplication:<<: *ApplicationDefaultsOrganizations:- *Org1- *Org2Capabilities:<<: *ApplicationCapabilities

2、生成创世块文件和通道文件

生成创世区块

[root@orderer twonodes]# configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block -channelID fabric-channel
2021-11-01 14:27:06.683 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2021-11-01 14:27:06.689 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft
2021-11-01 14:27:06.689 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216
2021-11-01 14:27:06.689 CST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: configtx.yaml
2021-11-01 14:27:06.691 CST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block
2021-11-01 14:27:06.691 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Creating system channel genesis block
2021-11-01 14:27:06.691 CST [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block

生成通道文件

[root@orderer twonodes]# configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
2021-11-01 14:28:02.995 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2021-11-01 14:28:03.001 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: configtx.yaml
2021-11-01 14:28:03.001 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 003 Generating new channel configtx
2021-11-01 14:28:03.002 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 004 Writing new channel tx

为 Org1 定义锚节点

[root@orderer twonodes]# configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
2021-11-01 14:32:33.342 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2021-11-01 14:32:33.348 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: configtx.yaml
2021-11-01 14:32:33.348 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Generating anchor peer update
2021-11-01 14:32:33.349 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 004 Writing anchor peer update

为 Org2 定义锚节点

[root@orderer twonodes]# configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
2021-11-01 14:32:46.475 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2021-11-01 14:32:46.481 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: configtx.yaml
2021-11-01 14:32:46.481 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Generating anchor peer update
2021-11-01 14:32:46.482 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 004 Writing anchor peer update

查看生成的文件

[root@orderer twonodes]# ls channel-artifacts/
channel.tx  genesis.block  Org1MSPanchors.tx  Org2MSPanchors.tx

三、配置各个节点

1、编写docker-compose文件

[root@orderer twonodes]# vim docker-compose.yaml
version: '2.4'volumes:orderer.example.com:peer0.org1.example.com:peer0.org2.example.com:networks:test:name: twonodes_testservices:orderer.example.com:container_name: orderer.example.comimage: hyperledger/fabric-orderer:latestlabels:service: hyperledger-fabricenvironment:- 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:7053working_dir: /opt/gopath/src/github.com/hyperledger/fabriccommand: orderervolumes:- ./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block- ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp- ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls- orderer.example.com:/var/hyperledger/production/ordererports:- 7050:7050- 7053:7053networks:- testpeer0.org1.example.com:container_name: peer0.org1.example.comimage: hyperledger/fabric-peer:latestlabels:service: hyperledger-fabricenvironment:#Generic peer variables- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=twonodes_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.example.com- CORE_PEER_ADDRESS=peer0.org1.example.com:7051- CORE_PEER_LISTENADDRESS=0.0.0.0:7051- CORE_PEER_CHAINCODEADDRESS=peer0.org1.example.com:7052- CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051- CORE_PEER_LOCALMSPID=Org1MSPvolumes:- /var/run/docker.sock:/host/var/run/docker.sock- ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp- ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls- peer0.org1.example.com:/var/hyperledger/productionworking_dir: /opt/gopath/src/github.com/hyperledger/fabric/peercommand: peer node startports:- 7051:7051networks:- testpeer0.org2.example.com:container_name: peer0.org2.example.comimage: hyperledger/fabric-peer:latestlabels:service: hyperledger-fabricenvironment:#Generic peer variables- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=twonodes_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.example.com- CORE_PEER_ADDRESS=peer0.org2.example.com:9051- CORE_PEER_LISTENADDRESS=0.0.0.0:9051- CORE_PEER_CHAINCODEADDRESS=peer0.org2.example.com:9052- CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:9052- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:9051- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.example.com:9051- CORE_PEER_LOCALMSPID=Org2MSPvolumes:- /var/run/docker.sock:/host/var/run/docker.sock- ./crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp- ./crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls- peer0.org2.example.com:/var/hyperledger/productionworking_dir: /opt/gopath/src/github.com/hyperledger/fabric/peercommand: peer node startports:- 9051:9051networks:- testcli1:container_name: cli1image: hyperledger/fabric-tools:latesttty: truestdin_open: trueenvironment:- 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.example.com:7051- CORE_PEER_LOCALMSPID=Org1MSP- CORE_PEER_TLS_ENABLED=true- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/mspworking_dir: /opt/gopath/src/github.com/hyperledger/fabric/peercommand: /bin/bashvolumes:- /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-artifactsnetworks:- testcli2:container_name: cli2image: hyperledger/fabric-tools:latesttty: truestdin_open: trueenvironment:- 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.example.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.example.com/peers/peer0.org2.example.com/tls/server.crt- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/mspworking_dir: /opt/gopath/src/github.com/hyperledger/fabric/peercommand: /bin/bashvolumes:- /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-artifactsnetworks:- test

2、运行docker-compose文件

[root@orderer twonodes]# docker-compose up -d
Creating network "twonodes_test" with the default driver
Creating volume "twonodes_orderer.example.com" with default driver
Creating volume "twonodes_peer0.org1.example.com" with default driver
Creating volume "twonodes_peer0.org2.example.com" with default driver
Creating peer0.org2.example.com ... done
Creating orderer.example.com    ... done
Creating peer0.org1.example.com ... done
Creating cli2                   ... done
Creating cli1                   ... done
[root@orderer twonodes]# docker ps -a
CONTAINER ID   IMAGE                               COMMAND             CREATED         STATUS         PORTS                                                                                  NAMES
cc393bc2da45   hyperledger/fabric-peer:latest      "peer node start"   5 seconds ago   Up 4 seconds   0.0.0.0:7051->7051/tcp, :::7051->7051/tcp                                              peer0.org1.example.com
b299acc7a3d6   hyperledger/fabric-tools:latest     "/bin/bash"         5 seconds ago   Up 4 seconds                                                                                          cli1
5b20e3a2419f   hyperledger/fabric-tools:latest     "/bin/bash"         5 seconds ago   Up 4 seconds                                                                                          cli2
c1ffa9d27ff1   hyperledger/fabric-peer:latest      "peer node start"   5 seconds ago   Up 4 seconds   7051/tcp, 0.0.0.0:9051->9051/tcp, :::9051->9051/tcp                                    peer0.org2.example.com
693cb6b585ce   hyperledger/fabric-orderer:latest   "orderer"           5 seconds ago   Up 4 seconds   0.0.0.0:7050->7050/tcp, :::7050->7050/tcp, 0.0.0.0:7053->7053/tcp, :::7053->7053/tcp   orderer.example.com

四、通道操作

1、创建通道

进入cli1容器

[root@orderer twonodes]# docker exec -it cli1 bash

创建通道

bash-5.1# peer channel create -o orderer.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
2021-11-01 06:42:36.437 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2021-11-01 06:42:36.457 UTC [cli.common] readBlock -> INFO 002 Expect block, but got status: &{NOT_FOUND}
2021-11-01 06:42:36.459 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2021-11-01 06:42:36.660 UTC [cli.common] readBlock -> INFO 004 Expect block, but got status: &{SERVICE_UNAVAILABLE}
2021-11-01 06:42:36.663 UTC [channelCmd] InitCmdFactory -> INFO 005 Endorser and orderer connections initialized
2021-11-01 06:42:36.865 UTC [cli.common] readBlock -> INFO 006 Expect block, but got status: &{SERVICE_UNAVAILABLE}
2021-11-01 06:42:36.868 UTC [channelCmd] InitCmdFactory -> INFO 007 Endorser and orderer connections initialized
2021-11-01 06:42:37.070 UTC [cli.common] readBlock -> INFO 008 Expect block, but got status: &{SERVICE_UNAVAILABLE}
2021-11-01 06:42:37.073 UTC [channelCmd] InitCmdFactory -> INFO 009 Endorser and orderer connections initialized
2021-11-01 06:42:37.274 UTC [cli.common] readBlock -> INFO 00a Expect block, but got status: &{SERVICE_UNAVAILABLE}
2021-11-01 06:42:37.277 UTC [channelCmd] InitCmdFactory -> INFO 00b Endorser and orderer connections initialized
2021-11-01 06:42:37.479 UTC [cli.common] readBlock -> INFO 00c Received block: 0
bash-5.1# ls
channel-artifacts  crypto             mychannel.block
bash-5.1# exit
exit

将通道文件 mychannel.block 拷贝到cli2

[root@orderer twonodes]# docker cp cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/mychannel.block ./
[root@orderer twonodes]# docker cp mychannel.block cli2:/opt/gopath/src/github.com/hyperledger/fabric/peer/

2、加入通道

1、peer0节点加入通道

cli1容器操作

[root@orderer twonodes]# docker exec -it cli1 bash
bash-5.1# peer channel join -b mychannel.block
2021-11-01 06:45:10.236 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2021-11-01 06:45:10.253 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel

cli2容器操作

[root@orderer ~]# docker exec -it cli2 bash
bash-5.1# ls
channel-artifacts  crypto             mychannel.block
bash-5.1# peer channel join -b mychannel.block
2021-11-01 06:45:07.964 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2021-11-01 06:45:07.983 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
2、更新锚节点

cli1容器操作

bash-5.1# peer channel update -o orderer.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/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
2021-11-01 06:47:09.550 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2021-11-01 06:47:09.562 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update

cli2容器操作

bash-5.1# peer channel update -o orderer.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/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
2021-11-01 06:47:21.680 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2021-11-01 06:47:21.694 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update

五、安装调用智能合约

1、复制官方实例链码

[root@orderer twonodes]# cp ~/fabric-samples/chaincode/sacc/sacc.go ./chaincode/go/

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

[root@orderer twonodes]# 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-protos-go v0.0.0-20211006172752-14f4318ce71c
go: downloading github.com/hyperledger/fabric-chaincode-go v0.0.0-20210718160520-38d29fabecb9
go: found github.com/hyperledger/fabric-chaincode-go/shim in github.com/hyperledger/fabric-chaincode-go v0.0.0-20210718160520-38d29fabecb9
go: found github.com/hyperledger/fabric-protos-go/peer in github.com/hyperledger/fabric-protos-go v0.0.0-20211006172752-14f4318ce71c
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# peer lifecycle chaincode package sacc.tar.gz \--path github.com/hyperledger/fabric-cluster/chaincode/go/ \--label sacc_1
bash-5.1# ls
channel-artifacts  crypto             mychannel.block    sacc.tar.gz

3、将打包好的链码复制到cli2

[root@orderer twonodes]# docker cp cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/sacc.tar.gz ./
[root@orderer twonodes]# ls
chaincode          configtx.yaml  crypto-config.yaml   mychannel.block
channel-artifacts  crypto-config  docker-compose.yaml  sacc.tar.gz
[root@orderer twonodes]# docker cp sacc.tar.gz cli2:/opt/gopath/src/github.com/hyperledger/fabric/peer/

4、安装链码

cli1容器操作

[root@orderer twonodes]# docker exec -it cli1 bash
bash-5.1# peer lifecycle chaincode install sacc.tar.gz
2021-11-01 07:05:52.655 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nGsacc_1:0730c33ef4216613f9edf82e02d6d7dc02156d6426f38eda47b5b1a171c2f621\022\006sacc_1" >
2021-11-01 07:05:52.655 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: sacc_1:0730c33ef4216613f9edf82e02d6d7dc02156d6426f38eda47b5b1a171c2f621

cli2容器操作

[root@orderer twonodes]# docker exec -it cli2 bash
bash-5.1# peer lifecycle chaincode install sacc.tar.gz
2021-11-01 07:06:03.411 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nGsacc_1:0730c33ef4216613f9edf82e02d6d7dc02156d6426f38eda47b5b1a171c2f621\022\006sacc_1" >
2021-11-01 07:06:03.411 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: sacc_1:0730c33ef4216613f9edf82e02d6d7dc02156d6426f38eda47b5b1a171c2f621

5、批准链码

注:–package-id引用的链码为安装链码时的ID

cli1容器操作

bash-5.1# peer lifecycle chaincode approveformyorg --channelID mychannel --name sacc --version 1.0 --init-required --package-id sacc_1:0730c33ef4216613f9edf82e02d6d7dc02156d6426f38eda47b5b1a171c2f621 --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
2021-11-01 07:09:12.872 UTC [cli.lifecycle.chaincode] setOrdererClient -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
2021-11-01 07:09:14.889 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [d84eb0fcb3435f990f5d95352e17b07d7916791febc20167eefa1b1af1a527d8] committed with status (VALID) at peer0.org1.example.com:7051

cli2容器操作

bash-5.1# peer lifecycle chaincode approveformyorg --channelID mychannel --name sacc --version 1.0 --init-required --package-id sacc_1:0730c33ef4216613f9edf82e02d6d7dc02156d6426f38eda47b5b1a171c2f621 --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
2021-11-01 07:10:27.069 UTC [cli.lifecycle.chaincode] setOrdererClient -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
2021-11-01 07:10:29.086 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [d80d3a1196d785255258ed3b6f1df4714d757a332f415a2f757faa3c2eb75b66] committed with status (VALID) at peer0.org2.example.com:9051

6、查看链码是否就绪

cli1容器操作

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": true}
}

cli2容器操作

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": true}
}

7、提交链码

cli1容器或cli2容器皆可操作

bash-5.1# peer lifecycle chaincode commit -o orderer.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/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
2021-11-01 07:13:00.000 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [e19e76e392da5077b63cd794a54290992a2311fef97673466ddd13abbdf1bbb8] committed with status (VALID) at peer0.org1.example.com:7051
2021-11-01 07:13:00.000 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [e19e76e392da5077b63cd794a54290992a2311fef97673466ddd13abbdf1bbb8] committed with status (VALID) at peer0.org2.example.com:9051

8、链码初始化

bash-5.1# peer chaincode invoke -o orderer.example.com:7050 --isInit --ordererTLSHostnameOverride orderer.example.com --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 -C mychannel -n sacc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["a","bb"]}'
2021-11-01 07:15:09.712 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200

9、查询数据

cli1容器查询

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

cli2容器新增数据

[root@orderer ~]# docker exec -it cli2 bash
bash-5.1# peer chaincode invoke -o orderer.example.com:7050 --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 -C mychannel -n sacc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["set","a","cc"]}'
2021-11-01 07:16:22.338 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 payload:"cc"

查询数据

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

区块链——Hyperledger Fabric2.2单点搭建网络相关推荐

  1. 区块链——Hyperledger Fabric2.2多机搭建及区块链浏览器

    文章目录 一.搭建环境 1.设置网络 2.安装docker和docker-compose 3.安装golang环境 二.生成Fabric证书 1.编写证书文件 2.生成证书文件 3.复制证书文件到节点 ...

  2. 万字解析——区块链hyperledger fabric2.2部署实战教程

    导航 一.前言 二.hyperledger fabric介绍 三.测试网络示例 3.1 搭建开发环境 3.2 安装示例.二进制和 Docker 镜像 3.3 使用Fabric测试网络 3.4 使用认证 ...

  3. Hyperledger Fabric2.3 环境搭建及Fabric 测试网络使用

    一.安装ubuntu20 Download Ubuntu Desktop | Download | Ubuntu 二.安装环境 参考: Prerequisites - hyperledger-fabr ...

  4. 区块链 Hyperledger Composer 使用教程(环境搭建、项目开发 一)

    Hyperledger Composer使用教程 基本概念介绍 1. 欢迎来到Hyperledger作曲家 Hyperledger Composer是一个广泛的,开放的开发工具集和框架,可以使开发区块 ...

  5. 基于区块链/Hyperledger Fabric的商品交易溯源系统搭建步骤

    原项目链接:https://github.com/togettoyou/fabric-realty 此项目链接:https://gitee.com/real__cool/fabdeal 演示链接:ht ...

  6. 蚂蚁区块链第13课 如何搭建一个DAPP应用(以姓名年龄为例)

    1,摘要 本文介绍如何使用Cloud IDE完成name-age智能合约的编译,获取其ABI和二进制码信息. 接着,本文介绍基于EXPRESS框架搭建的前端页面,完成已部署智能合约的调用,完成了相关功 ...

  7. 区块链开发(五)搭建以太坊区块链浏览器

    经过前面文章介绍,已经搭建以太坊的区块链环境,但是没有一个界面能查看到区块链的块数等信息,不是很直观,本篇搭建以太坊区块链浏览器. 下载区块链浏览器代码 uiran@cuiran:~/ethereum ...

  8. 【区块链实战】什么是 P2P 网络,区块链和 P2P 网络有什么关系

    目录 一.简介 二.知识点 P2P 网络 区块链节点与 P2P 的关系 区块链节点功能分类 P2P 网络特征 三.什么是 P2P 网络,区块链式使用 P2P 网络做什么 1.P2P 网络概念 2.P2 ...

  9. 详解区块链项目如何做主体搭建?

    随着近年来区块链产业的不断发展,很多朋友也想进入这个领域分一杯羹,但新朋友往往不太了解区块链项目的运作模式.今天小编来为大家简单说下. 一.海外主体搭建,一些成功的区块链项目的主体会选择非营利的新加坡 ...

最新文章

  1. linux 如何以树形结构显示文件目录结构
  2. RNQOJ Jam的计数法
  3. ML之回归预测:利用FSR/RiR/BasisExpand/ Lasso/DT/RF/GB算法对红酒品质wine数据集实现红酒口感评分预测(实数值评分预测)
  4. 详解 Flink 容器化环境下的 OOM Killed
  5. 如何判断三极管好坏?
  6. mysql字符集变为gbk_MYSQL数据库默认latin1字符集转换为GBK或UTF8
  7. C语言变量的类型和存储位置
  8. 4、Linux的文件系统结构(目录树结构)
  9. 室内温湿度监测系统解决方案
  10. 马斯克:全力支持狗狗币主要持有者出售货币 持仓太集中是问题
  11. Spring Boot开发
  12. U-Boot工作过程
  13. 最好用的十六进制编辑器 010 Editor
  14. 前端 HTML5+CSS3基础知识一
  15. NFT数字藏品交易平台免费版源码-视觉猿CMS
  16. vue中Uncaught (in promise) TypeError: Object(...) is not a function报错
  17. Appium: Could not proxy command to the remote server. Original error: socket hang up
  18. 记录一次minerd肉鸡木马的排查思路
  19. 基于YII2.0中设置用户端不需要登陆的操作
  20. PHP语法基础4.1

热门文章

  1. LoRa SX1278通信代码开发学习
  2. uniapp 中使用不同字体
  3. 阿里IOT云飞燕平台的使用和感悟。
  4. 2021北航计算机考研人数,惊了!2021考研人数422万?!淘汰率或超过70%?8所高校报考人数汇总...
  5. Nginx安装及简介
  6. 解决谷歌浏览器跨域问题
  7. 我的世界服务器淬炼系统,我的世界淬炼指令 | 手游网游页游攻略大全
  8. html5超萌哈士奇,哈士奇,是一种让人又爱又恨,又拥有自己独特风格的雪橇犬...
  9. 四分之一管的直径是多少 气管管径对照
  10. 移动端APP测试总结(二)