facar单机与多机部署

facar单机与多机部署

可以和我之前写的多机部署文章一起看,有些问题重复的
大佬的多机部署博客链接:https://blog.csdn.net/bean_business/article/details/110100669

单机部署

因为我之前把fabcar文件更改过,所以需要重新下载fabric-sample内容覆盖掉fabcar文件夹

链接:https://github.com/hyperledger/fabric-samples/tree/master

需要在linux上下载,在win10下载后复制过去似乎编码啥的有问题,运行会报错

单机部署的js版(运行过没问题)

https://hyperledger-fabric.readthedocs.io/zh_CN/release-2.2/write_first_app.html

ps:感觉js版的链码写得比较清楚易懂

多机部署

仍然是用multiple-deployment文件夹中内容

先把两台机的mychannel.block,之前打包的链码压缩包删掉

建议开始前再检查一遍docker-compose-up.yaml文件中ip地址有没有错误 (两台都检查一下)

host也要检查 😡(浪费好长时间)

可能因为我更新了wmware导致和之前ip不一样了

以下是虚拟机1的操作,复制fabric样例中的名为 fabcar 的链码(智能合约)到chaincode/go

cp -r ../chaincode/fabcar/go/* chaincode/go

go env -w GO111MODULE=on

go mod tidy

安装部署链码

在虚拟机1打包链码前需要在cli1内执行

go env -w GO111MODULE=auto

安装链码的操作直接复制多机部署博客就可以(不改名字之类的话)

(如果试着改下名字可以熟练下那些参数)

操作可以参考

https://blog.csdn.net/bean_business/article/details/108015490

https://hyperledger-fabric.readthedocs.io/zh_CN/release-2.2/commands/peerlifecycle.html

主要看前两个

https://freesion.com/article/2908947275/

https://www.cnblogs.com/GarrettWale/p/15398080.html

初始化链码

args里的就是参数。(表明调用哪个函数,传进什么参数)

peer chaincode invoke -o [orderer0.example.com:7050](http://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](http://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](http://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

查询所有车辆 (query查询)

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

创建新车

与初始化链码的指令差别就在args

peer chaincode invoke -o [orderer.example.com:7050](http://orderer.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](http://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](http://peer0.org2.example.com:9051/) --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --isInit -c '{"Args":["CreateCar","CAR10","GEELY","Borui","Blue","Yujialing"]}'

在这里插入图片描述

查询具体的车

peer chaincode query -C mychannel -n mycc -c '{"Args":["QueryCar","CAR10"]}'

更改车辆所有者(调用ChangeCarOwner函数)

peer chaincode invoke -o [orderer0.example.com:7050](http://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](http://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](http://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":["ChangeCarOwner","CAR10","广东靓仔"]}' --waitForEvent

更改并同步成功
虚拟机1

虚拟机2

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值