Fabric官方示例测试网络搭建

news/2024/7/7 14:43:48 标签: Hyperledger, 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_15">三、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 images

FABRIC_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-network

export 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.niftyadmin.cn/n/5145259.html

相关文章

软文推广没效果?媒介盒子分享软文优化技巧

虽然软文推广能够为企业实现品牌增值&#xff0c;但也有许多企业在推广过程中犯错导致宣传没有效果&#xff0c;今天媒介盒子就来和大家聊聊企业在进行软文推广中的常见问题以及优化技巧。 问题1&#xff1a;内容生硬无法自然融入品牌信息 这也是企业在软文写作中较常出现的问…

阿里云无影升级2.0 云电脑解决方案时代到来

10月31日&#xff0c;杭州云栖大会上&#xff0c;阿里云宣布无影全新升级2.0&#xff1a;从云电脑到云上解决方案&#xff0c;帮助中小企业更便捷地构建云上办公&#xff0c;并开放无影产品及解决方案能力&#xff0c;为生态合作伙伴提供企业云平台&#xff0c;帮助其打造定制化…

Spring 与 Spring Boot

什么是 Spring 可以理解 Spring 是一个框架。这个框架最早来源于在差不多的 20 年前的 2002 年。 在那个时候 Java 世界的开发还是以 EJB 为主&#xff0c;因为在这之前的大部分应用都会使用服务器客户端的应用模式。 其实这个模式在现在还是在使用的&#xff0c;例如 IBM 系统…

分析web应用防火墙与防火墙的功能与用途

随着互联网的普及和信息技术的发展&#xff0c;网络安全问题日益受到关注。防火墙和Web应用防火墙作为网络安全的重要组成部分&#xff0c;起着至关重要的作用。小编将对防火墙和Web应用防火墙的功能和用途进行比较分析&#xff0c;以帮助读者了解两者的区别和联系。 一、防火墙…

开发模型(瀑布、螺旋、scrum) 和 测试模型(V、W)、增量和迭代、敏捷(思想)及敏捷开发 scrum

&#x1f9f8;欢迎来到dream_ready的博客&#xff0c;&#x1f4dc;相信您对这篇博客也感兴趣o (ˉ▽ˉ&#xff1b;) 震惊&#xff01;测试人员对BUG的全方位解析&#xff0c;测试的执行和BUG管理&#xff01; 原来测试人员遇到BUG是这样返回给开发的&#xff01;什么是BUG&am…

阿里云多款ECS产品全面升级 性能最多提升40%

“阿里云始终围绕‘稳定、安全、性能、成本、弹性’的目标不断创新&#xff0c;为客户创造业务价值。”10月31日&#xff0c;杭州云栖大会上&#xff0c;阿里云弹性计算计算产品线负责人张献涛表示&#xff0c;通过持续的产品和技术创新&#xff0c;阿里云发布了HPC优化实例等多…

【代码随想录】算法训练计划09

第九天&#xff0c;今天是kmp算法&#xff0c; 复习字符串复习双指针&#xff0c;因为这两题可以跳过&#xff0c;就没写了&#xff0c;但是之前写过了&#xff0c;虽然不是用的kmp 不过我看卡哥的视频学了&#xff0c;懂了&#xff0c;但是脑想很模糊不靠谱&#xff0c;明天带…

>LINK : fatal error LNK1561和LINK : fatal error LNK1168:解决方法

>LINK : fatal error LNK1561和LINK : fatal error LNK1168:解决方法 >LINK : fatal error LNK1561和LINK : fatal error LNK1168:解决方法_fatal link error-CSDN博客 如果无法解决&#xff1a;只能试试在之前的项目中能否运行 这个错误提示表明在编译连接时&#xff…