当前位置: 代码迷 >> 综合 >> Fabric1.2 kafka多机部署配置
  详细解决方案

Fabric1.2 kafka多机部署配置

热度:50   发布时间:2023-12-22 13:46:19.0

Fabric kafka多机部署配置文件

地址分配
host.name=localhost
192.168.255.120 zookeeper0
192.168.255.114 zookeeper1
192.168.255.102 zookeeper2

192.168.255.120 kafka0
192.168.255.114 kafka1
192.168.255.102 kafka2

192.168.255.120 orderer0.example.com
192.168.255.114 orderer1.example.com
192.168.255.102 orderer2.example.com

192.168.255.121 peer0.org1.example.com
192.168.255.114 peer1.org1.example.com
192.168.255.102 peer0.org2.example.com
192.168.255.120 peer1.org2.example.com
在/etc/hosts加入

配置文件https://download.csdn.net/download/ruidongren/10674182

在go/src/github.com/hyperledger/fabric/examples/e2e_cli中运行
./generateArtifacts.sh mychannel
拷贝
channel-artifacts/
crypto-config/
这两个文件到其他服务器的go/src/github.com/hyperledger/fabric/examples/e2e_cli目录中

//配置完系统 依次启动 zookeep kafka roderer

docker-compose -f docker-compose-zookeeper.yaml up -d
docker-compose -f docker-compose-kafka.yaml up -d
docker-compose -f docker-compose-orderer.yaml up -d
docker-compose -f docker-compose-peer.yaml up -d

//启动 peer0.org1的 peer
docker exec -it cli bash //进入bash
//创建channel
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
#peer channel create -o orderer0.example.com:7050 -c mychannel -f ./channel-artifacts/mychannel.tx --tls --cafile $ORDERER_CA

//peer加入 channel
peer channel join -b mychannel.block

//安装智能合约
peer chaincode install -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd/ -v 1.0

//区块初始化数据为a为200,b为400
#ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
#peer chaincode instantiate -o orderer0.example.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n mycc -v 1.0 -c ‘{“Args”:[“init”,“a”,“200”,“b”,“400”]}’ -P “OR (‘Org1MSP.peer’,‘Org2MSP.peer’)”

// Peer上查询a,显示200
#peer chaincode query -C mychannel -n mycc -c ‘{“Args”:[“query”,“a”]}’

//拷贝mychannel.block到其他各服务器
//从docker中拷贝出
docker cp xxxxxxxx:/opt/gopath/src/github.com/hyperledger/fabric/peer/mychannel.block ./
scp huahua@192.168.255.121:/home/huahua/mychannel.block ./
/*
直接拷贝进去
docker cp /opt/gopath/src/github.com/hyperledger/fabric/kafkapeer/mychannel.block xxxxxxxx:/opt/gopath/src/github.com/hyperledger/fabric/peer/

从peer配置文件中烤肉
volumes:
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
*/

//启动其他服务器peer
//加入channel
peer channel join -b mychannel.block
//安装智能合约
peer chaincode install -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd/ -v 1.0

//交易
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer0.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

peer chaincode invoke --tls --cafile $ORDERER_CA -C mychannel -n mycc -c ‘{“Args”:[“invoke”,“a”,“b”,“20”]}’
peer chaincode invoke --tls --cafile $ORDERER_CA -C mychannel -n mycc -c ‘{“Args”:[“invoke”,“b”,“a”,“5”]}’

在这里插入图片描述