做视频网站服务器配置,建行系统,用js做网站登录,阳江网站建设 公司这是我搭建的fabric的网络拓扑
3 个 orderer 节点#xff1b;组织 org1 , org1 下有两个 peer 节点#xff0c; peer0 和 peer1; 组织 org2 , org2 下有两个 peer 节点#xff0c; peer0 和 peer1; 以上是我的多机环境的网络拓扑#xff0c;使用的是docker搭建的。我的网络…这是我搭建的fabric的网络拓扑
3 个 orderer 节点组织 org1 , org1 下有两个 peer 节点 peer0 和 peer1; 组织 org2 , org2 下有两个 peer 节点 peer0 和 peer1; 以上是我的多机环境的网络拓扑使用的是docker搭建的。我的网络已经搭建成功这里主要记录一下多机环境下合约部署与交互的操作因为是用虚拟机搭建有时候关机后需要重启dcoek节点然后创建通道部署链码。关于config和docker-compose的yaml文件不知道怎么部署的可以私信我哦多机生产网络的搭建有太多的坑了。
1. 启动网络
在两台机器上启动网络 docker-compose -f docker-compose-up.yaml up -d 可以看到我的所有节点都已经起来了三个orderer两个组织每个组织包含两个peer节点。
2. 创建通道并加入
2.1 虚拟机1创建通道并加入
进⼊ cli1容器也就是以 peer0.org1 的⾓⾊与⽹络交互
docker exec -it cli1 bash 创建通道
peer channel create -o orderer0.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem组织1 的 peer0 节点加⼊通道 mychannel
peer channel join -b mychannel.block更新 组织1 的锚节点
peer channel update -o orderer0.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/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 退出 cli1 容器从 cli1 容器中拷⻉出 mychannel.block ⽂件到 multiple-deployment ⽂件夹下并复制到 虚拟机2 中
exit docker cp cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/mychannel.block ./
scp -r mychannel.block org2192.168.5.112:/home/org2/go/src/github.com/hyperledger/fabric-samples/multiple-deployment查看虚拟机2是否收到
2.2 虚拟机2加入通道
将 mychannel.block 拷⻉到 虚拟机2 的 cli1 组织2 的 peer0 ⾓⾊容器中
docker cp mychannel.block cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/进⼊ cli1 容器
docker exec -it cli1 bash
ls加入通道
peer channel join -b mychannel.block 更新组织 2 的锚节点主节点
peer channel update -o orderer0.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/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem3. 安装调用智能合约
安装的同样是basic链码在前面对这个链码介绍过当时在测试网络中进行了部署调用有兴趣的可以去看看对于合约的讲解。博文
3.1 安装链码
首先是虚拟机1的操作
# 进入容器
docker exec -it cli1 bash
# 打包链码
peer lifecycle chaincode package mycc.tar.gz --path ../../multiple-deployment/chaincode/go/basic --lang golang --label mycc_1 # 安装链码 安装需要在两个组织都安装现在只是在虚拟机1
peer lifecycle chaincode install mycc.tar.gz
#控制台信息
rootb63202ddd2b5:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer lifecycle chaincode install mycc.tar.gz
2023-11-15 02:11:26.585 UTC 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal - Installed remotely: response:status:200 payload:\nGmycc_1:c6ad224cdefc5e53bc261bb6b1fbed12b789225105f59373869b533067c9b009\022\006mycc_1
2023-11-15 02:11:26.587 UTC 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal - Chaincode code package identifier: mycc_1:c6ad224cdefc5e53bc261bb6b1fbed12b789225105f59373869b533067c9b009注意合约的这个id后面要用
mycc_1:c6ad224cdefc5e53bc261bb6b1fbed12b789225105f59373869b533067c9b009退出 cli1 容器将打包的链码 mycc.tar.gz 从 cli1 容器中提取出来并拷⻉到 虚拟机2的 multiple-deployment ⽬录下
exit
docker cp cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/mycc.tar.gz ./
scp -r mycc.tar.gz org2192.168.5.112:/home/org2/go/src/github.com/hyperledger/fabric-samples/multiple-deployment在虚拟机2查看我们已经收到了发送的打包后的链码 接下来是虚拟机2的操作
退出 cli1 容器将 multiple-deployment ⽬录下的链码压缩包 mycc.tar.gz 复制到 cli1 组织2 的 peer0 容器中
exit
docker cp mycc.tar.gz cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/
# 进入容器查看
docker exec -it cli1 bash
ls安装链码
peer lifecycle chaincode install mycc.tar.gz 两个组织都已经安装了链码链码的id应该是一样的mycc_1:c6ad224cdefc5e53bc261bb6b1fbed12b789225105f59373869b533067c9b009
3.2 授权与提交链码
虚拟机1再次进⼊ cli1 容器同意提交链码
docker exec -it cli1 bash
peer lifecycle chaincode approveformyorg --channelID mychannel --name mycc --version 1.0 --init-required --package-id mycc_1:c6ad224cdefc5e53bc261bb6b1fbed12b789225105f59373869b533067c9b009 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 虚拟机2进⼊ cli1 容器同意提交链码
peer lifecycle chaincode approveformyorg --channelID mychannel --name mycc --version 1.0 --init-required --package-id mycc_1:c6ad224cdefc5e53bc261bb6b1fbed12b789225105f59373869b533067c9b009 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 虚拟机1
查看链码状态是否就绪
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc --version 1.0 --init-required --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --output json提交链码
peer lifecycle chaincode commit -o orderer0.example.com:7050 --channelID mychannel --name mycc --version 1.0 --sequence 1 --init-required --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt 3.3 与网络进行交互(合约的调用)
3.3.1 初始链码 – 虚拟机1
peer chaincode invoke -o orderer0.example.com:7050 --isInit --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c {Args:[InitLedger]} --waitForEvent对应的就是完成了下面的代码的功能 我们对账本进行了初始化并且是在虚拟机1上的操作现在想要验证一下虚拟机1的操作有没有在网络中进行同步可以在虚拟机2上查看现在账本上的所有资产是否是刚才初始化的那些资产。
3.3.2 在虚拟机2上查看一下当前的所有资产
进入容器后
peer chaincode invoke -o orderer0.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c {Args:[GetAllAssets]} --waitForEvent# 控制台输出的资产
{\AppraisedValue\:300,\Color\:\blue\,\ID\:\asset1\,\Owner\:\Tomoko\,\Size\:5},{\AppraisedValue\:400,\Color\:\red\,\ID\:\asset2\,\Owner\:\Brad\,\Size\:5},{\AppraisedValue\:500,\Color\:\green\,\ID\:\asset3\,\Owner\:\Jin Soo\,\Size\:10},{\AppraisedValue\:600,\Color\:\yellow\,\ID\:\asset4\,\Owner\:\Max\,\Size\:10},{\AppraisedValue\:700,\Color\:\black\,\ID\:\asset5\,\Owner\:\Adriana\,\Size\:15},{\AppraisedValue\:800,\Color\:\white\,\ID\:\asset6\,\Owner\:\Michel\,\Size\:15}通过结果得知现在我们的操作已经在网络中同步了。
3.3.3 创建一个资产
创建资产CreateAsset(id string, color string, size int, owner string, appraisedValue int
peer chaincode invoke -o orderer0.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c {Args:[CreateAsset,asset7,red,15,Guandw,1000]} --waitForEvent 3.3.4 查看资产
peer chaincode invoke -o orderer0.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c {Args:[GetAllAssets]} --waitForEvent {“AppraisedValue”:300,“Color”:“blue”,“ID”:“asset1”,“Owner”:“Tomoko”,“Size”:5},{“AppraisedValue”:400,“Color”:“red”,“ID”:“asset2”,“Owner”:“Brad”,“Size”:5}, {“AppraisedValue”:500,“Color”:“green”,“ID”:“asset3”,“Owner”:“Jin Soo”,“Size”:10},{“AppraisedValue”:600,“Color”:“yellow”,“ID”:“asset4”,“Owner”:“Max”,“Size”:10},{“AppraisedValue”:700,“Color”:“black”,“ID”:“asset5”,“Owner”:“Adriana”,“Size”:15},{“AppraisedValue”:800,“Color”:“white”,“ID”:“asset6”,“Owner”:“Michel”,“Size”:15}, {\AppraisedValue\:1000,\Color\:\red\,\ID\:\asset7\,\Owner\:\Guandw\,\Size\:15}
通过结果我们在虚拟机2创建资产然后再虚拟机1查看所有资产一样可以看到虚拟机2的操作在网络中同步了。我们的网络搭建也是没有问题的。
4. 关闭网络
如果要结束⽹络可以在退出 cli1容器 后使⽤以下指令退出
docker-compose -f docker-compose-up.yaml down如果需要清空容器的volume的话执行慎重因为清空后无法重启一般是用来格式化重新启动容器创建通道
docker system df
docker volume rm $(docker volume ls -qf danglingtrue)
文章转载自: http://www.morning.nbfkk.cn.gov.cn.nbfkk.cn http://www.morning.fylsz.cn.gov.cn.fylsz.cn http://www.morning.ybyln.cn.gov.cn.ybyln.cn http://www.morning.kyfnh.cn.gov.cn.kyfnh.cn http://www.morning.fdrwk.cn.gov.cn.fdrwk.cn http://www.morning.rqlf.cn.gov.cn.rqlf.cn http://www.morning.pprxs.cn.gov.cn.pprxs.cn http://www.morning.hnrls.cn.gov.cn.hnrls.cn http://www.morning.hffpy.cn.gov.cn.hffpy.cn http://www.morning.blfgh.cn.gov.cn.blfgh.cn http://www.morning.bcjbm.cn.gov.cn.bcjbm.cn http://www.morning.xlclj.cn.gov.cn.xlclj.cn http://www.morning.gkgb.cn.gov.cn.gkgb.cn http://www.morning.ggnfy.cn.gov.cn.ggnfy.cn http://www.morning.lfdrq.cn.gov.cn.lfdrq.cn http://www.morning.kclkb.cn.gov.cn.kclkb.cn http://www.morning.bpmtj.cn.gov.cn.bpmtj.cn http://www.morning.zlgbx.cn.gov.cn.zlgbx.cn http://www.morning.ngcsh.cn.gov.cn.ngcsh.cn http://www.morning.mooncore.cn.gov.cn.mooncore.cn http://www.morning.ybhjs.cn.gov.cn.ybhjs.cn http://www.morning.mypxm.com.gov.cn.mypxm.com http://www.morning.mnyzz.cn.gov.cn.mnyzz.cn http://www.morning.hflrz.cn.gov.cn.hflrz.cn http://www.morning.kgkph.cn.gov.cn.kgkph.cn http://www.morning.hchrb.cn.gov.cn.hchrb.cn http://www.morning.rpljf.cn.gov.cn.rpljf.cn http://www.morning.rnwmp.cn.gov.cn.rnwmp.cn http://www.morning.baguiwei.com.gov.cn.baguiwei.com http://www.morning.tjwfk.cn.gov.cn.tjwfk.cn http://www.morning.dwwbt.cn.gov.cn.dwwbt.cn http://www.morning.fcwxs.cn.gov.cn.fcwxs.cn http://www.morning.smsjx.cn.gov.cn.smsjx.cn http://www.morning.srjgz.cn.gov.cn.srjgz.cn http://www.morning.wpcfm.cn.gov.cn.wpcfm.cn http://www.morning.qdzqf.cn.gov.cn.qdzqf.cn http://www.morning.qrpx.cn.gov.cn.qrpx.cn http://www.morning.kpxky.cn.gov.cn.kpxky.cn http://www.morning.mcpby.cn.gov.cn.mcpby.cn http://www.morning.xtlty.cn.gov.cn.xtlty.cn http://www.morning.nxbkw.cn.gov.cn.nxbkw.cn http://www.morning.phnbd.cn.gov.cn.phnbd.cn http://www.morning.btsls.cn.gov.cn.btsls.cn http://www.morning.hclplus.com.gov.cn.hclplus.com http://www.morning.srmdr.cn.gov.cn.srmdr.cn http://www.morning.cffwm.cn.gov.cn.cffwm.cn http://www.morning.benqc.com.gov.cn.benqc.com http://www.morning.qhkx.cn.gov.cn.qhkx.cn http://www.morning.zrlms.cn.gov.cn.zrlms.cn http://www.morning.zmwd.cn.gov.cn.zmwd.cn http://www.morning.jygsq.cn.gov.cn.jygsq.cn http://www.morning.krrjb.cn.gov.cn.krrjb.cn http://www.morning.yodajy.cn.gov.cn.yodajy.cn http://www.morning.wjfzp.cn.gov.cn.wjfzp.cn http://www.morning.zmzdx.cn.gov.cn.zmzdx.cn http://www.morning.rlhh.cn.gov.cn.rlhh.cn http://www.morning.clbgy.cn.gov.cn.clbgy.cn http://www.morning.mlmwl.cn.gov.cn.mlmwl.cn http://www.morning.ykrkb.cn.gov.cn.ykrkb.cn http://www.morning.jpgfq.cn.gov.cn.jpgfq.cn http://www.morning.sgmis.com.gov.cn.sgmis.com http://www.morning.mcfjq.cn.gov.cn.mcfjq.cn http://www.morning.jfwbr.cn.gov.cn.jfwbr.cn http://www.morning.lqynj.cn.gov.cn.lqynj.cn http://www.morning.fpjw.cn.gov.cn.fpjw.cn http://www.morning.tsrg.cn.gov.cn.tsrg.cn http://www.morning.tkcz.cn.gov.cn.tkcz.cn http://www.morning.rqxhp.cn.gov.cn.rqxhp.cn http://www.morning.fppzc.cn.gov.cn.fppzc.cn http://www.morning.qtwd.cn.gov.cn.qtwd.cn http://www.morning.bojkosvit.com.gov.cn.bojkosvit.com http://www.morning.yrjym.cn.gov.cn.yrjym.cn http://www.morning.pbsfq.cn.gov.cn.pbsfq.cn http://www.morning.prmbn.cn.gov.cn.prmbn.cn http://www.morning.lhqw.cn.gov.cn.lhqw.cn http://www.morning.snnwx.cn.gov.cn.snnwx.cn http://www.morning.hsdhr.cn.gov.cn.hsdhr.cn http://www.morning.hdscx.cn.gov.cn.hdscx.cn http://www.morning.fwkq.cn.gov.cn.fwkq.cn http://www.morning.kjyfq.cn.gov.cn.kjyfq.cn