【fabric实战指南二】Fabric v1.0 部署过程原理详解

区块链兄弟社区,区块链技术专业问答先行者,中国区块链技术爱好者聚集地

作者:吴寿鹤

来源:区块链兄弟

原文链接:http://www.blockchainbrother.com/article/18

著权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

编译fabric tools

我们会编译以下几个工具:

  • github.com/hyperledger/fabric/common/configtx/tool/configtxgen
  • github.com/hyperledger/fabric/common/tools/cryptogen
  • github.com/hyperledger/fabric/common/tools/configtxlator
  • github.com/hyperledger/fabric/peer

以上每个工具都需要读取一个yaml文件配置,在配置文件中我们指明网络的拓扑结构,证书地址等。

cd $GOPATH/src/github.com/hyperledger/fabric
make release

ls -rtl release/linux-amd64/bin

-rwxrwxr-x 1 shouhewu shouhewu 15124356 Jul 17 13:58 configtxgen
-rwxrwxr-x 1 shouhewu shouhewu 7315638 Jul 17 13:58 cryptogen
-rwxrwxr-x 1 shouhewu shouhewu 16141847 Jul 17 13:58 configtxlator
-rwxrwxr-x 1 shouhewu shouhewu 22949903 Jul 17 13:58 peer
-rwxrwxr-x 1 shouhewu shouhewu 19942880 Jul 17 13:59 orderer
-rwxrwxr-x 1 shouhewu shouhewu 774 Jul 17 13:59 get-docker-images.sh
-rwxrwxr-x 1 shouhewu shouhewu 458 Jul 17 13:59 get-byfn.sh

Cryptogen Tool(cryptogen)

我们会使用crptogen tool 为网络中的节点,用户生成密码证书(x509 certs)。

怎么运行的?

Cryptogen 读取 crypto-config.yaml 文件,yaml文件中包含网络拓扑结构,这个yaml文件可以帮我们为每个组织和组织中的成员生成证书库。每个组织分配一个根证书(ca-cert),这个根证书会绑定一些peers和orders到这个组织。fabric中的交易和通信都会被一个参与者的私钥(keystore)签名,并会被公钥(signcerts)验证.yaml配置文件中有一个"count"变量,我们用这个变量表示一个组织中会有多少个节点。在我们的文档的例子中每个组织会有两个节点。

crypto-config.yaml :

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

# ---------------------------------------------------------------------------
# "OrdererOrgs" - Definition of organizations managing orderer nodes
# ---------------------------------------------------------------------------
    OrdererOrgs:
# ---------------------------------------------------------------------------
# Orderer
# ---------------------------------------------------------------------------
    - Name: Orderer
Domain: example.com
# ---------------------------------------------------------------------------
# "Specs" - See PeerOrgs below for complete description
# ---------------------------------------------------------------------------
    Specs:
- Hostname: orderer
# ---------------------------------------------------------------------------
# "PeerOrgs" - Definition of organizations managing peer nodes
# ---------------------------------------------------------------------------
    PeerOrgs:
# ---------------------------------------------------------------------------
# Org1
# ---------------------------------------------------------------------------
    - Name: Org1
Domain: org1.example.com
# ---------------------------------------------------------------------------
# "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.
# ---------------------------------------------------------------------------
# Specs:
    #   - Hostname: foo # implicitly "foo.org1.example.com"
#     CommonName: foo27.org5.example.com # overrides Hostname-based FQDN set above
#   - Hostname: bar
#   - Hostname: baz
# ---------------------------------------------------------------------------
# "Template"
# ---------------------------------------------------------------------------
# Allows for the definition of 1 or more hosts that are created sequentially
# from a template. By default, this looks like "peer%d" from 0 to Count-1.
# You may override the number of nodes (Count), the starting index (Start)
# or the template used to construct the name (Hostname).
#
# Note: Template and Specs are not mutually exclusive.  You may define both
# sections and the aggregate nodes will be created for you.  Take care with
# name collisions
# ---------------------------------------------------------------------------
    Template:
Count: 2
# Start: 5
# Hostname: {{.Prefix}}{{.Index}} # default
# ---------------------------------------------------------------------------
# "Users"
# ---------------------------------------------------------------------------
# Count: The number of user accounts _in addition_ to Admin
# ---------------------------------------------------------------------------
    Users:
Count: 1
# ---------------------------------------------------------------------------
# Org2: See "Org1" for full specification
# ---------------------------------------------------------------------------
    - Name: Org2
Domain: org2.example.com
Template:
Count: 2
Users:
Count: 1

执行结果

执行完cryptogen命令后,生成的证书会放在 crypto-config 文件夹中 。

ll crypto-config
drwxr-xr-x 4 shouhewu shouhewu 4096 Jul 17 15:15 ./
drwxr-xr-x 9 shouhewu shouhewu 4096 Jul 17 15:18 ../
drwxr-xr-x 3 shouhewu shouhewu 4096 Jul 17 15:15 ordererOrganizations/
drwxr-xr-x 4 shouhewu shouhewu 4096 Jul 17 15:15 peerOrganizations/

Configuration Transaction Generator(configtxgen)

configtxgen tool 用来生成四个artifacts:orderer bootstrap block,fabric channel configuration transaction,two anchor peer transactions(每个组织一个)

orderer block 是ordering service 的创世区块,在channel创建的时候channel transaction 文件会广播给orderer。anchor peer transaction表示每个组织在channel中的anchor 节点。

怎么工作的?

configtxgen会读取 configtx.yaml 配置文件。这个yaml 文件包含网络的定义,网络中有三个成员 一个orderer(OrdererOrg),两个peer(Org1,Org2),yaml文件中还包含一个由两个组织构成的联盟(SampleConsortium)。 在yaml文件最上方 “Profile”段落中,有两个header,一个是orderer genesis block - TwoOrgsOrdererGenesis ,另一个是channel - TwoOrgsChannel。这两个header十分重要,我们创建artifacts是我们会把他们作为参数传入。yaml文件中还包含另外两个东西:1.每个peer 组中的anchor peer(peer0.org1.example.com & peer0.org2.example.com) 。2. 每个成员的MSP 目录位置,它允许我们把每个组织的根证书会存在orderer genesis block中。

configtx.yaml

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

    TwoOrgsOrdererGenesis:
        Orderer:
            <<: *OrdererDefaults
Organizations:
    - *OrdererOrg
Consortiums:
    SampleConsortium:
        Organizations:
            - *Org1
            - *Org2
TwoOrgsChannel:
Consortium: SampleConsortium
Application:
    <<: *ApplicationDefaults
Organizations:
    - *Org1
    - *Org2

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

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

# ID to load the MSP definition as
ID: OrdererMSP

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

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

# ID to load the MSP definition as
ID: Org1MSP

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

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

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

# ID to load the MSP definition as
ID: Org2MSP

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

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

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

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

Addresses:
    - orderer.example.com:7050

# Batch Timeout: The amount of time to wait before creating a batch
BatchTimeout: 2s

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

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

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

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

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

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

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

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

执行结果

configtxgen 会把每个成员的证书打包,输出一个orderer genesis block 和三个channel transaction artifacts。

ll channel-artifacts/

drwxr-xr-x 2 shouhewu shouhewu 4096 Jul 17 15:15 ./
drwxr-xr-x 9 shouhewu shouhewu 4096 Jul 17 15:18 ../
-rw-r--r-- 1 shouhewu shouhewu 369 Jul 17 15:21 channel.tx
-rw-r--r-- 1 shouhewu shouhewu 9076 Jul 17 15:21 genesis.block
-rw-rw-r-- 1 shouhewu shouhewu 0 Jul 17 15:14 .gitkeep
-rw-r--r-- 1 shouhewu shouhewu 250 Jul 17 15:21 Org1MSPanchors.tx
-rw-r--r-- 1 shouhewu shouhewu 250 Jul 17 15:21 Org2MSPanchors.tx

文章发布只为分享区块链技术内容,版权归原作者所有,观点仅代表作者本人,绝不代表区块链兄弟赞同其观点或证实其描述

原文地址:https://www.cnblogs.com/blockchainbrother/p/8882367.html

时间: 2024-08-26 13:14:19

【fabric实战指南二】Fabric v1.0 部署过程原理详解的相关文章

Hyperledger Fabric 实战(十二): Fabric 源码本地调试

借助开发网络调试 fabric 源码本地调试 准备工作 IDE Goland Go 1.9.7 fabric-samples 模块 chaincode-docker-devmode fabric 源码 步骤 添加本地域名 127.0.0.1 peer 127.0.0.1 orderer 用 ide 打开 $GOPATH 下的fabric源码目录 在源码目录下添加 dev-network 把 sampleconfig 下的所有文件复制到 dev-network 修改 core.yaml 中 fil

Redis笔记系列(二)——Redis安装部署与维护详解

本文介绍Redis2.8的安装部署和维护方法. Redis在linux上的安装 步骤1: 首先从官网下在redis正式版的压缩包redis-2.8.19.tar.gz http://download.redis.io/releases/redis-2.8.19.tar.gz 步骤2:编译源程序: tar zxvf redis-2.8.19.tar.gz [[email protected] Downloads]$ tar zxvf redis-2.8.19.tar.gz [[email prot

Tomcat部署(原理详解与部署实操)

Tomcat部署 一.前言 ? 之前的文章讲述的是web中两大服务器软件:Apache和Nginx,在这,对此我们先做一个简单的小结. 1.Apache和Nginx的特点与性能 ? Apache支持支持模块多,性能稳定,Apache本身是静态解析,适合静态HTML.图片等,但可以通过扩展脚本.模块等支持动态页面等.但是其配置相对复杂,自身不支持动态页面. ? Nginx,轻量级的HTTP服务器,是一个高性能的HTTP和反向代理服务器,同时也是一个IMAP/POP3/SMTP 代理服务器.其特点是

[CXF REST标准实战系列] 二、Spring4.0 整合 CXF3.0,实现测试接口(转)

转自:[CXF REST标准实战系列] 二.Spring4.0 整合 CXF3.0,实现测试接口 文章Points: 1.介绍RESTful架构风格 2.Spring配置CXF 3.三层初设计,实现WebService接口层 4.撰写HTTPClient 客户端,并实现简单调用 介绍RESTful架构风格 REST是REST之父Roy Thomas创造的,当时提出来了REST的6个特点:客户端-服务器的.无状态的.可缓存的.统一接口.分层系统和按需编码.其具有跨语言和跨平台的优势. REST是一

Android群英传笔记——第十二章:Android5.X 新特性详解,Material Design UI的新体验

Android群英传笔记--第十二章:Android5.X 新特性详解,Material Design UI的新体验 第十一章为什么不写,因为我很早之前就已经写过了,有需要的可以去看 Android高效率编码-第三方SDK详解系列(二)--Bmob后端云开发,实现登录注册,更改资料,修改密码,邮箱验证,上传,下载,推送消息,缩略图加载等功能 这一章很多,但是很有趣,也是这书的最后一章知识点了,我现在还在考虑要不要写这个拼图和2048的案例,在此之前,我们先来玩玩Android5.X的新特性吧!

Redis实战和核心原理详解(5)使用Spring Session和Redis解决分布式Session跨域共享问题

Redis实战和核心原理详解(6)使用Spring Session和Redis解决分布式Session跨域共享问题 前言 对于分布式使用Nginx+Tomcat实现负载均衡,最常用的均衡算法有IP_Hash.轮训.根据权重.随机等.不管对于哪一种负载均衡算法,由于Nginx对不同的请求分发到某一个Tomcat,Tomcat在运行的时候分别是不同的容器里,因此会出现session不同步或者丢失的问题. 实际上实现Session共享的方案很多,其中一种常用的就是使用Tomcat.Jetty等服务器提

JSPatch实现原理详解&lt;二&gt;

本文转载至 http://blog.cnbang.net/tech/2855/ 距离上次写的<JSPatch实现原理详解>有一个月的时间,在这段时间里 JSPatch 在不断地完善和改进,代码已经有很多变化,有一些修改值得写一下,作为上一篇的补充. Special Struct 先说下 _objc_msgForward,在上一篇提到为了让替换的方法走 forwardInvocation,把它指向一个不存在的 IMP: class_getMethodImplementation(cls, @se

redis服务部署及配置详解

Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富.有字符串,链表,集合和有序集合.支持在服务器端计算集合的并,交和补集(difference)等,还支持多种排序功能.所以Redis也可以被看成是一个数据结构服务器. Redis的所有数据都是保存在内存中,然后不定期的通过异步方式保存到磁盘上(这称为"半持久化模式"):也可以把每一次数据变化都写入到一个append only file(aof)里面(这称为"全

【Big Data - Hadoop - MapReduce】通过腾讯shuffle部署对shuffle过程进行详解

摘要: 通过腾讯shuffle部署对shuffle过程进行详解 摘要:腾讯分布式数据仓库基于开源软件Hadoop和Hive进行构建,TDW计算引擎包括两部分:MapReduce和Spark,两者内部都包含了一个重要的过程—Shuffle.本文对Shuffle过程进行解析,并对两个计算引擎的Shuffle过程进行比较. 腾讯分布式数据仓库(Tencent distributed Data Warehouse, 简称TDW)基于开源软件Hadoop和Hive进行构建,并且根据公司数据量大.计算复杂等