当前位置: 首页 > news >正文

Fabric官方示例测试网络搭建

目录

  • 一、参考文档
  • 二、环境依赖
  • 三、Fabric源码安装
    • 3.1、创建链目录
    • 3.2、下载源码
    • 3.3、修改安装脚本
    • 3.4、开始安装
      • 3.4.1、执行安装脚本
      • 3.4.2、手动下载ca和二进制配置包
  • 四、启动测试网络
  • 五、使用测试网络
    • 5.1、创建应用通道
    • 5.2、部署链码
    • 5.3、发送交易
  • 六、关闭测试网络

一、参考文档

  • hyperledger超级账本官方文档地址:https://hyperledger-fabric.readthedocs.io/en/release-2.2/

  • hyperledger中文文档:https://hyperledgercn.github.io/hyperledgerDocs/

二、环境依赖

  • ubuntu 20.04.1
  • go version go1.16.3 linux/amd64
  • git version 2.25.1
  • docker 20.10.17
  • docker-compose 1.29.2

三、Fabric源码安装

3.1、创建链目录

mkdir -p $GOPATH/src/github.com/hyperledger

3.2、下载源码

cd $GOPATH/src/github.com/hyperledger
git clone https://gitee.com/hyperledger/fabric.git -b v2.2.0

3.3、修改安装脚本

vim $GOPATH/src/github.com/hyperledger/fabric/scripts/bootstrap.sh
  1. https://github.com/hyperledger/fabric-samples.git 修改为 https://gitee.com/hyperledger/fabric-samples.git
  2. 注释 pullBinaries

3.4、开始安装

3.4.1、执行安装脚本

cd $GOPATH/src/github.com/hyperledger/fabric/scripts/
./bootstrap.sh

若报错:

Pull Hyperledger Fabric docker imagesFABRIC_IMAGES: peer orderer ccenv tools nodeenv baseos javaenv
===> Pulling fabric Images
====> hyperledger/fabric-peer:2.2.0
Error response from daemon: error parsing HTTP 408 response body: invalid character '<' looking for beginning of value: "<html><body><h1>408 Request Time-out</h1>\nYour browser didn't send a complete request in time.\n</body></html>\n"
Error response from daemon: No such image: hyperledger/fabric-peer:2.2.0
Error response from daemon: No such image: hyperledger/fabric-peer:2.2.0
====> hyperledger/fabric-orderer:2.2.0
2.2.0: Pulling from hyperledger/fabric-orderer
error parsing HTTP 408 response body: invalid character '<' looking for beginning of value: "<html><body><h1>408 Request Time-out</h1>\nYour browser didn't send a complete request in time.\n</body></html>\n"
Error response from daemon: No such image: hyperledger/fabric-orderer:2.2.0
Error response from daemon: No such image: hyperledger/fabric-orderer:2.2.0
====> hyperledger/fabric-ccenv:2.2.0

则尝试调整/etc/docker/daemon.json

{"registry-mirrors": ["http://hub-mirror.c.163.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn"]
}
sudo systemctl daemon-reload
sudo systemctl restart docker

3.4.2、手动下载ca和二进制配置包

下载bootstrap.sh中指定的对应版本ca和二进制配置的包:

# VERSION=2.2.0
wget https://github.com/hyperledger/fabric/releases/download/v2.2.0/hyperledger-fabric-linux-amd64-2.2.0.tar.gz
# CA_VERSION=1.4.7
wget https://github.com/hyperledger/fabric-ca/releases/download/v1.4.7/hyperledger-fabric-ca-linux-amd64-1.4.7.tar.gz

复制到fabric-samples目录:

tar -zxvf hyperledger-fabric-linux-amd64-2.2.0.tar.gz
tar -zxvf hyperledger-fabric-ca-linux-amd64-1.4.7.tar.gz
cp -r bin fabric-samples/
cp -r config fabric-samples/

四、启动测试网络

cd $GOPATH/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network
# cryptogen启动方式
./network.sh up
# ca-server启动方式
# ./network.sh up -ca

日志:

Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' with crypto from 'cryptogen'
LOCAL_VERSION=2.2.0
DOCKER_IMAGE_VERSION=2.2.0
/usr/local/software/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/../bin/cryptogen
Generating certificates using cryptogen tool
Creating Org1 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations
org1.example.com
+ res=0
Creating Org2 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations
org2.example.com
+ res=0
Creating Orderer Org Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations
+ res=0
Generating CCP files for Org1 and Org2
/usr/local/software/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/../bin/configtxgen
Generating Orderer Genesis block
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
2023-11-01 16:23:18.229 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2023-11-01 16:23:18.244 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft
2023-11-01 16:23:18.244 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216 
2023-11-01 16:23:18.244 CST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /usr/local/software/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/configtx/configtx.yaml
2023-11-01 16:23:18.246 CST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block
2023-11-01 16:23:18.247 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Writing genesis block
+ res=0
Creating network "fabric_test" with the default driver
Creating volume "docker_orderer.example.com" with default driver
Creating volume "docker_peer0.org1.example.com" with default driver
Creating volume "docker_peer0.org2.example.com" with default driver
Creating peer0.org1.example.com ... done
Creating orderer.example.com    ... done
Creating peer0.org2.example.com ... done
Creating cli                    ... done
CONTAINER ID   IMAGE                               COMMAND             CREATED         STATUS                  PORTS                                                                                                NAMES
677082ab5dc4   hyperledger/fabric-tools:latest     "/bin/bash"         1 second ago    Up Less than a second                                                                                                        cli
9e567df423f2   hyperledger/fabric-peer:latest      "peer node start"   3 seconds ago   Up 1 second             0.0.0.0:9051->9051/tcp, :::9051->9051/tcp, 7051/tcp, 0.0.0.0:19051->19051/tcp, :::19051->19051/tcp   peer0.org2.example.com
30248ff4a8c7   hyperledger/fabric-orderer:latest   "orderer"           3 seconds ago   Up Less than a second   0.0.0.0:7050->7050/tcp, :::7050->7050/tcp, 0.0.0.0:17050->17050/tcp, :::17050->17050/tcp             orderer.example.com
884783874fcc   hyperledger/fabric-peer:latest      "peer node start"   3 seconds ago   Up 1 second             0.0.0.0:7051->7051/tcp, :::7051->7051/tcp, 0.0.0.0:17051->17051/tcp, :::17051->17051/tcp             peer0.org1.example.com

看到docker的2个peer节点容器、1个orderer节点容器和客户端tools容器都正常运行,测试网络启动成功。

五、使用测试网络

5.1、创建应用通道

使用network.sh脚本在org1和org2之间创建通道并加入他们的对等节点,执行以下命令创建一个通道:

./network.sh createChannel -c mychannel

5.2、部署链码

./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-java -ccl java

5.3、发送交易

配置环境变量:

cd $GOPATH/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-networkexport PATH=${PWD}/../bin:$PATH
# 该目录下包含peer节点的core.yaml
export FABRIC_CFG_PATH=$PWD/../config/# 客户端连接peer0
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051

发交易,初始化资产(调用链码的初始化方法InitLedger):

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"InitLedger","Args":[]}'

查询初始化后的资产(调用链码的GetAllAssets方法):

peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'

六、关闭测试网络

./network.sh down
http://www.lryc.cn/news/215402.html

相关文章:

  • ubuntu20.04 conda pack 打包虚拟环境,直接将其用到其他终端
  • 云原生-AWS EC2使用、安全性及国内厂商对比
  • 【Proteus仿真】【Arduino单片机】简易电子琴
  • QT5.15.2 for Android 真机调试
  • Mysql my.cnf配置文件参数详解
  • linux下构建rocketmq-dashboard多架构镜像——筑梦之路
  • git,ssh,sourcetree代码管理
  • Jenkins中解决下载maven包巨慢的问题
  • Redis(11)| 持久化AOF和RDB
  • ZYNQ实验---IQ调制实现SSB PART2
  • 机器学习-特征工程
  • 大数据技术之集群数据迁移
  • CF1265E Beautiful Mirrors
  • 软件测试/测试开发丨利用ChatGPT自动生成架构图
  • Java学习笔记(六)——面向对象编程(基础)
  • 0基础学习PyFlink——个数滚动窗口(Tumbling Count Windows)
  • 车载终端构筑智慧工厂:无人配送车的高效物流体系
  • 插件_日期_lunar-calendar公历农历转换
  • 【FreeRTOS】【STM32】08 FreeRTOS 消息队列
  • 【计算机组成原理】CPU的工作原理
  • 部署ELK
  • 纯前端实现图片验证码
  • #django基本常识01#
  • 什么是物流RPA?物流RPA解决什么问题?物流RPA实施难点在哪里?
  • 乐鑫工程部署过程记录
  • to 后接ing形式的情况
  • 我做云原生的那几年
  • @EventListener注解使用说明
  • 算法通关村第五关-白银挑战实现队列
  • 协力共创智能未来:乐鑫 ESP RainMaker 云方案线下研讨会圆满落幕