温馨提示×

温馨提示×

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

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

HyperLedgr如何部署以及初始化网络

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

小编给大家分享一下HyperLedgr如何部署以及初始化网络,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

先决条件列表

  • 最新版本的 git

  • 最新版本的 curl

  • 任意版本的 wget

  • docker 和 docker-compose
    docker --version需要

  • Go 环境设置

  • Node.js 环境设置(包括 npm)

  • Python

安装示例、二进制和 Docker 映像

根据脚本下载源文件, 并存储到 bin 文件夹,最后该脚本将从 Docker Hub 下载最新的 Hyperledger Fabric Docker 镜像到本地的 Docker 注册表

测试安装环境正确性

开始之前

确认第二章节的安装实例工作成功

启动测试网络

cd fabric-samples/test-network
启用./network.sh -h查看测试网络搭建脚本的用法

1.Usage:
2.  network.sh <Mode> [Flags]
3.    <Mode>
4.      - 'up' - bring up fabric orderer and peer nodes. No channel is created
5.      - 'up createChannel' - bring up fabric network with one channel
6.      - 'createChannel' - create and join a channel after the network is created
7.      - 'deployCC' - deploy the fabcar chaincode on the channel
8.      - 'down' - clear the network with docker-compose down
9.      - 'restart' - restart the network
10.
11.    Flags:
12.    -ca <use CAs> -  create Certificate Authorities to generate the crypto material
13.    -c <channel name> - channel name to use (defaults to "mychannel")
14.    -s <dbtype> - the database backend to use: goleveldb (default) or couchdb
15.    -r <max retry> - CLI times out after certain number of attempts (defaults to 5)
16.    -d <delay> - delay duration in seconds (defaults to 3)
17.    -l <language> - the programming language of the chaincode to deploy: go (default), javascript, or java
18.    -v <version>  - chaincode version. Must be a round number, 1, 2, 3, etc
19.    -i <imagetag> - the tag to be used to launch the network (defaults to "latest")
20.    -verbose - verbose mode
21.  network.sh -h (print this message)
22.
23. Possible Mode and flags
24.  network.sh up -ca -c -r -d -s -i -verbose
25.  network.sh up createChannel -ca -c -r -d -s -i -verbose
26.  network.sh createChannel -c -r -d -verbose
27.  network.sh deployCC -l -v -r -d -verbose
28.
29. Taking all defaults:
30.    network.sh up
31.
32. Examples:
33.  network.sh up createChannel -ca -c mychannel -s couchdb -i 2.0.0-beta
34.  network.sh createChannel -c channelName
35.  network.sh deployCC -l javascript

当使用这个脚本network.sh up时将不产生任何人通道(只创建两个组织和一个排序节点)
docker ps -a命令会显示目前计算机上创建的几个节点 (3)

创建频道

使用脚本为 Org1 和 Org2 之间的事务创建 Fabric 通道,不同的通道有不同的分类帐本;./neteork.sh createChannel -c channelName

部署链码

./network.sh deployCC -l javascript
init 将会初始化智能合约内容,并调用链码将初始化的数据写入账本

  • 查询帐本所有信息
    Org1 的环境变量配置,查询 Org2 的环境配置需更改

1.# Environment variables for Org1
2.
3.export CORE_PEER_TLS_ENABLED=true
4.# Change Org2MSP
5.export CORE_PEER_LOCALMSPID="Org1MSP"
6.# change org2.example.com && peer0.org2.example.com
7.export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
8.# change org2.example.com && Admin@org1.example.com
9.export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
10.export CORE_PEER_ADDRESS=localhost:7051

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

  • 更改帐上资本
    peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls true --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n fabcar --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":"changeCarOwner","Args":["CAR9","Dave"]}'
    --peerAddresses localhost:7051表示 Org1 的地址
    --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt表示 Org1 的私钥地址
    --peerAddresses localhost:9051表示 Org2 的地址
    --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt表示 Org2 的私钥地址
    ‘命令太长了,还是使用 fabcar 里面的 sdk 编辑代码更改吧’

  • 关闭网络
    ./network.sh down该命令将停止并删除节点、链码容器、组织密钥、Docker 注册表中的链码镜像、通道、dock 卷。

使用证书颁发机构启动网络

Hyperledger 结构使用公钥基础结构(PKI),创建对等节点和排序节点之前必须创建部署和操作网络的所需的所有加密材料:节点,网络管理员,提交事务的用户都需要公共证书和私钥来验证身份。
默认情况使用Crptogen工具来创建证书和密钥, 创建过程如下

/Usr/fabric-samples/test-network/../bin/cryptogen
##########################################################
############ Create Org1 Identities ######################
##########################################################
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations
org1.example.com
+ res=0
+ set +x
##########################################################
############ Create Org2 Identities ######################
##########################################################
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations
org2.example.com
+ res=0
+ set +x
##########################################################
############ Create Orderer Org Identities ###############
##########################################################
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations
+ res=0
+ set +x

以上是“HyperLedgr如何部署以及初始化网络”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

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

AI