HyperLedger(3)多主机部署Fabric1.0
来源:互联网 发布:圣剑英雄传 源码 编辑:程序博客网 时间:2024/05/22 12:59
多主机部署Fabric1.0
- 本文以fabric下examples/e2e_cli为例,并使用docker-compose-e2e.yaml来启动Fabric网络。
- 在三台主机上进行部署,分别orderer service、org1(包括2个peer,1个ca)、org2(包括2个peer,1个ca)。
准备工作
运行Fabric节点需要依赖以下工具:
- Docker: 用于管理Fabric镜像以及运行peer和orderer等组件。
- Docker-compose:用于配置Fabric容器
- Fabric源码:提供了用于生成证书(cryptogen)和配置channel(configtxgen)的工具和e2e_cli示例。
- Go语言开发环境:源码的工具编译依赖于Go语言。
在主机1利用cryptogen和configtxgen工具生成证书和配置channel等相关文件
命令分别如下:
#生成证书cryptogen generate --config=./crypto-config.yaml#生成配置channel所需文件configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.blockconfigtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannelconfigtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSPconfigtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
将步骤2生成的文件拷贝到主机2和主机3保持所有主机的这些文件相同。
主机1(orderer service)
IP:10.168.195.108
编辑docker-compose-e2e.yaml文件,只保留services下的orderer.example.com ,其它services注释掉。内容如下所示:
services: orderer.example.com: extends: file: base/docker-compose-base-peer.yaml service: orderer.example.com container_name: orderer.example.com
注意: 在部署org1和org2的主机上编辑/etc/hosts,并在文件末尾添加如下内容
10.168.195.98 orderer.example.com (按照自己实际情况)
主机2(org1:包括2个peer、1个ca)
编辑docker-compose-e2e.yaml文件,只保留services下的ca0、peer0.org1.example.com、peer1.org1.example.com,其它services注释掉。
给peer0.org1和peer1.org1添加如下内容:
extra_hosts: - "orderer.example.com:10.168.195.108"
编辑cli,修改如下内容:
#将command注释掉 command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT'#在volumes添加- ./peer:/opt/gopath/src/github.com/hyperledger/fabric/peer/- /etc/hosts:/etc/hosts
编辑base/peer-base.yaml文件,添加如下内容:
volumes: - /etc/hosts:/etc/hosts
主机3(org2:包括2个peer、1个ca)
编辑docker-compose-e2e.yaml文件,只保留services下的ca1、peer0.org2.example.com、peer1.org2.example.com,其它services注释掉。
给peer0.org1和peer1.org1添加如下内容:
extra_hosts: - "orderer.example.com:10.168.195.108"
编辑cli,修改如下内容:
#将command注释掉 command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT'#在volumes添加 - ./peer:/opt/gopath/src/github.com/hyperledger/fabric/peer/ - /etc/hosts:/etc/hosts#修改environment内容environment: - GOPATH=/opt/gopath - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock - CORE_LOGGING_LEVEL=DEBUG - CORE_PEER_ID=cli - CORE_PEER_ADDRESS=peer0.org2.example.com:7051 - CORE_PEER_LOCALMSPID=Org2MSP - CORE_PEER_TLS_ENABLED=true - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
编辑base/peer-base.yaml文件,添加如下内容:
volumes: - /etc/hosts:/etc/hosts
测试
启动Fabric网络
先启动主机1上上的orderer service
sudo docker-compose -f docker-compose-e2e.yaml up
分别在主机2、主机3上启动org1、org2的peer
sudo docker-compose -f docker-compose-e2e.yaml up
Channel
在主机2上进入cli容器
sudo docker exec -it cli bash
创建channel
peer channel create -o orderer.example.com:7050 -c mychannel -f channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
在e2e_cli/peer目录下生成一个名为mychannel.block文件,将它拷贝到主机3的e2e_cli/peer目录下。
加入channel
#在主机2、3上的cli容器内分别执行如下命令peer channel join -b mychannel.block
更新背书节点信息
#在主机2上执行peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem#在主机3上执行peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
Chaincode
Install
#主机2、3上都需要执行该命令peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
Instantiate
#该命令只需要在一个节点上实例化即可。该示例我们在主机2上进行。peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
Query
#此时在主机2、3上分别查询a的值都为100.peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
Invoke
#在主机2上进行转账操作。a转给b10.peer chaincode invoke -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'
Query
再次执行步骤3的Query操作,此时a为90,b为210.
- HyperLedger(3)多主机部署Fabric1.0
- HyperLedger/fabric1.0.0正式版部署
- Hyperledger Fabric1.0架构概览
- Hyperledger Fabric1.0架构概览
- Hyperledger Fabric1.0架构概览
- Hyperledger Fabric1.0架构概览
- HyperLedger/fabric1.0.0正式版安装部署
- 区块链 hyperledger fabric1.0 环境搭建
- IBM HyperLedger fabric1.0 详解和解决方案
- fabric1.0部署
- vmware workstation12+ubuntu16版本快速启动hyperledger fabric1.0网络
- 部署测试fabric1.0及源码解析
- the transaction flow in v1.0 of Hyperledger Fabric(fabric1.0交易流程)
- 基于Ubuntu安装HyperLedger/fabric1.0.0-beta
- hyperledger-fabric多机部署体验
- Hyperledger Fabric v1.0 部署指南
- Hyperledger Composer部署
- fabric1.0 错误分析总结
- JS原型对象,原型链
- 目标检测衡量标准
- Android ClassLoader与JAVA ClassLoader详解及对比
- HyperLedger(2)动态添加channel、organization
- IXDC2017大会: Google Daydream的虚拟现实设计思考
- HyperLedger(3)多主机部署Fabric1.0
- 二维数组根据某个键的值进行排序
- Windows下DOS命令
- Installing and developing with Hyperledger Composer
- NASA 顶级程序员是如何编程的?这里有十大准则
- Linux下的进程间通信-详解
- Deploy Composer and Generate REST API
- 关于程序员之间丧心病狂的鄙视链——编程语言篇
- 便捷提取python导入包的属性