107-全過程部署fabc

Lich Howger發表於2020-10-31

 

 

 

晚上20點13分開始的

我真的快要崩潰了

 

 

 

 

 

apt update

 

 

 

 

安裝git

apt install git

 

 

 

 

 

 

安裝docker

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

 

 

 

 

 

 

 

建立個資料夾吧

mkdir howger

 

 

 

 

 

 

安裝fabric映象

touch bootstrap.sh

vi bootstrap.sh

 

https://github.com/hyperledger/fabric/blob/master/scripts/bootstrap.sh

chmod 777 bootstrap.sh

 

./bootstrap

 

 

 

 

 

 

 

安裝docker-compose

curl -L https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

 

 

 

 

 

 

 

回滾版本到1.4

git checkout bc72f3e3a681eeca12dc4858d07e938244da825f

 

 

 

 

 

 

建立配置

../bin/cryptogen generate --config=./crypto-config.yaml

 

 

 

 

 

 

 

建立創世區塊

export FABRIC_CFG_PATH=$PWD

../bin/configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block

 

 

 

 

 

 

建立channel配置

export CHANNEL_NAME=mychannel  && ../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME

 

 

 

 

 

 

設定錨節點

../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP

 

../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP

 

 

 

 

 

 

 

啟動網路

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

 

 

 

 

 

 

 

進入cli容器

docker exec -it cli bash

 

 

 

 

 

 

 

切換到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

 

 

 

 

 

 

設定channel名字

export CHANNEL_NAME=mychannel

 

 

 

 

 

建立channel

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

 

 

 

 

 

加入channel

 peer channel join -b mychannel.block

 

 

 

 

 

Org2 加入channel

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 join -b mychannel.block

 

 

 

 

 

 

 

更新錨節點

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
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

 

 

 

 

 

 

安裝鏈碼

安裝fabcar鏈碼

peer chaincode install -n mycc -v 1.0 -l node -p /opt/gopath/src/github.com/chaincode/fabcar/javascript

 

 

 

 

 

 

 

切換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

Org2安裝鏈碼

peer chaincode install -n mycc -v 1.0 -l node -p /opt/gopath/src/github.com/chaincode/fabcar/javascript

 

 

 

 

 

 

 

例項化鏈碼

這個要好久好久,我差不多等了5分鐘

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 -l node -v 1.0 -c '{"Args":["initLedger"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"

 

 

 

 

 

 

查詢一下

peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["queryAllCars"]}'

 

 

 

 

 

 

 

 

 

相關文章