千家信息网

Hyperledger Fabric如何构建第一个网络

发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,小编给大家分享一下Hyperledger Fabric如何构建第一个网络,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!先决条件操作系统建议使用Ubuntu或者MacOS,不建议使用w
千家信息网最后更新 2025年12月02日Hyperledger Fabric如何构建第一个网络

小编给大家分享一下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  [-c ] [-t ] [-d ] [-f ] [-s ] [-l ] [-i ] [-v]     - 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 to use (defaults to "mychannel")    -t  - CLI timeout duration in seconds (defaults to 10)    -d  - delay duration in seconds (defaults to 3)    -f  - specify which docker-compose file use (defaults to docker-compose-cli.yaml)    -s  - the database backend to use: goleveldb (default) or couchdb    -l  - the chaincode language: golang (default), node or java    -i  - 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

日志输出

(4) 启动网络

./byfn.sh up

日志会看到从 start

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

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

./byfn.sh down

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

0