参考好多网上的文章想弄出属于的一套调试模式: 研究将近两个星期终于搞定!
拥有此套调试流程开发底层效率可以三倍docker流! 磨刀不误砍柴功!
关于拉代码这回事我就不在这里说了.....
环境和工具尽量如下
编辑器用golang 调试贼爽
下面说流程:
- make native 打包出cryptogen,idemixgen,configtxgen 工具 peer 和orderer 不用打包我们用更方便的方法调试
2. 设置环境变量 我为了方便将这3个peer和orderer的环境变量加入到 ~/.bash_profile中 建议设置重启source 对编辑器不生效!
export FABRIC_CFG_PATH=/go/src/github.com/hyperledger/fabric/config
export FABRIC_LOGGING_SPEC=debug
export CHANNEL_NAME=mychannel
3. 接下来在fabric 目录下创建config目录
复制 scripts/fabric-samples/first-network下面的configtx.yaml,crypto-config.yaml 和scripts/fabric-samples/config的code.yaml和orderer.yaml 到你创建的config文件夹中
4.用一下生成msp证书 会多出 crypto-config文件夹
cryptogengenerate--config=./crypto-config.yaml
5.创建创世区块
configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
6.生成通道文件 如果没channel-artifacts此文件夹手动建名字自己想也可以
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel.tx -channelID mychannel
7.生成锚节点
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
8.在hosts文件 将下面域名映射127.0.0.1
127.0.0.1 peer0.org1.example.com
127.0.0.1 peer1.org1.example.com
127.0.0.1 peer2.org1.example.com
127.0.0.1 peer3.org1.example.com
127.0.0.1 orderer.example.com
9. 启动orderer节点建议
根据配置在Environment选项填入一下环境变量
ORDERER_GENERAL_LOGLEVEL=DEBUG;ORDERER_GENERAL_TLS_ENABLED=false;ORDERER_GENERAL_PROFILE_ENABLED=false;ORDERER_GENERAL_LISTENADDRESS=0.0.0.0;ORDERER_GENERAL_LISTENPORT=7050;ORDERER_GENERAL_GENESISMETHOD=file;ORDERER_GENERAL_GENESISFILE=/go/src/github.com/hyperledger/fabric/config/channel-artifacts/genesis.block;ORDERER_GENERAL_LOCALMSPID=OrdererMSP;CONSENSUS_TYPE=sole;ORDERER_GENERAL_LOCALMSPDIR=crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp
10.启动peer节点
根据配置在Environment选项填入一下环境变量
CORE_PEER_ID=Org1MSP;CORE_CHAINCODE_MODE=dev;CORE_PEER_NETWORKID=dev;CORE_PEER_TLS_ENABLED=false;CORE_PEER_ADDRESS=peer0.org1.example.com:7051;CORE_PEER_LISTENADDRESS=0.0.0.0:7051;CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051;CORE_PEER_LOCALMSPID=Org1MSP;CORE_PEER_MSPCONFIGPATH=crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp;CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052;CORE_PEER_CHAINCODEADDRESS=peer0.org1.example.com:7052;FABRIC_LOGGING_SPEC=INFO
11.新建终端添加下面环境变量
export CORE_PEER_ID=Org1MSP
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
export CORE_PEER_LOCALMSPID=Org1MSP
export CORE_PEER_MSPCONFIGPATH=/go/src/github.com/hyperledger/fabric/config/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
12. 创建通道
peer channel create -o orderer.example.com:7050 -c mychannel -f /go/src/github.com/hyperledger/fabric/config/channel-artifacts/mychannel.tx --tls --cafile /go/src/github.com/hyperledger/fabric/config/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
注意: 如果orderer 和peer节点没开启tls 验证 就别填 --tls --cafile 参数
13. 加入通道
peer channel join -b $CHANNEL_NAME.block
14. 更新锚节点
peer channel update -o orderer.example.com:7050 -c mychannel -f /go/src/github.com/hyperledger/fabric/config/channel-artifacts/Org1MSPanchors.tx
15. 打开新终端开启链码
export CORE_CHAINCODE_ID_NAME=mycc:1.0
export CORE_PEER_ADDRESS=peer0.org1.example.com:7052
go run /go/src/github.com/hyperledger/fabric/scripts/fabric-samples/chaincode/chaincode_example02/go/chaincode_example02.go
16. 安装链码 参数同11
peer chaincode install -n mycc -v1.0-l golang -p github.com/chaincode/chaincode_example02/go/
17.初始化链码
peer chaincode instantiate -o orderer.example.com:7050--tlstrue--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 -l golang -v1.0-c '{"Args":["init","a","100","b","200"]}' -P 'AND ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'
ok 链码测试
peer chaincodequery-C mychannel -n mycc -c '{"Args":["query","a"]}'
假设配置错误删除 以下文件夹重新配置
/var/hyperledger/production
channel-artifacts
crypto-config
祝您好运!
以下是我微信有问题可以交流
有疑问加站长微信联系(非本文作者)