1.退出当前容器命令:exit
查看当前分支版本:git status
停止当前网络运行:./byfn.sh down
寻找可用的版本:git fetch origin
跳转到1.2.0分支:git checkout v1.2.0
生成创世区块:./byfn.sh generate
启动1.2.0版本网络:./byfn.sh up -t 3000 -i 1.2.0
跳转到主分支:git fetch origin
跳转要更新的版本:git checkout v1.3.0
2.停止背书节点:docker stop orderer.example.com
设置分类账环境变量:export LEDGERS_BACKUP=./ledgers-backup
设置1.3.0版本镜像标签:export IMAGE_TAG=$(go env GOARCH)-1.3.0 //不知道tag可以上GitHub查tag
创建背书节点的分类账备份文件夹:mkdir -p $LEDGERS_BACKUP
备份分类账本和msp:docker cp orderer.example.com:/var/hyperledger/production/orderer/ ./$LEDGERS_BACKUP/orderer.example.com
下载重新启动背书节点:docker-compose -f docker-compose-cli.yaml up -d --no-deps orderer.example.com
3.设置节点环境变量:export PEER=peer0.org1.example.com
停止节点运行:docker stop $PEER
创建对等节点备份文件夹:mkdir -p $LEDGERS_BACKUP
备份账本和msp:docker cp $PEER:/var/hyperledger/production ./$LEDGERS_BACKUP/$PEER
删除对等节点链码容器:CC_CONTAINERS=$(docker ps | grep dev-$PEER | awk '{print $1}')
if [ -n "$CC_CONTAINERS" ] ; then docker rm -f $CC_CONTAINERS ; fi
删除对等节点容器镜像:CC_IMAGES=$(docker images | grep dev-$PEER | awk '{print $1}')
if [ -n "$CC_IMAGES" ] ; then docker rmi -f $CC_IMAGES ; fi
下载对等节点镜像和重新启动容器:docker-compose -f docker-compose-cli.yaml up -d --no-deps $PEER
停止cli容器:docker-compose -f docker-compose-cli.yaml stop cli
获取1.3版本的cli容器:IMAGE_TAG=$(go env GOARCH)-1.3.0 docker-compose -f docker-compose-cli.yaml up -d --no-deps cli
进入cli容器:docker exec -it cli bash
设置通道名称环境变量:CH_NAME=mychannel
设置排序服务根证书环境变量:ORDERER_CA=/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.example.com:7050 --peerAddresses 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 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --tls --cafile $ORDERER_CA -C $CH_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'
测试是否调用成功:peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'//80即可
退出当前容器:exit
同理更新每一个容器:export PEER=peer1.org1.example.com export PEER=peer0.org2.example.com export PEER=peer1.org2.example.com //没有详细写,如上步骤
步骤:docker stop $PEER
docker cp $PEER:/var/hyperledger/production ./$LEDGERS_BACKUP/$PEER
CC_CONTAINERS=$(docker ps | grep dev-$PEER | awk '{print $1}')
if [ -n "$CC_CONTAINERS" ] ; then docker rm -f $CC_CONTAINERS ; fi
CC_IMAGES=$(docker images | grep dev-$PEER | awk '{print $1}')
if [ -n "$CC_IMAGES" ] ; then docker rmi -f $CC_IMAGES ; fi
docker-compose -f docker-compose-cli.yaml up -d --no-deps $PEER
docker-compose -f docker-compose-cli.yaml stop cli
IMAGE_TAG=$(go env GOARCH)-1.3.0 docker-compose -f docker-compose-cli.yaml up -d --no-deps cli
4.背书节点系统信道
进入cli 容器:docker exec -it cli bash
查看当前容器状态:env|grep PEER
背书节点信道组
设置环境变量:CORE_PEER_LOCALMSPID="OrdererMSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin@example.com/msp
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
设置通道名称CH_NAME=testchainid
信道组:
获取最新配置区块:
peer channel fetch config config_block.pb -o orderer.example.com:7050 -c $CH_NAME --tls --cafile $ORDERER_CA
易于编辑,转化pb为json:configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json
去除元数据等:
jq .data.data[0].payload.data.config config_block.json > config.json
添加更新功能文件:jq -s '.[0] * {"channel_group":{"values": {"Capabilities": .[1]}}}' config.json ./scripts/capabilities.json > modified_config.json
将其转化为二进制更新文件:configtxlator proto_encode --input config.json --type common.Config --output config.pb
configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb
configtxlator compute_update --channel_id $CH_NAME --original config.pb --updated modified_config.pb --output config_update.pb //同添加组织步骤
将配置更新文件打包成事务:configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
echo '{"payload":{"header":{"channel_header":{"channel_id":"'$CH_NAME'", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' | jq . > config_update_in_envelope.json
configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output config_update_in_envelope.pb
签名并提交更新:peer channel update -f config_update_in_envelope.pb -c $CH_NAME -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA
5.个人组
背书节点环境变量
设置环境变量:export CORE_PEER_LOCALMSPID="Org1MSP"
export 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
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
export CH_NAME="mychannel"
信道组:
同理进行如上加蓝步骤
使用org1管理员进行提交更新:peer channel signconfigtx -f config_update_in_envelope.pb
进入org2管理员环境进行签名:export CORE_PEER_LOCALMSPID="Org2MSP"
export 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
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=peer0.org2.example.com:7051
org2管理员签名提交更新:peer channel signconfigtx -f config_update_in_envelope.pb
进入排序节点组织进行签名环境:
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin@example.com/msp
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
进行签名提交更新:peer channel update -f config_update_in_envelope.pb -c $CH_NAME -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA
应用组:
进入org1环境变量:
export CORE_PEER_LOCALMSPID="Org1MSP"
export 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
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
执行如上蓝色步骤
进行签名提交更新:
peer channel signconfigtx -f config_update_in_envelope.pb
进入org2环境变量:
export CORE_PEER_LOCALMSPID="Org2MSP"
export 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
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=peer0.org2.example.com:7051
进行签名并提交更新:peer channel update -f config_update_in_envelope.pb -c $CH_NAME -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA
6.验证升级是否完成:
进行转账操作:peer chaincode invoke -o orderer.example.com:7050 --peerAddresses 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 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --tls --cafile $ORDERER_CA -C $CH_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'
查询结果:peer chaincode query -C $CH_NAME -n mycc -c '{"Args":["query","a"]}'
结果:Query Result: 70 //出现任何数字都可以