hyperledger fabric----cryptogen tools

cryptogen是一个生成认证证书(x509 certs)的工具,在官网提供的fabric-samples/bin目录下。

单独从github下载的fabric-samples里边没有bin目录,所以得在fabric-samples目录下使用附件的shell脚本文件下载或使用

curl -sSL https://goo.gl/Q3YRTi | bash

命令下载(如果提示网络连不上,就得);

Cryptogen源码在fabric/common/configtx/tool/configtxgen中,是一个独立的可执行程序。v1.0.0之后的版本,源码转到fabric/common/tools/cryptogen/中。

最有效的方法就是去这个地址直接下载想要的版本:https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/

 

另外还有个方法就是从源码编译,首先下载Fabric源码,然后将其放在“$GOPATH/src/github.com/hyperledger/fabric”目录下,cd到fabric目录下,使用(需要先安装好go-lang)

  1. cd $GOPATH/src/github.com/hyperledger/fabric

  2. make configtxgen

  3. # 如果出错:'ltdl.h' file not found

  4. sudo apt install libtool libltdl-dev

  5. # 然后再运行make

  6. make configtxgen

生成的文件目录在:

build/bin/cryptogen 

可以将bin目录拷贝到fabric-samples用来快速生成first-network网络配置

文件中包含了需要生成证书和公私钥的Orderer与peer配置(官网文档中提的是组织Organization的概念)。这些证书代表了身份,用来在实体间进行通信以及交易的时候进行签名与验证身份。配置文件内容如下:

#
# 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

里边主要包含Orderer组织的配置(包含1个Orderer)和peer组织的配置(包含2个peer组织org1,org2)。
Name:定义名称

Domain与Hostname:组合成为节点的名称,也是生成后的文件夹的名称。

Count:用来指定每个org下边所拥有的节点数,这里配置的是每个org各2个peer

Users:用来指定添加进节点的默认用户数

3 cryptogen命令说明

使用如下命令,生成证书文件:

cryptogen generate --config=./crypto-config.yaml
保存在crypto-config目录下
 

你可能感兴趣的:(fabric部分名词解释,部署fabric,fabric-sdk,区块链)