Hyperledger-fabric 手动操作第一次运行简单网络
Posted nykuvl
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hyperledger-fabric 手动操作第一次运行简单网络相关的知识,希望对你有一定的参考价值。
Hyperledger-fabric 手动操作第一次运行简单网络
尽量使用fabric-sample/first-network目录中的yaml文件进行配置,第一次自己写配置文件问题很多都不知道怎么解决
创建一个文件夹存放命令执行过程中生成的相关文件
mkdir mynetwork
# 创建存放证书的文件夹
cd mynetwork
# 使用模板生成证书
cryptogen showtemplate > crypto-config.yaml
#修改yaml文件中的内容使符合业务需求
cryptogen generate --config=crypto-config.yaml --output ./crypto-config
得到crypto-config文件夹
使用tree命令查看结构
nykuvl@ubuntu:~/go/src/github.com/hyperledger/my-network/fabricconfig$ tree -L 4 crypto-config
crypto-config
├── ordererOrganizations
│?? └── example.com
│?? ├── ca
│?? │?? ├── ca.example.com-cert.pem
│?? │?? └── fbb7775a7d8299d555d3d4d325f63d2e99f4b78914b78133dece9fad37691a9c_sk
│?? ├── msp
│?? │?? ├── admincerts
│?? │?? ├── cacerts
│?? │?? └── tlscacerts
│?? ├── orderers
│?? │?? └── orderer.example.com
│?? ├── tlsca
│?? │?? ├── 4553c56deea65409930e3eca2560547fba1685e03c568cbf5d915f6f11cec9c1_sk
│?? │?? └── tlsca.example.com-cert.pem
│?? └── users
│?? └── Admin@example.com
└── peerOrganizations
├── org1.example.com
│?? ├── ca
│?? │?? ├── 8016c152202a05f8085c9c7064c22896f15c9f7bd634892a69378e84a4e0bdac_sk
│?? │?? └── ca.org1.example.com-cert.pem
│?? ├── msp
│?? │?? ├── admincerts
│?? │?? ├── cacerts
│?? │?? └── tlscacerts
│?? ├── peers
│?? │?? ├── peer0.org1.example.com
│?? │?? └── peer1.org1.example.com
│?? ├── tlsca
│?? │?? ├── 5c7c18bc6a261b3b3144c9cee6f9a0f72c6c2899730e4c294609ca4d46a6f3be_sk
│?? │?? └── tlsca.org1.example.com-cert.pem
│?? └── users
│?? ├── Admin@org1.example.com
│?? ├── User1@org1.example.com
│?? ├── User2@org1.example.com
│?? └── User3@org1.example.com
└── org2.example.com
├── ca
│?? ├── ca.org2.example.com-cert.pem
│?? └── d6e0837afbc8f75c96a3bb4563d327d5829f358a3edb166d7314b033db2f0b26_sk
├── msp
│?? ├── admincerts
│?? ├── cacerts
│?? └── tlscacerts
├── peers
│?? ├── peer0.org2.example.com
│?? └── peer1.org2.example.com
├── tlsca
│?? ├── 8025007e0eb0f53e12d9d47ff29143b5c1d81684e0ff5dd999d67cd615081201_sk
│?? └── tlsca.org2.example.com-cert.pem
└── users
├── Admin@org2.example.com
├── User1@org2.example.com
└── User2@org2.example.com
42 directories, 12 files
将测试域名映射到本机的IP地址上
使用tree和grep命令获取example.com结尾的域名
nykuvl@ubuntu:~/go/src/github.com/hyperledger/my-network/fabricconfig$ tree -L 5 crypto-config | grep example.com
│?? └── example.com
│?? │?? ├── ca.example.com-cert.pem
│?? │?? │?? └── Admin@example.com-cert.pem
│?? │?? │?? └── ca.example.com-cert.pem
│?? │?? └── tlsca.example.com-cert.pem
│?? │?? └── orderer.example.com
│?? │?? └── tlsca.example.com-cert.pem
│?? └── Admin@example.com
├── org1.example.com
│?? │?? └── ca.org1.example.com-cert.pem
│?? │?? │?? └── Admin@org1.example.com-cert.pem
│?? │?? │?? └── ca.org1.example.com-cert.pem
│?? │?? └── tlsca.org1.example.com-cert.pem
│?? │?? ├── peer0.org1.example.com
│?? │?? └── peer1.org1.example.com
│?? │?? └── tlsca.org1.example.com-cert.pem
│?? ├── Admin@org1.example.com
│?? ├── User1@org1.example.com
│?? ├── User2@org1.example.com
│?? └── User3@org1.example.com
└── org2.example.com
│?? ├── ca.org2.example.com-cert.pem
│?? │?? └── Admin@org2.example.com-cert.pem
│?? │?? └── ca.org2.example.com-cert.pem
│?? └── tlsca.org2.example.com-cert.pem
│?? ├── peer0.org2.example.com
│?? └── peer1.org2.example.com
│?? └── tlsca.org2.example.com-cert.pem
├── Admin@org2.example.com
├── User1@org2.example.com
└── User2@org2.example.com
提取信息得到以下域名
orderer.example.com
peer0.org1.example.com
peer1.org1.example.com
peer0.org2.example.com
peer1.org2.example.com
设置hosts
vim /etc/hosts
# 添加以下内容,IP地址使用本地IP地址
192.168.139.134 orderer.example.com
192.168.139.134 peer0.org1.example.com
192.168.139.134 peer1.org1.example.com
192.168.139.134 peer0.org2.example.com
192.168.139.134 peer1.org2.example.com
设置完成后使用ping <域名>的方式测试配置是否正确
创建order目录存放orderer节点相关的文件
# 将fabric官方给的configtx配置样例复制到目录下
cp -r $GOPATH/src/github.com/hyperledger/fabric/sampleconfig/configtx.yaml $GOPATH/src/github.com/hyperledger/mynetwork/
sampleconfig/configtx.yaml代码及注释
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
---
################################################################################
#
# ORGANIZATIONS
#
# 本节定义可以在配置描述文件中引用的组织身份。
#
################################################################################
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.
#
# SampleOrg使用sampleconfig定义了一个MSP。 永远不要在生产中使用它,
# 而可以将其用作其他定义的模板。
- &SampleOrg
# Name is the key by which this org will be referenced in channel
# configuration transactions.
# Name can include alphanumeric characters as well as dots and dashes.
# Name是在channel配置transactions中引用此组织的键。
# Name可以包括字母数字字符以及点和破折号。
Name: SampleOrg
# ID is the key by which this org's MSP definition will be referenced.
# ID can include alphanumeric characters as well as dots and dashes.
# ID是引用此组织的MSP定义的键。ID可以包含字母数字字符以及点和破折号。
ID: SampleOrg
# MSPDir is the filesystem path which contains the MSP configuration.
# MSPDir是包含MSP配置的文件系统路径。
MSPDir: 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>
# 策略在配置树的此级别定义策略集。对于组织策略,其规范路径通常为
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
Policies: &SampleOrgPolicies
Readers:
Type: Signature
Rule: "OR('SampleOrg.member')"
# If your MSP is configured with the new NodeOUs, you might
# want to use a more specific rule like the following:
# Rule: "OR('SampleOrg.admin', 'SampleOrg.peer', 'SampleOrg.client')"
# 如果您的MSP配置了新的NodeOUs,则可能要使用更具体的规则,如下所示:
# 规则: "OR('SampleOrg.admin', 'SampleOrg.peer', 'SampleOrg.client')"
Writers:
Type: Signature
Rule: "OR('SampleOrg.member')"
# If your MSP is configured with the new NodeOUs, you might
# want to use a more specific rule like the following:
# Rule: "OR('SampleOrg.admin', 'SampleOrg.client')"
# 如果您的MSP配置了新的NodeOUs,则可能要使用更具体的规则,如下所示:
# 规则:"OR('SampleOrg.admin', 'SampleOrg.client')"
Admins:
Type: Signature
Rule: "OR('SampleOrg.admin')"
# OrdererEndpoints is a list of all orderers this org runs which clients
# and peers may to connect to to push transactions and receive blocks respectively.
# OrdererEndpoint是该组织运行的所有orderer的列表,
# 客户端和对等点可以分别连接到这些orderer以推送transactions和接收区块。
OrdererEndpoints:
- "127.0.0.1:7050"
# 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.
# AnchorPeers定义了可用于跨组织gossip通信的对等点的位置。
# 注意,此值仅在“应用程序”部分上下文中的“创世”块中编码。
AnchorPeers:
- Host: 127.0.0.1
Port: 7051
################################################################################
#
# 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.
# 本节定义fabric网络的功能。 从v1.1.0开始,这是一个新概念,不应在具有v1.0.x对等点和
# orderer的混合网络中使用。 功能定义了fabric二进制文件中必须存在的功能,该二进制文件
# 才能安全地参与fabric网络。 例如,如果添加了新的MSP类型,则较新的二进制文件可能会
# 识别并验证该类型的签名,而没有此支持的较旧的二进制文件将无法验证这些transactions。
# 这可能会导致不同版本的fabric二进制文件有不同的世界状态。 相反,为通道定义功能会通知
# 那些没有此功能的二进制文件,它们必须停止处理transactions,直到升级为止。
# 对于v1.0.x,如果定义了任何功能(包括关闭了所有功能的映射),则v1.0.x对等点将故意崩溃。
#
################################################################################
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.
# Note that setting a later Channel version capability to true will also
# implicitly set prior Channel version capabilities to true. There is no need
# to set each version capability to true (prior version capabilities remain
# in this sample only to provide the list of valid values).
# Channel capabilities同时适用于orderer和对等节点,并且必须同时受其支持。
# 将功能的值设置为true以使用它。
# 请注意,将更高版本的Channel版本功能设置为true也会隐式将先前的Channel版本功能设置为true。
# 无需将每个版本功能都设置为true(此示例中保留的先前版本功能仅是为了提供有效值的列表)。
Channel: &ChannelCapabilities
# V1.4.3 for Channel is a catchall flag for behavior which has been
# determined to be desired for all orderers and peers running at the v1.4.3
# level, but which would be incompatible with orderers and peers from
# prior releases.
# Prior to enabling V1.4.3 channel capabilities, ensure that all
# orderers and peers on a channel are at v1.4.3 or later.
# 用于Channel的V1.4.3是行为的综合标志,该行为已被确定为运行在V1.4.3级别的
# 所有orderer和对等节点所需的,但与以前版本中的orderer和对等节点不兼容。在启用V1.4.3
# Channel capabilities之前,请确保Channel上的所有orderer和对等节点都是V1.4.3或更高版本。
V1_4_3: true
# V1.3 for Channel enables the new non-backwards compatible
# features and fixes of fabric v1.3
V1_3: false
# V1.1 for Channel enables the new non-backwards compatible
# features and fixes of fabric v1.1
V1_1: false
# 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.
# Note that setting a later Orderer version capability to true will also
# implicitly set prior Orderer version capabilities to true. There is no need
# to set each version capability to true (prior version capabilities remain
# in this sample only to provide the list of valid values).
# Orderer capabilities仅适用于Orderer,并且可以与以前的发行版对等节点安全地使用。
# 将功能的值设置为true以使用它。 请注意,将更高的Orderer版本功能设置为true
# 也将隐式将先前的Orderer版本功能设置为true。 无需将每个版本功能都设置为true
# (此示例中保留的先前版本功能仅是为了提供有效值的列表)。
Orderer: &OrdererCapabilities
# V1.4.2 for Orderer is a catchall flag for behavior which has been
# determined to be desired for all orderers running at the v1.4.2
# level, but which would be incompatible with orderers from prior releases.
# Prior to enabling V1.4.2 orderer capabilities, ensure that all
# orderers on a channel are at v1.4.2 or later.
V1_4_2: true
# V1.1 for Orderer enables the new non-backwards compatible
# features and fixes of fabric v1.1
V1_1: false
# 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.
# Note that setting a later Application version capability to true will also
# implicitly set prior Application version capabilities to true. There is no need
# to set each version capability to true (prior version capabilities remain
# in this sample only to provide the list of valid values).
# Application capabilities仅适用于对等网络,并且可以与以前的发行版Orderer一起安全使用。
# 将功能的值设置为true以使用它。 请注意,将更高的应用程序版本功能设置为true
# 也将隐式将先前的应用程序版本功能设置为true。 无需将每个版本功能都设置为true
# (此示例中保留的先前版本功能仅是为了提供有效值的列表)。
Application: &ApplicationCapabilities
# V1.4.2 for Application enables the new non-backwards compatible
# features and fixes of fabric v1.4.2
V1_4_2: true
# V1.3 for Application enables the new non-backwards compatible
# features and fixes of fabric v1.3.
V1_3: false
# V1.2 for Application enables the new non-backwards compatible
# features and fixes of fabric v1.2 (note, this need not be set if
# later version capabilities are set)
V1_2: false
# V1.1 for Application enables the new non-backwards compatible
# features and fixes of fabric v1.1 (note, this need not be set if
# later version capabilities are set).
V1_1: false
################################################################################
#
# APPLICATION
#
# This section defines the values to encode into a config transaction or
# genesis block for application-related parameters.
# 本节定义了要编码为应用程序相关参数的配置tansaction或创世区块中的值。
#
################################################################################
Application: &ApplicationDefaults
ACLs: &ACLsDefault
# This section provides defaults for policies for various resources
# in the system. These "resources" could be functions on system chaincodes
# (e.g., "GetBlockByNumber" on the "qscc" system chaincode) or other resources
# (e.g.,who can receive Block events). This section does NOT specify the resource's
# definition or API, but just the ACL policy for it.
# 本节提供系统中各种资源的策略的默认设置。 这些“资源”可以是系统chaincode上的函数
# (例如,“ qscc”系统chaincode上的“ GetBlockByNumber”)或其他资源
# (例如,可以接收Block事件的资源)。 本节不指定资源的定义或API,
# 而仅指定它的ACL策略。
#
# User's can override these defaults with their own policy mapping by defining the
# mapping under ACLs in their channel definition
# 用户可以通过在其Channel定义中的ACL下定义映射来覆盖这些默认值,并使用自己的策略映射
#---Lifecycle System Chaincode (lscc) function to policy mapping for access control---#
# ACL policy for lscc's "getid" function
lscc/ChaincodeExists: /Channel/Application/Readers
# ACL policy for lscc's "getdepspec" function
lscc/GetDeploymentSpec: /Channel/Application/Readers
# ACL policy for lscc's "getccdata" function
lscc/GetChaincodeData: /Channel/Application/Readers
# ACL Policy for lscc's "getchaincodes" function
lscc/GetInstantiatedChaincodes: /Channel/Application/Readers
#---Query System Chaincode (qscc) function to policy mapping for access control---#
# ACL policy for qscc's "GetChainInfo" function
qscc/GetChainInfo: /Channel/Application/Readers
# ACL policy for qscc's "GetBlockByNumber" function
qscc/GetBlockByNumber: /Channel/Application/Readers
# ACL policy for qscc's "GetBlockByHash" function
qscc/GetBlockByHash: /Channel/Application/Readers
# ACL policy for qscc's "GetTransactionByID" function
qscc/GetTransactionByID: /Channel/Application/Readers
# ACL policy for qscc's "GetBlockByTxID" function
qscc/GetBlockByTxID: /Channel/Application/Readers
#---Configuration System Chaincode (cscc) function to policy mapping for access control---#
# ACL policy for cscc's "GetConfigBlock" function
cscc/GetConfigBlock: /Channel/Application/Readers
# ACL policy for cscc's "GetConfigTree" function
cscc/GetConfigTree: /Channel/Application/Readers
# ACL policy for cscc's "SimulateConfigTreeUpdate" function
cscc/SimulateConfigTreeUpdate: /Channel/Application/Readers
#---Miscellanesous peer function to policy mapping for access control---#
# ACL policy for invoking chaincodes on peer
peer/Propose: /Channel/Application/Writers
# ACL policy for chaincode to chaincode invocation
peer/ChaincodeToChaincode: /Channel/Application/Readers
#---Events resource to policy mapping for access control###---#
# ACL policy for sending block events
event/Block: /Channel/Application/Readers
# ACL policy for sending filtered block events
event/FilteredBlock: /Channel/Application/Readers
# Organizations lists the orgs participating on the application side of the
# network.
# Organizations列出参与网络应用程序端的组织。
Organizations:
# Policies defines the set of policies at this level of the config tree
# For Application policies, their canonical path is
# /Channel/Application/<PolicyName>
# 策略在配置树的此级别定义策略集。对于应用程序策略,其规范路径为
# /Channel/Application/<PolicyName>
Policies: &ApplicationDefaultPolicies
Readers:
Type: ImplicitMeta
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
# Capabilities describes the application level capabilities, see the
# dedicated Capabilities section elsewhere in this file for a full
# description
# Capabilities描述了应用程序级别的功能,有关完整说明,请参阅此文件其他地方的专用功能部分。
Capabilities:
<<: *ApplicationCapabilities
################################################################################
#
# ORDERER
#
# This section defines the values to encode into a config transaction or
# genesis block for orderer related parameters.
# 本节定义了要编码为与Orderer相关的参数的配置tansaction或生成块的值。
#
################################################################################
Orderer: &OrdererDefaults
# Orderer Type: The orderer implementation to start.
# Available types are "solo", "kafka" and "etcdraft".
OrdererType: solo
# Addresses used to be the list of orderer addresses that clients and peers
# could connect to. However, this does not allow clients to associate orderer
# addresses and orderer organizations which can be useful for things such
# as TLS validation. The preferred way to specify orderer addresses is now
# to include the OrdererEndpoints item in your org definition
# Addresses曾经是客户端和对等节点可以连接的Orderer地址的列表。
# 但是,这不允许客户端将Orderer地址和Orderer组织相关联,
# 这对于诸如TLS验证之类的事情很有用。
# 现在,指定Orderer地址的首选方法是在org definition中包括OrdererEndpoints项
Addresses:
# - 127.0.0.1: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.
# The orderer views messages opaquely, but typically, messages may
# be considered to be Fabric transactions. The 'batch' is the group
# of messages in the 'data' field of the block. Blocks will be a few kb
# larger than the batch size, when signatures, hashes, and other metadata
# is applied.
# 批处理大小:控制批处理到一个区块中的消息数。 orderer不透明地查看消息,
# 但是通常,消息可以被视为Fabric transactions。 “批”是该块的“数据”字段中的一组消息。
# 当应用签名,哈希和其他元数据时,区块将比批处理大小大几kb。
BatchSize:
# Max Message Count: The maximum number of messages to permit in a
# batch. No block will contain more than this number of messages.
# 最大消息计数:在一个批处理中消息的最大数目。 没有区块会包含比这个数量更多的消息。
MaxMessageCount: 500
# Absolute Max Bytes: The absolute maximum number of bytes allowed for
# the serialized messages in a batch. The maximum block size is this value
# plus the size of the associated metadata (usually a few KB depending
# upon the size of the signing identities). Any transaction larger than
# this value will be rejected by ordering. If the "kafka" OrdererType is
# selected, set 'message.max.bytes' and 'replica.fetch.max.bytes' on
# the Kafka brokers to a value that is larger than this one.
# 绝对最大字节数:批处理中序列化消息允许的绝对最大字节数。
# 最大块大小是该值加上相关元数据的大小(通常为几个KB,具体取决于签名标识的大小)。
# 任何大于此值的交易将被Orderer拒绝。 如果选择了“ kafka” OrdererType,
# 则将Kafka代理上的“ message.max.bytes”和“ replica.fetch.max.bytes”设置为大于此值的值。
AbsoluteMaxBytes: 10 MB
# Preferred Max Bytes: The preferred maximum number of bytes allowed
# for the serialized messages in a batch. Roughly, this field may be considered
# the best effort maximum size of a batch. A batch will fill with messages
# until this size is reached (or the max message count, or batch timeout is
# exceeded). If adding a new message to the batch would cause the batch to
# exceed the preferred max bytes, then the current batch is closed and written
# to a block, and a new batch containing the new message is created. If a
# message larger than the preferred max bytes is received, then its batch
# will contain only that message. Because messages may be larger than
# preferred max bytes (up to AbsoluteMaxBytes), some batches may exceed
# the preferred max bytes, but will always contain exactly one transaction.
# 首选最大字节数:批处理中序列化消息允许的首选最大字节数。
# 粗略地讲,此字段可被视为批处理中最大努力的最大大小。
# 批处理将填充消息,直到达到此大小(或最大消息数或超过批处理超时)为止。
# 如果将新消息添加到批处理将导致该批处理超出首选的最大字节数,
# 则将关闭当前批处理并将其写入一个块,并创建一个包含新消息的新批处理。
# 如果收到的消息大于首选的最大字节,则其批处理将仅包含该消息。
# 由于消息可能大于首选的最大字节(最大为AbsoluteMaxBytes),
# 因此某些批次可能会超出首选的最大字节,但始终只包含一个事务。
PreferredMaxBytes: 2 MB
# Max Channels is the maximum number of channels to allow on the ordering
# network. When set to 0, this implies no maximum number of channels.
# 最大Channel数是ordering网络上允许的最大Channel数。 设置为0时,表示没有最大通道数。
MaxChannels: 0
Kafka:
# Brokers: A list of Kafka brokers to which the orderer connects. Edit
# this list to identify the brokers of the ordering service.
# NOTE: Use IP:port notation.
# Brokers:Orderer连接的Kafka brokers列表。
# 编辑此列表以标识ordering服务的brokers。
# 注意:使用IP:端口符号。
Brokers:
- kafka0:9092
- kafka1:9092
- kafka2:9092
# EtcdRaft defines configuration which must be set when the "etcdraft"
# orderertype is chosen.
# EtcdRaft定义了选择“ etcdraft”Oderer类型时必须设置的配置。
EtcdRaft:
# The set of Raft replicas for this network. For the etcd/raft-based
# implementation, we expect every replica to also be an OSN. Therefore,
# a subset of the host:port items enumerated in this list should be
# replicated under the Orderer.Addresses key above.
# 此网络的Raft副本集。 对于基于etcd / raft的实现,我们希望每个副本也都是OSN。
# 因此,此列表中列举的host:port项的子集应复制在上方的Orderer.Addresses键下。
Consenters:
- Host: raft0.example.com
Port: 7050
ClientTLSCert: path/to/ClientTLSCert0
ServerTLSCert: path/to/ServerTLSCert0
- Host: raft1.example.com
Port: 7050
ClientTLSCert: path/to/ClientTLSCert1
ServerTLSCert: path/to/ServerTLSCert1
- Host: raft2.example.com
Port: 7050
ClientTLSCert: path/to/ClientTLSCert2
ServerTLSCert: path/to/ServerTLSCert2
# Options to be specified for all the etcd/raft nodes. The values here
# are the defaults for all new channels and can be modified on a
# per-channel basis via configuration updates.
# 为所有etcd / raft节点指定的选项。 此处的值是所有新通道的默认值,
# 可以通过配置更新在每个Channel的基础上进行修改。
Options:
# TickInterval is the time interval between two Node.Tick invocations.
# TickInterval是两次Node.Tick调用之间的时间间隔。
TickInterval: 500ms
# ElectionTick is the number of Node.Tick invocations that must pass
# between elections. That is, if a follower does not receive any
# message from the leader of current term before ElectionTick has
# elapsed, it will become candidate and start an election.
# ElectionTick must be greater than HeartbeatTick.
# ElectionTick是两次选举之间必须传递的Node.Tick调用数。
# 也就是说,如果在ElectionTick过去之前,follower没有收到当前任职领导者的任何消息,
# 它将成为候选人并开始选举。 ElectionTick必须大于HeartbeatTick。
ElectionTick: 10
# HeartbeatTick is the number of Node.Tick invocations that must
# pass between heartbeats. That is, a leader sends heartbeat
# messages to maintain its leadership every HeartbeatTick ticks.
# HeartbeatTick是必须在两次心跳之间传递的Node.Tick调用数。
# 也就是说,领导者发送心跳消息,以在每次HeartbeatTick滴答时保持其领导地位。
HeartbeatTick: 1
# MaxInflightBlocks limits the max number of in-flight append messages
# during optimistic replication phase.
# MaxInflightBlocks限制了乐观复制阶段的运行中附加消息的最大数量。
MaxInflightBlocks: 5
# SnapshotIntervalSize defines number of bytes per which a snapshot is taken
# SnapshotIntervalSize定义用于拍摄快照的字节数
SnapshotIntervalSize: 20 MB
# Organizations lists the orgs participating on the orderer side of the
# network.
Organizations:
# Policies defines the set of policies at this level of the config tree
# For Orderer policies, their canonical path is
# /Channel/Orderer/<PolicyName>
Policies:
Readers:
Type: ImplicitMeta
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
# BlockValidation specifies what signatures must be included in the block
# from the orderer for the peer to validate it.
BlockValidation:
Type: ImplicitMeta
Rule: "ANY Writers"
# Capabilities describes the orderer level capabilities, see the
# dedicated Capabilities section elsewhere in this file for a full
# description
Capabilities:
<<: *OrdererCapabilities
################################################################################
#
# CHANNEL
#
# This section defines the values to encode into a config transaction or
# genesis block for channel related parameters.
# 本节定义了要编码为Channel相关参数的配置transaction或创世区块的值。
#
################################################################################
Channel: &ChannelDefaults
# Policies defines the set of policies at this level of the config tree
# For Channel policies, their canonical path is
# /Channel/<PolicyName>
Policies:
# Who may invoke the 'Deliver' API
Readers:
Type: ImplicitMeta
Rule: "ANY Readers"
# Who may invoke the 'Broadcast' API
Writers:
Type: ImplicitMeta
Rule: "ANY Writers"
# By default, who may modify elements at this config level
Admins:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
# Capabilities describes the channel level capabilities, see the
# dedicated Capabilities section elsewhere in this file for a full
# description
Capabilities:
<<: *ChannelCapabilities
################################################################################
#
# PROFILES
#
# Different configuration profiles may be encoded here to be specified as
# parameters to the configtxgen tool. The profiles which specify consortiums
# are to be used for generating the orderer genesis block. With the correct
# consortium members defined in the orderer genesis block, channel creation
# requests may be generated with only the org member names and a consortium
# name.
# 此处可以对不同的配置配置文件进行编码,以指定为configtxgen工具的参数。
# 指定联盟的配置文件将用于生成有序的创始块。 在Orderer创世块中定义了正确的联盟成员后,
# 可以仅使用组织成员名称和联盟名称来生成Channel创建请求。
#
################################################################################
Profiles:
# SampleSingleMSPSolo defines a configuration which uses the Solo orderer,
# and contains a single MSP definition (the MSP sampleconfig).
# The Consortium SampleConsortium has only a single member, SampleOrg.
# SampleSingleMSPSolo定义使用Solo排序器的配置,并且包含单个MSP定义(MSP sampleconfig)。
# 联盟SampleConsortium只有一个成员SampleOrg。
SampleSingleMSPSolo:
<<: *ChannelDefaults
Orderer:
<<: *OrdererDefaults
Organizations:
- *SampleOrg
Consortiums:
SampleConsortium:
Organizations:
- *SampleOrg
# SampleSingleMSPKafka defines a configuration that differs from the
# SampleSingleMSPSolo one only in that it uses the Kafka-based orderer.
SampleSingleMSPKafka:
<<: *ChannelDefaults
Orderer:
<<: *OrdererDefaults
OrdererType: kafka
Organizations:
- *SampleOrg
Consortiums:
SampleConsortium:
Organizations:
- *SampleOrg
# SampleInsecureSolo defines a configuration which uses the Solo orderer,
# contains no MSP definitions, and allows all transactions and channel
# creation requests for the consortium SampleConsortium.
SampleInsecureSolo:
<<: *ChannelDefaults
Orderer:
<<: *OrdererDefaults
Consortiums:
SampleConsortium:
Organizations:
# SampleInsecureKafka defines a configuration that differs from the
# SampleInsecureSolo one only in that it uses the Kafka-based orderer.
SampleInsecureKafka:
<<: *ChannelDefaults
Orderer:
OrdererType: kafka
<<: *OrdererDefaults
Consortiums:
SampleConsortium:
Organizations:
# SampleDevModeSolo defines a configuration which uses the Solo orderer,
# contains the sample MSP as both orderer and consortium member, and
# requires only basic membership for admin privileges. It also defines
# an Application on the ordering system channel, which should usually
# be avoided.
SampleDevModeSolo:
<<: *ChannelDefaults
Orderer:
<<: *OrdererDefaults
Organizations:
- <<: *SampleOrg
Policies:
<<: *SampleOrgPolicies
Admins:
Type: Signature
Rule: "OR('SampleOrg.member')"
Application:
<<: *ApplicationDefaults
Organizations:
- <<: *SampleOrg
Policies:
<<: *SampleOrgPolicies
Admins:
Type: Signature
Rule: "OR('SampleOrg.member')"
Consortiums:
SampleConsortium:
Organizations:
- <<: *SampleOrg
Policies:
<<: *SampleOrgPolicies
Admins:
Type: Signature
Rule: "OR('SampleOrg.member')"
# SampleDevModeKafka defines a configuration that differs from the
# SampleDevModeSolo one only in that it uses the Kafka-based orderer.
SampleDevModeKafka:
<<: *ChannelDefaults
Orderer:
<<: *OrdererDefaults
OrdererType: kafka
Organizations:
- <<: *SampleOrg
Policies:
<<: *SampleOrgPolicies
Admins:
Type: Signature
Rule: "OR('SampleOrg.member')"
Application:
<<: *ApplicationDefaults
Organizations:
- <<: *SampleOrg
Policies:
<<: *SampleOrgPolicies
Admins:
Type: Signature
Rule: "OR('SampleOrg.member')"
Consortiums:
SampleConsortium:
Organizations:
- <<: *SampleOrg
Policies:
<<: *SampleOrgPolicies
Admins:
Type: Signature
Rule: "OR('SampleOrg.member')"
# SampleSingleMSPChannel defines a channel with only the sample org as a
# member. It is designed to be used in conjunction with SampleSingleMSPSolo
# and SampleSingleMSPKafka orderer profiles. Note, for channel creation
# profiles, only the 'Application' section and consortium # name are
# considered.
# SampleSingleMSPChannel定义仅以sample org作为成员的Channel。
# 它旨在与SampleSingleMSPSolo和SampleSingleMSPKafka orderer程序配置文件一起使用。
# 请注意,对于Channel创建配置文件,仅考虑“Application”部分和联盟编号名称。
SampleSingleMSPChannel:
Consortium: SampleConsortium
Application:
<<: *ApplicationDefaults
Organizations:
- *SampleOrg
# SampleDevModeEtcdRaft defines a configuration that differs from the
# SampleDevModeSolo one only in that it uses the etcd/raft-based orderer.
SampleDevModeEtcdRaft:
<<: *ChannelDefaults
Orderer:
<<: *OrdererDefaults
OrdererType: etcdraft
Organizations:
- <<: *SampleOrg
Policies:
<<: *SampleOrgPolicies
Admins:
Type: Signature
Rule: "OR('SampleOrg.member')"
Application:
<<: *ApplicationDefaults
Organizations:
- <<: *SampleOrg
Policies:
<<: *SampleOrgPolicies
Admins:
Type: Signature
Rule: "OR('SampleOrg.member')"
Consortiums:
SampleConsortium:
Organizations:
- <<: *SampleOrg
Policies:
<<: *SampleOrgPolicies
Admins:
Type: Signature
Rule: "OR('SampleOrg.member')"
中文详解: http://blog.hub wiz.com/2019/04/24/fabric-configtx-yaml-cn/
简单配置一个configtx.yaml和创建创世区块
Organizations:
- &OrdererOrg
Name: OrdererOrg
ID: OrdererMSP
MSPDir: /home/nykuvl/go/src/github.com/hyperledger/mynetwork/crypto-config/ordererOrganizations/example.com/msp
Policies:
Readers:
Type: Signature
Rule: "OR('OrdererMSP.member')"
Writers:
Type: Signature
Rule: "OR('OrdererMSP.member')"
Admins:
Type: Signature
Rule: "OR('OrdererMSP.admin')"
- &Org1
Name: Org1MSP
ID: Org1MSP
MSPDir: /home/nykuvl/go/src/github.com/hyperledger/mynetwork/crypto-config/peerOrganizations/org1.example.com/msp
Policies:
Readers:
Type: Signature
Rule: "OR('Org1MSP.admin', 'Org1MSP.peer', 'Org1MSP.client')"
Writers:
Type: Signature
Rule: "OR('Org1MSP.admin', 'Org1MSP.client')"
Admins:
Type: Signature
Rule: "OR('Org1MSP.admin')"
AnchorPeers:
- Host: peer0.org1.example.com
Port: 7051
- &Org2
Name: Org2MSP
ID: Org2MSP
MSPDir: /home/nykuvl/go/src/github.com/hyperledger/mynetwork/crypto-config/peerOrganizations/org2.example.com/msp
Policies:
Readers:
Type: Signature
Rule: "OR('Org2MSP.admin', 'Org2MSP.peer', 'Org2MSP.client')"
Writers:
Type: Signature
Rule: "OR('Org2MSP.admin', 'Org2MSP.client')"
Admins:
Type: Signature
Rule: "OR('Org2MSP.admin')"
AnchorPeers:
- Host: peer0.org2.example.com
Port: 9051
Capabilities:
Channel: &ChannelCapabilities
V1_4_3: true
V1_3: false
V1_1: false
Orderer: &OrdererCapabilities
V1_4_2: true
V1_1: false
Application: &ApplicationCapabilities
V1_4_2: true
V1_3: false
V1_2: false
V1_1: false
Application: &ApplicationDefaults
Organizations:
Policies:
Readers:
Type: ImplicitMeta
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
Capabilities:
<<: *ApplicationCapabilities
Orderer: &OrdererDefaults
OrdererType: solo
Addresses:
- orderer.example.com:7050
BatchTimeout: 2s
BatchSize:
MaxMessageCount: 10
AbsoluteMaxBytes: 99 MB
PreferredMaxBytes: 512 KB
Kafka:
Brokers:
- 127.0.0.1:9092
EtcdRaft:
Consenters:
- Host: orderer.example.com
Port: 7050
ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
- Host: orderer2.example.com
Port: 7050
ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
- Host: orderer3.example.com
Port: 7050
ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt
ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt
- Host: orderer4.example.com
Port: 7050
ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt
ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt
- Host: orderer5.example.com
Port: 7050
ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt
ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt
Organizations:
Policies:
Readers:
Type: ImplicitMeta
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
BlockValidation:
Type: ImplicitMeta
Rule: "ANY Writers"
Channel: &ChannelDefaults
Policies:
Readers:
Type: ImplicitMeta
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
Capabilities:
<<: *ChannelCapabilities
Profiles:
TwoOrgsOrdererGenesis:
<<: *ChannelDefaults
Orderer:
<<: *OrdererDefaults
Organizations:
- *OrdererOrg
Capabilities:
<<: *OrdererCapabilities
Consortiums:
SampleConsortium:
Organizations:
- *Org1
- *Org2
TwoOrgsChannel:
Consortium: SampleConsortium
<<: *ChannelDefaults
Application:
<<: *ApplicationDefaults
Organizations:
- *Org1
- *Org2
Capabilities:
<<: *ApplicationCapabilities
SampleDevModeKafka:
<<: *ChannelDefaults
Capabilities:
<<: *ChannelCapabilities
Orderer:
<<: *OrdererDefaults
OrdererType: kafka
Kafka:
Brokers:
- kafka.example.com:9092
Organizations:
- *OrdererOrg
Capabilities:
<<: *OrdererCapabilities
Application:
<<: *ApplicationDefaults
Organizations:
- <<: *OrdererOrg
Consortiums:
SampleConsortium:
Organizations:
- *Org1
- *Org2
SampleMultiNodeEtcdRaft:
<<: *ChannelDefaults
Capabilities:
<<: *ChannelCapabilities
Orderer:
<<: *OrdererDefaults
OrdererType: etcdraft
EtcdRaft:
Consenters:
- Host: orderer.example.com
Port: 7050
ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
- Host: orderer2.example.com
Port: 7050
ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
- Host: orderer3.example.com
Port: 7050
ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt
ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt
- Host: orderer4.example.com
Port: 7050
ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt
ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt
- Host: orderer5.example.com
Port: 7050
ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt
ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt
Addresses:
- orderer.example.com:7050
- orderer2.example.com:7050
- orderer3.example.com:7050
- orderer4.example.com:7050
- orderer5.example.com:7050
Organizations:
- *OrdererOrg
Capabilities:
<<: *OrdererCapabilities
Application:
<<: *ApplicationDefaults
Organizations:
- <<: *OrdererOrg
Consortiums:
SampleConsortium:
Organizations:
- *Org1
- *Org2
接着进入orderer目录生成创世块文件
export FABRIC_CFG_PATH=$PWD
mkdir channel-artifacts
configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
创建Channel
export CHANNEL_NAME=mychannel
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
在Channel上定义Org1和Org2的anchor peer
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
这时候channel-artifacts目录下应该有四个文件
channel-artifacts/
├── channel.tx
├── genesis.block
├── Org1MSPanchors.tx
└── Org2MSPanchors.tx0 directories, 4 files
如果文件目录设置与yaml脚本不匹配要手动进行修改
# 引入环境变量
export IMAGE_TAG=1.4
export COMPOSE_PROJECT_NAME=net
cp -r ../fabric-samples/first-network/base/ ./
cp ../fabric-samples/first-network/docker-compose-cli.yaml ./
# 执行docker-compose
CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=600 docker-compose -f docker-compose-cli.yaml up -d
Tip: 当启动后发现docker ps只有cli一个容器开启,使用docker logs查看其他容器停止的原因
启动docker之前先把chaincode目录从fabric-sample里拿出来,之后安装链码会用到
# 先进入hyperledger的目录下,再执行以下命令
cp -r fabric-sample/chiancode ./
创建和加入通道
进入docker cli容器
docker exec -it cli bash
export CHANNEL_NAME=mychannel
# the channel.tx file is mounted in the channel-artifacts directory within your CLI container
# as a result, we pass the full path for the file
# we also pass the path for the orderer ca-cert in order to verify the TLS handshake
# be sure to replace the $CHANNEL_NAME variable appropriately
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
清空docker环境解决各种permission denied
出现问题无法创建通道,执行清空docker环境的命令,然后再从头开始
# STOP AND DELETE THE DOCKER CONTAINERS
docker ps -aq | xargs -n 1 docker stop
docker ps -aq | xargs -n 1 docker rm -v
# DELETE THE OLD DOCKER VOLUMES
docker volume prune
# DELETE OLD DOCKER NETWORKS (OPTIONAL: seems to restart fine without)
docker network prune
# DELETE SCRIPT-CREATED FILES
rm -rf channel-artifacts/*.block channel-artifacts/*.tx crypto-config
rm -f docker-compose-e2e.yaml
# VERIFY RESULTS
docker ps -a
docker volume ls
ls -l
加入通道
通过改变环境变量来操作不同节点
# peer0.org1.example.com 加入通道
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
export CORE_PEER_LOCALMSPID="Org1MSP"
export 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
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
peer channel join -b mychannel.block
# peer1.org1.example.com 加入通道
# 注意:端口号要根据docker-compose的文件来设置,通过docker ps查看开放的端口号
export CORE_PEER_ADDRESS=peer1.org1.example.com:8051
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
peer channel join -b mychannel.block
# peer0.org2.example.com 加入通道
export CORE_PEER_ADDRESS=peer0.org2.example.com:9051
export CORE_PEER_LOCALMSPID="Org2MSP"
export 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
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
peer channel join -b mychannel.block
# peer1.org2.example.com 加入通道
export CORE_PEER_ADDRESS=peer1.org2.example.com:10051
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
peer channel join -b mychannel.block
安装和实例化链码
安装链码时有教程写是使用网络资源进行安装,我自己在装的时候是不起作用的,要手动指定chaincode的目录
# peer0.org1.example.com 安装链码
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
export CORE_PEER_LOCALMSPID="Org1MSP"
export 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
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
# chaincode的目录要规划好,根据自行设置的目录结构更改命令
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go
# peer1.org1.example.com 安装链码
# 注意:端口号要根据docker-compose的文件来设置,通过docker ps查看开放的端口号
export CORE_PEER_ADDRESS=peer1.org1.example.com:8051
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go
# peer0.org2.example.com 安装链码
export CORE_PEER_ADDRESS=peer0.org2.example.com:9051
export CORE_PEER_LOCALMSPID="Org2MSP"
export 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
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go
# peer1.org2.example.com 安装链码
export CORE_PEER_ADDRESS=peer1.org2.example.com:10051
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go
实例化链码
# 先切换到peer0.org1.example.com节点
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
export CORE_PEER_LOCALMSPID="Org1MSP"
export 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
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --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 $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
查询操作
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
调用
从a账户转10到b账户
peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --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 $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'
以上是关于Hyperledger-fabric 手动操作第一次运行简单网络的主要内容,如果未能解决你的问题,请参考以下文章
fabric:在ubuntu20.04上部署Hyperledger-fabric最新2.3.2环境
Hyperledger-fabric入门学习记录Fabcar实例
markdown 如何在多个server.md中部署hyperledger-fabric