前提是已经安装好fabric的相关环境
安装相关网络环境请看另一篇
https://www.jianshu.com/p/7e43b890d6d6
文件简介并需要提前准备的
crypto-config.yaml: 密钥配置文件
·order节点配置:个数、名称等
·peer节点配置:个数、名称等configtx.yaml: 组织、通道配置文件
·联盟配置:系统链(全局组织信息);业务链
·组织链配置:
·order组织配置:solo(共识类型、出块时间间隔、块大小)Kafkadocker-compose: docker镜像配置,如order节点、peer节点的配置
创建命令流程
- 清除环境
docker rm $(docker ps -aq)
systemctl restart docker
- 设置路径
export FABRIC_CFG_PATH=$GOPATH/src/github.com/hyperledger/my-network
- 编译生成cryptogen
cd ~/go/src/github.com/hyperledger/fabric
make cryptogen
- 编辑crypto-config.yaml,生成证书
cryptogen generate --config=./crypto-config.yaml
- 编译生成configtxgen
make configtxgen
- 编辑configtx.yaml
6.1 生成创世区块
configtxgen -profile OneOrgOrdererGenesis -outputBlock ./config/genesis.block
6.2 生成通道
configtxgen -profile TwoOrgChannel -outputCreateChannelTx ./config/kuanchannel.tx -channelID kuanchannel
6.3 锚节点配置
configtxgen -profile TwoOrgChannel -outputAnchorPeersUpdate ./config/Org0MSPanchors.tx -channelID kuanchannel -asOrg Org0MSP
configtxgen -profile TwoOrgChannel -outputAnchorPeersUpdate ./config/Org1MSPanchors.tx -channelID kuanchannel -asOrg Org1MSP
- 编辑docker-compose,启动网络
docker-compose up -d
- 创建通道
peer channel create -o orderer.kuan.com:7050 -c kuanchannel -f /etc/hyperledger/config/kuanchannel.tx
- 加入通道
peer channel join -b kuanchannel.block
其他节点加入通道需要将kuanchannel.block复制到其他通道再执行该命令
- 创建锚节点
peer channel update -o orderer.kuan.com:7050 -c kuanchannel -f /etc/hyperledger/config/Org1MSPanchors.tx
- 安装链码(java或者node链码需要额外添加一个参数 -l java 或者-l node )
peer chaincode install -n cc_sample -v 1.0 -p ChainCode/cmd
- 初始化链码(java或者node链码需要额外添加一个参数 -l java 或者-l node )
peer chaincode instantiate -o orderer.kuan.com:7050 -C kuanchannel -n cc_sample -v 1.0 -c '{"Args":["init"]}' --tls false --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
- 更新链码
peer chaincode upgrade -o orderer.kuan.com:7050 -C kuanchannel -n cc_sample -v 1.0 -c '{"Args":["init"]}' --tls false --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
- 调用链码
peer chaincode invoke -o orderer.kuan.com:7050 -C kuanchannel -n cc_filebackup -c '{"Args":["newFile","12","a","111","1","sad,sa","asd","123213","http://noname.com","2018-06-06","132"]}' --tls false --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem