Hyperledger Fabric 入門 first-network 搭建


1.准備環境:

安裝git、docker、curl、go

[root@test_vonedao_83 fabric]# git --version
git version 1.8.3.1
[root@test_vonedao_83 fabric]# curl --version
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.36 zlib/1.2.7 libidn/1.28 libssh2/1.4.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp 
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets 
[root@test_vonedao_83 fabric]# go version
go version go1.12.1 linux/amd64
[root@test_vonedao_83 fabric]# docker -v
Docker version 1.13.1, build 7f2769b/1.13.1

[root@test_vonedao_83 fabric]# pwd
/opt/fabric
[root@test_vonedao_83 fabric]# cd /opt/fabric/
[root@test_vonedao_83 fabric]# pwd
/opt/fabric

 2. 一般入門,先git拉源碼(可以不拉源碼,直接下載bootstrap.sh)

 # git clone "https://gerrit.hyperledger.org/r/fabric"

克隆下了后,目錄大概就是這些內容,暫時各個文件內容,還不太清楚。我們先去scripts里面看看:

引導腳本bootstrap.sh:會自動進行fabric相關鏡像的下載 ,並且還會把fabric samples庫下載下來(時間可能有點久,如果出現長時間停頓,可以嘗試重新執行腳本)

執行腳本:

 

下載的fabric-samples,我們看下有什么:

 

在目錄fabric-samples/bin下面的這些命令,可以用

export FABRIC_HOME=/你定義的路徑/fabric/scripts/fabric-samples/

export PATH=$FABRIC_HOME/bin:$PATH 

加入到系統環境變量中。方便可以直接使用:

 模塊的命令介紹:

configtxgen 區塊和交易生成模塊

 
         

[root@dev_vonedao_95 first-network]# configtxgen --help
Usage of configtxgen:
-asOrg    所屬組織
-channelCreateTxBaseProfile string
Specifies a profile to consider as the orderer system channel current state to allow modification of non-application parameters during channel create tx generation. Only valid in conjuction with 'outputCreateChannelTx'.
-channelID  channel名稱,若沒有則系統提供一個默認值
-configPath 配置路徑?
-inspectBlock 打印特定區塊文件中的配置內容
-inspectChannelCreateTx 打印創建通道的交易配置文件
-outputAnchorPeersUpdate 更新channel配置信息
-outputBlock 輸出區塊文件的路徑
-outputCreateChannelTx 標示輸出創始塊文件
-printOrg 以JSON格式打印組織的定義。(用於手動將組織添加到channel)
-profile 配置文件的節點
-version 版本信息

configtxlator 區塊和交易解析模塊。把區塊鏈的二進制文件轉化成JSON格式的文件,便於我們閱讀和理解。

 
         

[root@dev_vonedao_95 first-network]# configtxlator --help
usage: configtxlator [<flags>] <command> [<args> ...]

 
         

Utility for generating Hyperledger Fabric channel configurations

 
         

Flags:
--help Show context-sensitive help (also try --help-long and --help-man).

 
         

Commands:
help [<command>...]
Show help.

 
         

start [<flags>]   啟動configtxlator REST服務器

 
         

proto_encode --type=TYPE [<flags>]
Converts a JSON document to protobuf.

 
         

proto_decode --type=TYPE [<flags>]
Converts a proto message to JSON.

 
         

compute_update --channel_id=CHANNEL_ID [<flags>]
Takes two marshaled common.Config messages and computes the config update which transitions between the two.

 
         

version
Show version information

 

cryptogen 組織和證書生成模塊

 
         

[root@dev_vonedao_95 first-network]# cryptogen --help
usage: cryptogen [<flags>] <command> [<args> ...]

 
         

Utility for generating Hyperledger Fabric key material

 
         

Flags:
--help Show context-sensitive help (also try --help-long and --help-man).

 
         

Commands:
help [<command>...]
Show help.

 
         

generate [<flags>]
Generate key material

 
         

showtemplate
Show the default configuration template

 
         

version
Show version information

 
         

extend [<flags>]
Extend existing network

 

orderer 交易打包、排序模塊

[root@dev_vonedao_95 first-network]# orderer --help
usage: orderer [<flags>] <command> [<args> ...]

Hyperledger Fabric orderer node

Flags:
--help Show context-sensitive help (also try --help-long and --help-man).

Commands:
help [<command>...]
Show help.

start*
Start the orderer node

version
Show version information

benchmark
Run orderer in benchmark mode

peer 主節點模塊,負責存儲區塊鏈數據,運行維護鏈碼


[root@dev_vonedao_95 first-network]# orderer --help
usage: orderer [<flags>] <command> [<args> ...]

Hyperledger Fabric orderer node

Flags:
--help Show context-sensitive help (also try --help-long and --help-man).

Commands:
help [<command>...]
Show help.

start*
Start the orderer node

version
Show version information

benchmark
Run orderer in benchmark mode

discover   發現服務的客戶端

[root@dev_vonedao_95 first-network]# discover --help
usage: discover [<flags>] <command> [<args> ...]

Command line client for fabric discovery service

Flags:
  --help                   Show context-sensitive help (also try --help-long and --help-man).
  --configFile=CONFIGFILE  Specifies the config file to load the configuration from
  --peerTLSCA=PEERTLSCA    Sets the TLS CA certificate file path that verifies the TLS peer's certificate
  --tlsCert=TLSCERT        (Optional) Sets the client TLS certificate file path that is used when the peer enforces client authentication
  --tlsKey=TLSKEY          (Optional) Sets the client TLS key file path that is used when the peer enforces client authentication
  --userKey=USERKEY        Sets the user's key file path that is used to sign messages sent to the peer
  --userCert=USERCERT      Sets the user's certificate file path that is used to authenticate the messages sent to the peer
  --MSP=MSP                Sets the MSP ID of the user, which represents the CA(s) that issued its user certificate

Commands:
  help [<command>...]
    Show help.

  peers [<flags>]
    Discover peers

  config [<flags>]
    Discover channel config

  endorsers [<flags>]
    Discover chaincode endorsers

  saveConfig
    Save the config passed by flags into the file specified by --configFile

 

fabric-ca-client   證書頒發客戶端

[root@dev_vonedao_95 first-network]# fabric-ca-client --help
Hyperledger Fabric Certificate Authority Client

Usage:
  fabric-ca-client [command]

Available Commands:
  affiliation Manage affiliations
  certificate Manage certificates
  enroll      Enroll an identity
  gencrl      Generate a CRL
  gencsr      Generate a CSR
  getcainfo   Get CA certificate chain and Idemix public key
  identity    Manage identities
  reenroll    Reenroll an identity
  register    Register an identity
  revoke      Revoke an identity
  version     Prints Fabric CA Client version

Flags:
      --caname string                  Name of CA
      --csr.cn string                  The common name field of the certificate signing request
      --csr.hosts stringSlice          A list of comma-separated host names in a certificate signing request
      --csr.keyrequest.algo string     Specify key algorithm
      --csr.keyrequest.size int        Specify key size
      --csr.names stringSlice          A list of comma-separated CSR names of the form <name>=<value> (e.g. C=CA,O=Org1)
      --csr.serialnumber string        The serial number in a certificate signing request
      --enrollment.attrs stringSlice   A list of comma-separated attribute requests of the form <name>[:opt] (e.g. foo,bar:opt)
      --enrollment.label string        Label to use in HSM operations
      --enrollment.profile string      Name of the signing profile to use in issuing the certificate
      --enrollment.type string         The type of enrollment request: 'x509' or 'idemix' (default "x509")
  -H, --home string                    Client's home directory (default "/root/.fabric-ca-client")
      --id.affiliation string          The identity's affiliation
      --id.attrs stringSlice           A list of comma-separated attributes of the form <name>=<value> (e.g. foo=foo1,bar=bar1)
      --id.maxenrollments int          The maximum number of times the secret can be reused to enroll (default CA's Max Enrollment)
      --id.name string                 Unique name of the identity
      --id.secret string               The enrollment secret for the identity being registered
      --id.type string                 Type of identity being registered (e.g. 'peer, app, user') (default "client")
      --loglevel string                Set logging level (info, warning, debug, error, fatal, critical)
  -M, --mspdir string                  Membership Service Provider directory (default "msp")
  -m, --myhost string                  Hostname to include in the certificate signing request during enrollment (default "dev_vonedao_95")
  -a, --revoke.aki string              AKI (Authority Key Identifier) of the certificate to be revoked
  -e, --revoke.name string             Identity whose certificates should be revoked
  -r, --revoke.reason string           Reason for revocation
  -s, --revoke.serial string           Serial number of the certificate to be revoked
      --tls.certfiles stringSlice      A list of comma-separated PEM-encoded trusted certificate files (e.g. root1.pem,root2.pem)
      --tls.client.certfile string     PEM-encoded certificate file when mutual authenticate is enabled
      --tls.client.keyfile string      PEM-encoded key file when mutual authentication is enabled
  -u, --url string                     URL of fabric-ca-server (default "http://localhost:7054")

Use "fabric-ca-client [command] --help" for more information about a command.

 

idemixgen  用來根據 MSP 為身份混合器創建配置文件

[root@dev_vonedao_95 first-network]# idemixgen --help
usage: idemixgen [<flags>] <command> [<args> ...]

Utility for generating key material to be used with the Identity Mixer MSP in Hyperledger Fabric

Flags:
  -h, --help                    Show context-sensitive help (also try --help-long and --help-man).
      --output="idemix-config"  The output directory in which to place artifacts

Commands:
  help [<command>...]
    Show help.

  ca-keygen
    Generate CA key material

  signerconfig [<flags>]
    Generate a default signer for this Idemix MSP

  version
    Show version information

 學習下byfn.sh腳本的相關命令和參數:

[root@dev_vonedao_95 first-network]# sh byfn.sh 
Usage: 
  byfn.sh <mode> [-c <channel name>] [-t <timeout>] [-d <delay>] [-f <docker-compose-file>] [-s <dbtype>] [-l <language>] [-o <consensus-type>] [-i <imagetag>] [-a] [-n] [-v]
    <mode> - one of 'up', 'down', 'restart', 'generate' or 'upgrade'
      - 'up' - bring up the network with docker-compose up    啟動網絡
      - 'down' - clear the network with docker-compose down   關閉網絡
      - 'restart' - restart the network   重啟網絡
      - 'generate' - generate required certificates and genesis block    生成證書和創世區塊
      - 'upgrade'  - upgrade the network from version 1.3.x to 1.4.0     將網絡從1.3升級到1.4
    -c <channel name> - channel name to use (defaults to "mychannel")    設置channel名稱,默認mychannel
    -t <timeout> - CLI timeout duration in seconds (defaults to 10)      CLI超時時間,默認10秒
    -d <delay> - delay duration in seconds (defaults to 3)               延時時間,默認3秒  
    -f <docker-compose-file> - specify which docker-compose file use (defaults to docker-compose-cli.yaml)   指定docker-compose文件,默認docker-compose-cli.yaml
-s <dbtype> - the database backend to use: goleveldb (default) or couchdb  指定使用的數據庫,默認是goleveldb或者couchdb

-l <language> - the chaincode language: golang (default) or node 指定鏈碼使用的語言,默認是golang或者node

-o <consensus-type> - the consensus-type of the ordering service: solo (default), kafka, or etcdraft 指定排序服務使用的共識機制。默認是solo,kafka或者etcdraft

-i <imagetag> - the tag to be used to launch the network (defaults to "latest") 用於啟動網絡的鏡像版本。默認是latest

-a - launch certificate authorities (no certificate authorities are launched by default) 啟動證書頒發機構,默認沒有證書頒發機構

-n - do not deploy chaincode (abstore chaincode is deployed by default) 不部署鏈碼(默認情況下部署Absore鏈碼)

-v - verbose mode 版本信息
byfn.
sh -h (print this message)

Typically, one would first generate the required certificates and
genesis block, then bring up the network. e.g.:

 
         

byfn.sh generate -c mychannel
byfn.sh up -c mychannel -s couchdb
byfn.sh up -c mychannel -s couchdb -i 1.4.0
byfn.sh up -l node
byfn.sh down -c mychannel
byfn.sh upgrade -c mychannel

 
         

Taking all defaults:
byfn.sh generate
byfn.sh up
byfn.sh down

 

 

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM