千家信息网

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

发表于:2024-10-25 作者:千家信息网编辑
千家信息网最后更新 2024年10月25日,小编给大家分享一下HyperLedgr如何部署以及初始化网络,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!先决条件列表最新
千家信息网最后更新 2024年10月25日HyperLedgr如何部署以及初始化网络

小编给大家分享一下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  [Flags]3.    4.      - 'up' - bring up fabric orderer and peer nodes. No channel is created5.      - 'up createChannel' - bring up fabric network with one channel6.      - 'createChannel' - create and join a channel after the network is created7.      - 'deployCC' - deploy the fabcar chaincode on the channel8.      - 'down' - clear the network with docker-compose down9.      - 'restart' - restart the network10.11.    Flags:12.    -ca  -  create Certificate Authorities to generate the crypto material13.    -c  - channel name to use (defaults to "mychannel")14.    -s  - the database backend to use: goleveldb (default) or couchdb15.    -r  - CLI times out after certain number of attempts (defaults to 5)16.    -d  - delay duration in seconds (defaults to 3)17.    -l  - the programming language of the chaincode to deploy: go (default), javascript, or java18.    -v   - chaincode version. Must be a round number, 1, 2, 3, etc19.    -i  - the tag to be used to launch the network (defaults to "latest")20.    -verbose - verbose mode21.  network.sh -h (print this message)22.23. Possible Mode and flags24.  network.sh up -ca -c -r -d -s -i -verbose25.  network.sh up createChannel -ca -c -r -d -s -i -verbose26.  network.sh createChannel -c -r -d -verbose27.  network.sh deployCC -l -v -r -d -verbose28.29. Taking all defaults:30.    network.sh up31.32. Examples:33.  network.sh up createChannel -ca -c mychannel -s couchdb -i 2.0.0-beta34.  network.sh createChannel -c channelName35.  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 Org12.3.export CORE_PEER_TLS_ENABLED=true4.# Change Org2MSP5.export CORE_PEER_LOCALMSPID="Org1MSP"6.# change org2.example.com && peer0.org2.example.com7.export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt8.# change org2.example.com && Admin@org1.example.com9.export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp10.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=organizationsorg1.example.com+ res=0+ set +x###################################################################### Create Org2 Identities ################################################################################+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizationsorg2.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如何部署以及初始化网络"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

0