温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Hyperledger Fabric如何构建第一个网络

发布时间:2021-12-06 14:21:34 来源:亿速云 阅读:178 作者:小新 栏目:互联网科技

小编给大家分享一下Hyperledger Fabric如何构建第一个网络,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

先决条件

操作系统

建议使用Ubuntu或者MacOS,不建议使用windows

Curl

下载最新版本的 curl 工具安装(如果尚未安装)

Docker和Docker Compose

Docker版本17.06.2-ce或更高版本。

Docker Compose版本1.14.0或更高版本。

以下命令检查已安装的Docker的版本:

docker --version

以下命令检查已安装的Docker Compose的版本:

docker-compose --version

Go

Hyperledger Fabric对其许多组件使用Go编程语言1.11.x

环境变量设置 GOPATH 为:

export GOPATH=$HOME/go

将 GOPATH/bin 添加到 PATH 中:

export PATH = $ PATH:$ GOPATH / bin

Node.js和NPM

利用针对Node.js的Hyperledger Fabric SDK开发Hyperledger Fabric的应用程序,则需要安装版本8.9.x的Node.js。

安装Node.js也会安装NPM,但建议命令升级该工具:

npm install npm@5.6.0 -g

Git

下载安装 Git

搭建第一个网络

1.克隆 hyperledger/fabric-samples

git clone https://github.com/hyperledger/fabric-samples.git

2.切换到 fabric-samples 文件夹下

cd fabric-samples

3.指定版本的Hyperledger Fabric平台特定二进制文件和配置文件分别安装到fabric-samples 存储库的根目录中bin文件夹和config文件夹,和下载指定版本的Hyperledger Fabric docker镜像

./scripts/bootstrap.sh [version] [ca version] [thirdparty_version]

4.构建第一个网络

   (1) 使用 first-network 样本

cd first-network

   (2) byfn.sh 脚本的帮助文本

Usage:
  byfn.sh <mode> [-c <channel name>] [-t <timeout>] [-d <delay>] [-f <docker-compose-file>] [-s <dbtype>] [-l <language>] [-i <imagetag>] [-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 v1.0.x to v1.1
    -c <channel name> - channel name to use (defaults to "mychannel")
    -t <timeout> - CLI timeout duration in seconds (defaults to 10)
    -d <delay> - delay duration in seconds (defaults to 3)
    -f <docker-compose-file> - specify which docker-compose file use (defaults to docker-compose-cli.yaml)
    -s <dbtype> - the database backend to use: goleveldb (default) or couchdb
    -l <language> - the chaincode language: golang (default), node or java
    -i <imagetag> - the tag to be used to launch the network (defaults to "latest")
    -v - verbose mode
  byfn.sh -h (print this message)Typically, one would first generate the required certificates andgenesis 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.1.0-alpha
        byfn.sh up -l node
        byfn.sh down -c mychannel
        byfn.sh upgrade -c mychannelTaking all defaults:
        byfn.sh generate
        byfn.sh up
        byfn.sh down

   (3) 生成msp证书密钥文件,简要说明,回车继续

./byfn.sh generate

      日志输出

Hyperledger Fabric如何构建第一个网络

   (4) 启动网络

./byfn.sh up

日志会看到从 start 

  Hyperledger Fabric如何构建第一个网络

到此,第一个联盟链搭建成功,是自动化脚本构建的,接着下一章会分析细节。

   (5) 终止网络,终止容器,删除加密材料和四个工件,并删除链上代码镜像

./byfn.sh down

看完了这篇文章,相信你对“Hyperledger Fabric如何构建第一个网络”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI