手動搭建基礎的fabric網絡-fabric學習筆記(二)

手動搭建基礎的fabric網絡

(1)使用密鑰生成器cryptogen產生Org1和Org2的加密材料

Cryptogen generate –config=./crypto-config.yaml

(2)使用交易配置工具configtxgen產生創世區塊

export FABRIC_CFG_PATH=$PWD (用來告訴configtxgen 去哪兒找configtx.yaml 文件)

Configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel(系統通道) -outputBlock ./channel-artifacts/genesis.block

(3)使用交易配置工具configtxgen產生通道配置交易文件channel.tx

Configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel(普通通道)

(4)使用交易配置工具configtxgen產生錨節點

Configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel(普通通道) -asOrg Org1MSP

Configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel(普通通道) -asOrg Org2MSP

(5)使用docker-compose啓動網絡進入cli容器

docker-compose -f docker-compose-cli.yaml up -d

docker exec -it cli bash

(6)創建通道channel

Peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx –tls true –cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem(證書路徑)

(7)配置不同的peer節點的環境變量,使的所有的peer節點加入channel

Peer channel join -b mychannel.block

切換peer節點環境變量的例子(切換爲peer0.org1)

# Environment variables for PEER0
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

(8)分別爲“Org1MSP”和“Org2MSP” 更新錨節點

#更新Org1MSP

Peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchor.tx –tls true –cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem(證書路徑)

#更新Org2MSP

Peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchor.tx –tls true –cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem(證書路徑)

(9)分別在org1和org2上安裝、實例化鏈碼

#安裝

Peer chaincode install -n mychaincode -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/(chaincode路徑)

#實例化

Peer chaincode instantiate -o orderer.example.com:7050 –tls true –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 mychaincode -v 1.0 -l golang -c '{"Args":["init","a","100","b","200"]}' -P 'AND ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'

(10)利用chaincode查詢數據,調用chaincode

#查詢

Peer chaincode query -C mychannel -n mychaincode -c '{"Args":["query","a"]}'

# 調用

Peer chaincode invoke -o orderer.example.com:7050 –tls true –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 mychaincode –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:9051 –tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章