fabric2.2.0搭建

2021-03-30  本文已影响0人  张亚伦

目标:
3个order 3个peer

环境搭建

  1. 启动ca (order,peer)
    docker-compose -f ./docker/docker-compose-ca.yaml up -d 2>&1
[root@localhost fabric2.2.0_zxl]# tree organizations/
organizations/
└── fabric-ca
    ├── ordererOrg
    │?? ├── ca-cert.pem
    │?? ├── fabric-ca-server-config.yaml
    │?? ├── fabric-ca-server.db
    │?? ├── IssuerPublicKey
    │?? ├── IssuerRevocationPublicKey
    │?? ├── msp
    │?? │?? ├── cacerts
    │?? │?? ├── keystore
    │?? │?? │?? ├── 1e42c84dadee8f150fbc5dd345f6330836bdda5cb9ee4b650e1057753493cbce_sk
    │?? │?? │?? ├── b59d892a7a6aedc80db0fb501c38ccd7fb71a5b8d82e3bc5127402035cff0b97_sk
    │?? │?? │?? ├── IssuerRevocationPrivateKey
    │?? │?? │?? └── IssuerSecretKey
    │?? │?? ├── signcerts
    │?? │?? └── user
    │?? └── tls-cert.pem
    ├── org1
    │?? ├── ca-cert.pem
    │?? ├── fabric-ca-server-config.yaml
    │?? ├── fabric-ca-server.db
    │?? ├── IssuerPublicKey
    │?? ├── IssuerRevocationPublicKey
    │?? ├── msp
    │?? │?? ├── cacerts
    │?? │?? ├── keystore
    │?? │?? │?? ├── 23976420eb6cf3cda3fc29294f1436a69a125826ad78fc49d54f6f3718e5262c_sk
    │?? │?? │?? ├── 7f1bc06976eec6412172b53f5cd6f3f0def51b17a5a15c642d2ae042bb9af7a9_sk
    │?? │?? │?? ├── IssuerRevocationPrivateKey
    │?? │?? │?? └── IssuerSecretKey
    │?? │?? ├── signcerts
    │?? │?? └── user
    │?? └── tls-cert.pem
    └── registerEnroll.sh

13 directories, 21 files
[root@localhost fabric2.2.0_zxl]# 
  1. registerEnroll:
       createOrg1: 
                infoln "Enrolling the CA admin"
                infoln "Registering peer0",
                infoln "Registering user", 
                infoln "Registering the org admin",
                infoln "Generating the peer0 msp",
                infoln "Generating the peer0-tls certificates",
                infoln "Generating the user msp",
                infoln "Generating the org admin msp",

                infoln "Generating the peer1 msp",
                infoln "Generating the peer1-tls certificates",

        createOrderer:
                infoln "Enrolling the CA admin"
                infoln "Registering orderer"
                infoln "Registering the orderer admin"
                infoln "Generating the orderer msp"
                infoln "Generating the orderer-tls certificates"
                infoln "Generating the admin msp"

脚本:

sh -x  ./organizations/fabric-ca/registerEnroll.sh 

# infoln "Generating CCP files for Org1"
sh -x ./organizations/ccp-generate.sh  

  1. 启动节点(order peer)
 // 设置FABRIC_CFG_PATH=${PWD}/configtx或者进入configtx目录后执行下面命令

# 生成创始区块
configtxgen -profile OrgsOrdererGenesis -channelID system-channel -outputBlock ./blocktx/genesis.block

# copy the 'gennesis.block' file to the 'sharedfiles' directory
cp ../configtx/blocktx/genesis.block  ./sharedfiles/

# 启动order (分别启动,例如:order1,order2)

docker-compose -f docker-compose-order.yaml up -d 2>&1

#

# _启动peer和cli
docker-compose -f docker-compose-peer.yaml up -d 2>&1
#

docker save -o fabric-tools.tar hyperledger/fabric-tools:2.2.0
docker load -i fabric-tools.tar
  1. 部署预制的应用通道
# createChannelTx
configtxgen -profile OrgsChannel -outputCreateChannelTx  blocktx/netchannel.tx -channelID netchannel

#创建通道

docker exec -it org1cli sh


peer channel create -o orderer1.example.com:7050 -c netchannel -f blocktx/netchannel.tx --tls true --cafile ./organizations/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem



#加入通道(其他组织节点会自动加进去)
peer channel join -b netchannel.block

  1. 部署链码basic
peer lifecycle chaincode package basic1.tar.gz --path ../asset-transfer-basic/chaincode-javascript/ --lang node --label basic_1.0


peer lifecycle chaincode install basic.tar.gz

output:
2021-03-19 08:36:51.127 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: basic_1.0:87399a8496d498a8aedfe4cd7a4e469b7d6c9649a267499c5814bfe9b555e552

peer lifecycle chaincode queryinstalled

output:
Installed chaincodes on peer:
Package ID: basic_1.0:87399a8496d498a8aedfe4cd7a4e469b7d6c9649a267499c5814bfe9b555e552, Label: basic_1.0


peer lifecycle chaincode approveformyorg -o orderer1.example.com:7050 --tls --cafile ./organizations/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID netchannel --name basic --version 1.0 --sequence 1 --package-id basic_1.0:87399a8496d498a8aedfe4cd7a4e469b7d6c9649a267499c5814bfe9b555e552

output:
2021-03-19 09:07:18.730 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [1a4c1eadee45e74471198075f679e5e0f7d8c805c2195ef99296245271de6e9e] committed with status (VALID) at

peer lifecycle chaincode checkcommitreadiness --channelID netchannel --name basic --version 1.0 --sequence 1 --output json


peer lifecycle chaincode commit -o orderer1.example.com:7050 --tls --cafile ./organizations/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID netchannel --name basic --version 1.0 --sequence 1  --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /etc/hyperledger/fabric/tls/ca.crt 

output:
2021-03-19 09:19:17.260 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [51bb52b67582f9266e7c50789a770b651d2e361023a0f549c0ce728e177b991b] committed with status (VALID) at peer0.org1.example.com:7051

peer lifecycle chaincode querycommitted --channelID netchannel --name basic

output:
Committed chaincode definition for chaincode 'basic' on channel 'netchannel':
Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true]
  1. 调用链码
#调用链码

// InitLedger
peer chaincode invoke -o orderer1.example.com:7050 --tls --cafile ./organizations/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem   -C netchannel -n basic --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /etc/hyperledger/fabric/tls/ca.crt -c '{"Args":["InitLedger"]}'

#查询链码
// GetAllAssets
peer chaincode query -C netchannel -n basic -c '{"Args":["GetAllAssets"]}'


// CreateAsset
peer chaincode invoke -o orderer1.example.com:7050 --tls --cafile ./organizations/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem   -C netchannel -n basic --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /etc/hyperledger/fabric/tls/ca.crt -c '{"Args":["CreateAsset","asset7","white", "15", "zxl", "800"]}'

//UpdateAsset
peer chaincode invoke -o orderer1.example.com:7050 --tls --cafile ./organizations/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem   -C netchannel -n basic --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /etc/hyperledger/fabric/tls/ca.crt -c '{"Args":["UpdateAsset","asset7","zxl", "1218", "zxl", "800"]}'

//ReadAsset
peer chaincode query -C netchannel -n basic -c '{"Args":["ReadAsset","asset7"]}'



其他链码

  1. 部署链码basic

cd src
peer lifecycle chaincode package abstore.tar.gz --lang node --label abstore_1.0 --path ../javascript/ 
peer lifecycle chaincode install basic.tar.gz

output:
2021-03-19 08:36:51.127 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: basic_1.0:87399a8496d498a8aedfe4cd7a4e469b7d6c9649a267499c5814bfe9b555e552

peer lifecycle chaincode queryinstalled

output:
Installed chaincodes on peer:
Package ID: basic_1.0:87399a8496d498a8aedfe4cd7a4e469b7d6c9649a267499c5814bfe9b555e552, Label: basic_1.0


peer lifecycle chaincode approveformyorg -o orderer1.example.com:7050 --tls --cafile ./organizations/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID netchannel --name basic --version 1.0 --sequence 1 --package-id basic_1.0:87399a8496d498a8aedfe4cd7a4e469b7d6c9649a267499c5814bfe9b555e552

output:
2021-03-19 09:07:18.730 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [1a4c1eadee45e74471198075f679e5e0f7d8c805c2195ef99296245271de6e9e] committed with status (VALID) at

peer lifecycle chaincode checkcommitreadiness --channelID netchannel --name basic --version 1.0 --sequence 1 --output json


peer lifecycle chaincode commit -o orderer1.example.com:7050 --tls --cafile ./organizations/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID netchannel --name basic --version 1.0 --sequence 1  --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /etc/hyperledger/fabric/tls/ca.crt 

output:
2021-03-19 09:19:17.260 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [51bb52b67582f9266e7c50789a770b651d2e361023a0f549c0ce728e177b991b] committed with status (VALID) at peer0.org1.example.com:7051

peer lifecycle chaincode querycommitted --channelID netchannel --name basic

output:
Committed chaincode definition for chaincode 'basic' on channel 'netchannel':
Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true]
  1. 调用链码
#调用链码

peer chaincode invoke -o orderer1.example.com:7050 --tls --cafile ./organizations/ordererOrganizations/example.com/orderers/orderer1.example.com/msp/tlscacerts/tlsca.example.com-cert.pem   -C netchannel -n basic --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /etc/hyperledger/fabric/tls/ca.crt -c '{"Args":["InitLedger"]}'

#查询链码
peer chaincode query -C netchannel -n basic -c '{"Args":["GetAllAssets"]}'

上一篇下一篇

猜你喜欢

热点阅读