1.根据配置文件手动生成秘钥及创世区块
1.进入 /fabric-samples-release-1.4/first-network
2.生成证书和密钥,保存在crypto-config 文件夹中。
../bin/cryptogen generate --config=./crypto-config.yaml
3.配置configtx.yaml位置变量【…】
export FABRIC_CFG_PATH=$PWD
4.使用configtxgen工具生成创世区块(区块生成到first-network/channel-artifacts目录下)
../bin/configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
2.创建必需的应用通道交易配置文件
5.指定通道名称的环境变量
export CHANNEL_NAME=mychannel
6.生成应用通道交易配置文件
../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
#####生成锚节点更新配置文件 7.为构建的通道上的Org1定义锚节点
../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
8.为构建的通道上的Org2定义锚节点
../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
3.启动网络
9.使用配置好了的docker-compose文件关联下载好了的镜像,然后通过前面生成的 genesis.block引导排序节点。
docker-compose -f docker-compose-cli.yaml up -d
4.创建并加入通道
10.执行docker exec命令进入指定的CLI容器
docker exec -it cli bash
11.设置环境变量 查看环境变量是否设置
echo $CHANNEL_NAME
设置环境变量
export CHANNEL_NAME=mychannel
12.创建通道
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
13.将节点加入应用通道
peer channel join -b mychannel.block
14.使用Org1的管理员身份更新锚节点配置
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
CORE_PEER_LOCALMSPID="Org1MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
15.使用Org2的管理员身份更新锚节点配置
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
CORE_PEER_ADDRESS=peer0.org2.example.com:9051
CORE_PEER_LOCALMSPID="Org2MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org2MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
5.链码部分
16.使用命令exit退出CLI容器
exit
17.利用docker-compose命令查看容器是否处于活动状态
sudo docker ps
18.如果没有活动的容器,则先试用docker-compose命令启动网络,然后进入CLI容器 启动网络
sudo docker-compose -f docker-compose-cli.yaml up -d
进入CLI容器
sudo docker exec -it cli bash
19.检查当前节点(默认为peer0.example.com)已加入哪些通道中
peer channel list
执行成功后终端输出如下信息:
2021-08-22 14:02:17.178 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
Channels peers has joined:
mychannel
20.安装链码 检查通道名称的环境变量是否正确
echo $CHANNEL_NAME
设置环境变量
export CHANNEL_NAME=mychannel
使用install命令安装链码
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
21.实例化链码
peer chaincode instantiate -o orderer.example.com:7050 --tls --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 $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
22.查询链码
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
23.调用链码
peer chaincode invoke -o orderer.example.com:7050 --tls --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 $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'
|