您好,登錄后才能下訂單哦!
目錄
一.通過自動化腳本啟動服務(wù)
自動化腳本byfn.sh位于目錄$HOME/hyfa/fabric-samples/first-network下,具體用途如下
$./byfn.sh -h //查看幫助說明
Usage:
byfn.sh <mode> [-c <channel name>] [-t <timeout>] [-d <delay>] [-f <docker-compose-file>] [-s <dbtype>] [-l <language>] [-i <imagetag>] [-v]
<mode> - one of 'up', 'down', 'restart', 'generate' or 'upgrade'
- 'up' - bring up the network with docker-compose up
- 'down' - clear the network with docker-compose down
- 'restart' - restart the network
- 'generate' - generate required certificates and genesis block
- 'upgrade' - upgrade the network from version 1.1.x to 1.2.x
-c <channel name> - channel name to use (defaults to "mychannel")
-t <timeout> - CLI timeout duration in seconds (defaults to 10)
-d <delay> - delay duration in seconds (defaults to 3)
-f <docker-compose-file> - specify which docker-compose file use (defaults to docker-compose-cli.yaml)
-s <dbtype> - the database backend to use: goleveldb (default) or couchdb
-l <language> - the chaincode language: golang (default) or node
-i <imagetag> - the tag to be used to launch the network (defaults to "latest")
-v - verbose mode
byfn.sh -h (print this message)
Typically, one would first generate the required certificates and
genesis block, then bring up the network. e.g.:
byfn.sh generate -c mychannel
byfn.sh up -c mychannel -s couchdb
byfn.sh up -c mychannel -s couchdb -i 1.2.x
byfn.sh up -l node
byfn.sh down -c mychannel
byfn.sh upgrade -c mychannel
Taking all defaults:
byfn.sh generate
byfn.sh up
byfn.sh down
1.生成組織結(jié)構(gòu)及×××?xí)?/p>
$ sudo ./byfn.sh generate
生成組織結(jié)構(gòu)及×××?xí)?保存在當(dāng)前目錄的crypto-config目錄)
drwxr-xr-x 3 root root 4096 Jul 11 11:26 ordererOrganizations
drwxr-xr-x 4 root root 4096 Jul 11 11:26 peerOrganizations
生成Orderer創(chuàng)世區(qū)塊文件(保存在當(dāng)前目錄的chanel-artifacts目錄下)
$HOME/hyfa/fabric-samples/first-network/channel-artifacts/genesis.block
生成應(yīng)用通道交易配置文件(保存在當(dāng)前目錄的chanel-artifacts目錄下)
$HOME/hyfa/fabric-samples/first-network/channel-artifacts/channel.tx
組織中錨節(jié)點更新配置文件(保存在當(dāng)前目錄的chanel-artifacts目錄下)
--檢測當(dāng)前應(yīng)用通道中新加入的節(jié)點
--跨組織的數(shù)據(jù)交換
Org1MSPanchors.tx
Org2MSPanchors.tx
2.創(chuàng)建容器與通道
$sudo ./byfn.sh up
列出新拉取(pull)的docker鏡像
dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab latest 526ebbb4eccd 44 seconds ago 147MB
dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9 latest ba6eb425f830 57 seconds ago 147MB
dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b latest b582a75829b3 About a minute ago 147MB
列出新創(chuàng)建的docker容器名稱
$sudo docker ps |awk '{print $NF}' |grep -v NAMES|sort
====返回結(jié)果====
cli
dev-peer0.org1.example.com-mycc-1.0
dev-peer0.org2.example.com-mycc-1.0
dev-peer1.org2.example.com-mycc-1.0
orderer.example.com
peer0.org1.example.com
peer0.org2.example.com
peer1.org1.example.com
peer1.org2.example.com
創(chuàng)建通道m(xù)ychannel
Channel name : mychannel
Creating channel...
節(jié)點加入通道
Having all peers join the channel...
set +x
2018-07-11 06:42:21.742 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-07-11 06:42:21.867 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer0.org1 joined channel 'mychannel' =====================
set +x
2018-07-11 06:42:24.942 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-07-11 06:42:25.053 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer1.org1 joined channel 'mychannel' =====================
set +x
2018-07-11 06:42:28.129 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-07-11 06:42:28.232 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer0.org2 joined channel 'mychannel' =====================
3.生成錨節(jié)點配置
Updating anchor peers for org1...
+ peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.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
+ res=0
+ set +x
2018-07-11 06:42:34.493 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-07-11 06:42:34.504 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org 'Org1MSP' on channel 'mychannel' =====================
Updating anchor peers for org2...
+ peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.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
+ res=0
+ set +x
2018-07-11 06:42:37.574 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-07-11 06:42:37.586 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org 'Org2MSP' on channel 'mychannel' =====================
4.在節(jié)點上安裝鏈碼并實例化
Installing chaincode on peer0.org1...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
2018-07-11 06:42:40.666 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2018-07-11 06:42:40.666 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2018-07-11 06:42:40.969 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
===================== Chaincode is installed on peer0.org1 =====================
Install chaincode on peer0.org2...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
2018-07-11 06:42:41.051 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2018-07-11 06:42:41.051 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2018-07-11 06:42:41.240 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
===================== Chaincode is installed on peer0.org2 =====================
Instantiating chaincode on peer0.org2...
+ 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 mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'AND ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'
+ res=0
+ set +x
2018-07-11 06:42:41.306 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2018-07-11 06:42:41.306 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
===================== Chaincode is instantiated on peer0.org2 on channel 'mychannel' =====================
5.調(diào)用鏈碼對賬本數(shù)據(jù)進行操作
Querying chaincode on peer0.org1...
===================== Querying on peer0.org1 on channel 'mychannel'... =====================
Attempting to Query peer0.org1 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x
100
===================== Query successful on peer0.org1 on channel 'mychannel' =====================
Sending invoke transaction on peer0.org1 peer0.org2...
+ 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 mycc --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 -c '{"Args":["invoke","a","b","10"]}'
+ res=0
+ set +x
2018-07-11 06:43:08.200 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' =====================
Installing chaincode on peer1.org2...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
2018-07-11 06:43:08.271 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2018-07-11 06:43:08.271 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2018-07-11 06:43:08.449 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
===================== Chaincode is installed on peer1.org2 =====================
Querying chaincode on peer1.org2...
===================== Querying on peer1.org2 on channel 'mychannel'... =====================
Attempting to Query peer1.org2 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x
90
===================== Query successful on peer1.org2 on channel 'mychannel' =====================
自動化腳本執(zhí)行完畢
========= All GOOD, BYFN execution completed ===========
_____ _ _ ____
| ____| | \ | | | _ \
| _| | \| | | | | |
| |___ | |\ | | |_| |
|_____| |_| \_| |____/
6.關(guān)閉服務(wù)
$sudo ./byfn.sh down //通過down參數(shù)關(guān)閉服務(wù)
二.通過手動方式啟動服務(wù)
在實際的應(yīng)用場景下,我們會經(jīng)常對某些配置進行個性化定制,以滿足實際生產(chǎn)需求,所以,我們在本小節(jié)介紹如何通過手動方式啟動對應(yīng)的服務(wù),并通過修改相關(guān)配置文件滿足實際場景,手動步驟與自動化腳本基本一致。
1.生成組織結(jié)構(gòu)及×××?xí)?/p>
$ cd hyfa/fabric-samples/first-network/
為fabric網(wǎng)絡(luò)生成指定拓撲結(jié)構(gòu)的組織關(guān)系和×××?xí)?/p>
$ sudo ../bin/cryptogen generate --config=./crypto-config.yaml
此命令依賴 crypto-config.yaml 配置文件
命令輸出
org1.example.com
org2.example.com
證書和密鑰(即MSP)將被輸出到目錄 first-network/crypto-config 的目錄中
drwxr-xr-x 3 root root 4096 Jul 11 00:31 ordererOrganizations
drwxr-xr-x 4 root root 4096 Jul 11 00:31 peerOrganizations
peerOrganizations
所有的Peer節(jié)點組織(2個組織, 4個節(jié)點)的相關(guān)身份信息. 其中最關(guān)鍵的是MSP目錄, 代表了實體的身份信息
$ tree -L 6 crypto-config //通過tree命令查看目錄樹
crypto-config
├── ordererOrganizations
│?? └── example.com
│?? ├── ca
│?? │?? ├── ca.example.com-cert.pem
│?? │?? └── ded244dc5aa11c2b42e43fa4de6b952259078c78131fc86031a02baff21abd78_sk
│?? ├── msp
│?? │?? ├── admincerts
│?? │?? │?? └── Admin@example.com-cert.pem
│?? │?? ├── cacerts
│?? │?? │?? └── ca.example.com-cert.pem
│?? │?? └── tlscacerts
│?? │?? └── tlsca.example.com-cert.pem
│?? ├── orderers
│?? │?? └── orderer.example.com
│?? │?? ├── msp
│?? │?? │?? ├── admincerts
│?? │?? │?? ├── cacerts
│?? │?? │?? ├── keystore
│?? │?? │?? ├── signcerts
│?? │?? │?? └── tlscacerts
│?? │?? └── tls
│?? │?? ├── ca.crt
│?? │?? ├── server.crt
│?? │?? └── server.key
│?? ├── tlsca
│?? │?? ├── 1e1955762d0669ba18f078a04ac7b19918f40554aeddd6841dc6c059eefbbcf9_sk
│?? │?? └── tlsca.example.com-cert.pem
│?? └── users
│?? └── Admin@example.com
│?? ├── msp
│?? │?? ├── admincerts
│?? │?? ├── cacerts
│?? │?? ├── keystore
│?? │?? ├── signcerts
│?? │?? └── tlscacerts
│?? └── tls
│?? ├── ca.crt
│?? ├── client.crt
│?? └── client.key
└── peerOrganizations
├── org1.example.com # 第一個組織的相關(guān)材料,每個組織會生成單獨的根證書
│?? ├── ca #存放組織的根證書和對應(yīng)的私鑰文件,默認采用EC算法,證書為自簽名。為根證書。
│?? │?? ├── 15d058166d13e584fca35523a71a12b2fbaf6de5072d3661801476dfbfb3ea4f_sk
│?? │?? └── ca.org1.example.com-cert.pem
│?? ├── msp #存放代表該組織的身份信息
│?? │?? ├── admincerts #組織管理員的身份驗證證書,被根證書簽名
│?? │?? │?? └── Admin@org1.example.com-cert.pem
│?? │?? ├── cacerts #組織的根證書,同CA目錄下文件
│?? │?? │?? └── ca.org1.example.com-cert.pem
│?? │?? ├── config.yaml
│?? │?? └── tlscacerts #用于TLS的CA 證書,自簽名
│?? │?? └── tlsca.org1.example.com-cert.pem
│?? ├── peers # 存放屬于該組織的所有Peer節(jié)點
│?? │?? ├── peer0.org1.example.com #第一個peer的信息,包括其msp證書和tls 證書兩類
│?? │?? │?? ├── msp
│?? │?? │?? │?? ├── admincerts#組織管理員的身份驗證證書。Peer將基于這些證書來認證交易簽署者是否為管理員身份
│?? │?? │?? │?? ├── cacerts #存放組織的根證書
│?? │?? │?? │?? ├── config.yaml
│?? │?? │?? │?? ├── keystore #本節(jié)點的身份私鑰,用來簽名
│?? │?? │?? │?? ├── signcerts #驗證本節(jié)點簽名的證書,被組織根證書簽名
│?? │?? │?? │?? └── tlscacerts #TLS 連接用的×××?xí)?,即組織TLS 證書
│?? │?? │?? └── tls # 存放tls相關(guān)的證書和私鑰
│?? │?? │?? ├── ca.crt #組織的根證書
│?? │?? │?? ├── server.crt #驗證本節(jié)點簽名的證書,被組織根證書簽名
│?? │?? │?? └── server.key #本節(jié)點的身份私鑰,用來簽名
│?? │?? └── peer1.org1.example.com
│?? │?? ├── msp
│?? │?? │?? ├── admincerts
│?? │?? │?? ├── cacerts
│?? │?? │?? ├── config.yaml
│?? │?? │?? ├── keystore
│?? │?? │?? ├── signcerts
│?? │?? │?? └── tlscacerts
│?? │?? └── tls
│?? │?? ├── ca.crt
│?? │?? ├── server.crt
│?? │?? └── server.key
│?? ├── tlsca
│?? │?? ├── d45d38d7d48e3e41332c66d673869080be030c0e76d47cc6c8d6909f89f401e8_sk
│?? │?? └── tlsca.org1.example.com-cert.pem
│?? └── users
│?? ├── Admin@org1.example.com
│?? │?? ├── msp
│?? │?? │?? ├── admincerts
│?? │?? │?? ├── cacerts
│?? │?? │?? ├── keystore
│?? │?? │?? ├── signcerts
│?? │?? │?? └── tlscacerts
│?? │?? └── tls
│?? │?? ├── ca.crt
│?? │?? ├── client.crt
│?? │?? └── client.key
│?? └── User1@org1.example.com
│?? ├── msp
│?? │?? ├── admincerts
│?? │?? ├── cacerts
│?? │?? ├── keystore
│?? │?? ├── signcerts
│?? │?? └── tlscacerts
│?? └── tls
│?? ├── ca.crt
│?? ├── client.crt
│?? └── client.key
└── org2.example.com
├── ca
│?? ├── 5d261ccc23b0a7345dc3ee387a4714c6ec3261f957d40e82198b1d6141b715a9_sk
│?? └── ca.org2.example.com-cert.pem
├── msp
│?? ├── admincerts
│?? │?? └── Admin@org2.example.com-cert.pem
│?? ├── cacerts
│?? │?? └── ca.org2.example.com-cert.pem
│?? ├── config.yaml
│?? └── tlscacerts
│?? └── tlsca.org2.example.com-cert.pem
├── peers
│?? ├── peer0.org2.example.com
│?? │?? ├── msp
│?? │?? │?? ├── admincerts
│?? │?? │?? ├── cacerts
│?? │?? │?? ├── config.yaml
│?? │?? │?? ├── keystore
│?? │?? │?? ├── signcerts
│?? │?? │?? └── tlscacerts
│?? │?? └── tls
│?? │?? ├── ca.crt
│?? │?? ├── server.crt
│?? │?? └── server.key
│?? └── peer1.org2.example.com
│?? ├── msp
│?? │?? ├── admincerts
│?? │?? ├── cacerts
│?? │?? ├── config.yaml
│?? │?? ├── keystore
│?? │?? ├── signcerts
│?? │?? └── tlscacerts
│?? └── tls
│?? ├── ca.crt
│?? ├── server.crt
│?? └── server.key
├── tlsca
│?? ├── c16ccfac347d187e318e38de956036528f29e542c4cb2451dafd0d33b44efebf_sk
│?? └── tlsca.org2.example.com-cert.pem
└── users
├── Admin@org2.example.com
│?? ├── msp
│?? │?? ├── admincerts
│?? │?? ├── cacerts
│?? │?? ├── keystore
│?? │?? ├── signcerts
│?? │?? └── tlscacerts
│?? └── tls
│?? ├── ca.crt
│?? ├── client.crt
│?? └── client.key
└── User1@org2.example.com
├── msp
│?? ├── admincerts
│?? ├── cacerts
│?? ├── keystore
│?? ├── signcerts
│?? └── tlscacerts
└── tls
├── ca.crt
├── client.crt
└── client.key
Cryptogen 按照配置文件中指定的結(jié)構(gòu)生成了對應(yīng)的組織和密鑰、證書文件
其中最關(guān)鍵的是各個資源下的msp 目錄內(nèi)容,存儲了生成的代表MSP 身份的各種證書文件,一般包括:
這些身份文件隨后可以分發(fā)到對應(yīng)的Orderer 節(jié)點和Peer 節(jié)點上,并放到對應(yīng)的MSP路徑下,用于簽名使用。
2.創(chuàng)建創(chuàng)世區(qū)塊并啟動Orderer
指定使用 configtx.yaml 文件中定義的 TwoOrgsOrdererGenesis 模板, 生成Orderer服務(wù)系統(tǒng)通道的初始區(qū)塊文件
$ sudo ../bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
命令輸出
2018-07-11 00:52:00.625 PDT [common/tools/configtxgen] main -> WARN 001 Omitting the channel ID for configtxgen is deprecated. Explicitly passing the channel ID will be required in the future, defaulting to 'testchainid'.
2018-07-11 00:52:00.625 PDT [common/tools/configtxgen] main -> INFO 002 Loading configuration
2018-07-11 00:52:00.632 PDT [common/tools/configtxgen/encoder] NewChannelGroup -> WARN 003 Default policy emission is deprecated, please include policy specificiations for the channel group in configtx.yaml
2018-07-11 00:52:00.632 PDT [common/tools/configtxgen/encoder] NewOrdererGroup -> WARN 004 Default policy emission is deprecated, please include policy specificiations for the orderer group in configtx.yaml
2018-07-11 00:52:00.632 PDT [common/tools/configtxgen/encoder] NewOrdererOrgGroup -> WARN 005 Default policy emission is deprecated, please include policy specificiations for the orderer org group OrdererOrg in configtx.yaml
2018-07-11 00:52:00.634 PDT [msp] getMspConfig -> INFO 006 Loading NodeOUs
2018-07-11 00:52:00.634 PDT [common/tools/configtxgen/encoder] NewOrdererOrgGroup -> WARN 007 Default policy emission is deprecated, please include policy specificiations for the orderer org group Org1MSP in configtx.yaml
2018-07-11 00:52:00.635 PDT [msp] getMspConfig -> INFO 008 Loading NodeOUs
2018-07-11 00:52:00.635 PDT [common/tools/configtxgen/encoder] NewOrdererOrgGroup -> WARN 009 Default policy emission is deprecated, please include policy specificiations for the orderer org group Org2MSP in configtx.yaml
2018-07-11 00:52:00.635 PDT [common/tools/configtxgen] doOutputBlock -> INFO 00a Generating genesis block
2018-07-11 00:52:00.635 PDT [common/tools/configtxgen] doOutputBlock -> INFO 00b Writing genesis block
$ ls channel-artifacts/
-rw-r--r-- 1 root root 12655 Jul 11 00:52 channel-artifacts/genesis.block //生成的創(chuàng)世區(qū)塊
3.生成應(yīng)用通道交易配置文件
$ export CHANNEL_NAME=mychannel //設(shè)置臨時變量
指定使用 configtx.yaml 配置文件中的 TwoOrgsChannel 模板, 來生成新建通道的配置交易文件, TwoOrgsChannel 模板指定了Org1和Org2都屬于后面新建的應(yīng)用通道
$ sudo ../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
命令輸出
2018-07-11 00:54:21.557 PDT [common/tools/configtxgen] main -> INFO 001 Loading configuration
2018-07-11 00:54:21.563 PDT [common/tools/configtxgen] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
2018-07-11 00:54:21.563 PDT [common/tools/configtxgen/encoder] NewApplicationGroup -> WARN 003 Default policy emission is deprecated, please include policy specificiations for the application group in configtx.yaml
2018-07-11 00:54:21.563 PDT [msp] getMspConfig -> INFO 004 Loading NodeOUs
2018-07-11 00:54:21.564 PDT [common/tools/configtxgen/encoder] NewApplicationOrgGroup -> WARN 005 Default policy emission is deprecated, please include policy specificiations for the application org group Org1MSP in configtx.yaml
2018-07-11 00:54:21.564 PDT [msp] getMspConfig -> INFO 006 Loading NodeOUs
2018-07-11 00:54:21.564 PDT [common/tools/configtxgen/encoder] NewApplicationOrgGroup -> WARN 007 Default policy emission is deprecated, please include policy specificiations for the application org group Org2MSP in configtx.yaml
2018-07-11 00:54:21.565 PDT [common/tools/configtxgen] doOutputChannelCreateTx -> INFO 008 Writing new channel tx
$ ll channel-artifacts/channel.tx
-rw-r--r-- 1 root root 346 Jul 11 00:54 channel-artifacts/channel.tx //生成的通道文件
4.生成各組織的錨節(jié)點更新文件
錨節(jié)點配置更新文件用來對組織的錨節(jié)點進行配置
同樣基于 configtx.yaml 配置文件生成新建通道文件, 每個組織都需要分別生成且注意指定對應(yīng)的組織名稱
$ sudo ../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
$ sudo ../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
命令輸出
2018-07-11 00:57:34.629 PDT [common/tools/configtxgen] main -> INFO 001 Loading configuration
2018-07-11 00:57:34.635 PDT [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2018-07-11 00:57:34.635 PDT [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
2018-07-11 00:57:40.028 PDT [common/tools/configtxgen] main -> INFO 001 Loading configuration
2018-07-11 00:57:40.037 PDT [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2018-07-11 00:57:40.037 PDT [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
5.創(chuàng)建容器,啟動網(wǎng)絡(luò)
$ sudo docker-compose -f docker-compose-cli.yaml up -d
-f: 指定docker-compose文件
-d:Detached mode,后臺運行容器
命令輸出
Creating network "net_byfn" with the default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating volume "net_peer1.org2.example.com" with default driver
Creating volume "net_peer1.org1.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_orderer.example.com" with default driver
Creating peer1.org1.example.com ...
Creating peer1.org2.example.com ...
Creating peer0.org2.example.com ...
Creating orderer.example.com ...
Creating peer0.org1.example.com ...
Creating orderer.example.com
Creating peer0.org2.example.com
Creating peer0.org1.example.com
Creating peer1.org1.example.com
Creating peer1.org2.example.com ... done
Creating cli ...
Creating cli ... done
查看創(chuàng)建的docker容器
生成的docker容器名稱
cli
peer1.org2.example.com
peer1.org1.example.com
peer0.org2.example.com
peer0.org1.example.com
orderer.example.com
6.創(chuàng)建通道并配置
執(zhí)行如下命令進入到CLI容器中(后繼操作都在容器中執(zhí)行)
$ sudo docker exec -it cli bash
直接進入容器該路徑下,相關(guān)操作不要更換路徑
root@138a8115a08c:/opt/gopath/src/github.com/hyperledger/fabric/peer# pwd
/opt/gopath/src/github.com/hyperledger/fabric/peer
6.1 配置變量
export CHANNEL_NAME=mychannel
6.2 創(chuàng)建通道
$ 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
命令返回:
2018-07-11 11:44:50.198 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-07-11 11:44:50.228 UTC [cli/common] readBlock -> INFO 002 Got status: &{NOT_FOUND}
2018-07-11 11:44:50.232 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-07-11 11:44:50.436 UTC [cli/common] readBlock -> INFO 004 Received block: 0
該命令自動在本地生成與該應(yīng)用通道同名的初始區(qū)塊 mychannel.block, 只有擁有該文件才可以加入創(chuàng)建的應(yīng)用通道中
參數(shù)說明:
-o: 指定orderer節(jié)點的地址
-c: 指定要創(chuàng)建的應(yīng)用通道的名稱(必須與在創(chuàng)建應(yīng)用通道交易配置文件時的通道名稱保持一致)
-f: 指定創(chuàng)建應(yīng)用通道時所使用的應(yīng)用通道交易配置文件
--tls: 開啟TLS驗證
--cafile: 指定TLS_CA證書路徑
查看生成的文件
root@138a8115a08c:/opt/gopath/src/github.com/hyperledger/fabric/peer# ll
total 36
drwxr-xr-x 5 root root 4096 Jul 11 11:44 ./
drwxr-xr-x 3 root root 4096 Jul 11 08:00 ../
drwxrwxr-x 2 1000 1000 4096 Jul 11 07:57 channel-artifacts/
drwxr-xr-x 4 root root 4096 Jul 11 07:31 crypto/
-rw-r--r-- 1 root root 15671 Jul 11 11:44 mychannel.block
drwxrwxr-x 2 1000 1000 4096 Jul 10 07:59 scripts/
6.3 當(dāng)前節(jié)點加入通道
應(yīng)用通道所包含組織的成員節(jié)點可以加入通道中
$ peer channel join -b mychannel.block
join命令: 將本Peer節(jié)點加入到某個應(yīng)用通道中
命令返回
2018-07-11 13:20:01.980 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-07-11 13:20:02.084 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
查看加入列表
$ peer channel list
Channels peers has joined:
mychannel
6.4更新錨節(jié)點
錨節(jié)點通過廣播的方式通知有新節(jié)點加入
使用Org1的管理員身份更新錨節(jié)點配置(默認)
$ 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
命令返回
2018-07-11 12:00:12.677 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-07-11 12:00:12.690 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
變更腳本變量(比如當(dāng)前變量CORE_PEER_LOCALMSPID默認為Org1MSP)
CORE_PEER_LOCALMSPID="Org2MSP"
CORE_PEER_ADDRESS=peer0.org2.example.com:7051
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
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
執(zhí)行更新錨節(jié)點配置命令
$ 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
命令返回
2018-07-11 12:05:37.325 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2018-07-11 12:05:37.338 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
如果需要加入其它組織,變更腳本變量后執(zhí)行更新錨節(jié)點操作即可,至此,手動配置網(wǎng)絡(luò)完成, 可以測試鏈碼ChainCode
切換:pee1.org1.example.com
CORE_PEER_LOCALMSPID="Org1MSP"
CORE_PEER_ADDRESS=peer1.org1.example.com:7051
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabri c/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.exa mple.com/msp
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fa bric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.exa mple.com/tls/ca.crt
三.測試鏈碼
進去CLI容器進行相關(guān)運維操作
$ sudo docker exec -it cli bash
Peer加入應(yīng)用通道后, 可以執(zhí)行鏈碼相關(guān)操作,進行測試 鏈碼在調(diào)用之前, 必須先經(jīng)過安裝和實例化兩個步驟, 部署到Peer節(jié)點上.
1.查看并環(huán)境變量
$ echo $CORE_PEER_LOCALMSPID #確認當(dāng)前指定的org
Org1MSP
$ echo $CORE_PEER_ADDRESS #確認當(dāng)前指定的peer
peer0.org1.example.com:7051
$ export CHANNEL_NAME=mychannel #設(shè)置通道名稱
2.安裝并實例化鏈碼
2.1 鏈碼使用須知
-- 將其安裝在指定的節(jié)點上
-- 安裝完成后要對其進行實例化
-- 調(diào)用鏈碼(查詢, 執(zhí)行事務(wù))
2.2 安裝并實例化鏈碼
安裝鏈碼
$ peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
參數(shù)說明:
-n: 指定要安裝的鏈碼的名稱
-v: 指定鏈碼的版本
-p: 指定要安裝的鏈碼的所在路徑,注意不要寫絕對路徑
命令返回:
2018-07-11 13:01:11.090 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2018-07-11 13:01:11.090 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2018-07-11 13:01:11.351 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
實例化鏈碼
$ 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 "OR('Org1MSP.peer','Org2MSP.peer')"
參數(shù)說明:
-o: 指定Oderer節(jié)點地址
--tls: 開啟TLS驗證
--cafile: 指定TLS_CA證書路
-n: 指定要實例化的鏈碼名稱
-v: 指定要實例化的鏈碼的版本號
-C: 指定通道名稱
-c: 實例化鏈碼時指定的參數(shù)
("init","a", "100", "b","200":設(shè)置a賬戶初始化金額為100,b賬戶的初始金額為200)
-P: 指定背書策略(指定交易在哪些節(jié)點上面進行簽名)
命令返回:
2018-07-11 13:21:13.234 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2018-07-11 13:21:13.234 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
3.代碼調(diào)用測試
3.1 查詢賬戶余額
$ peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' #查詢a賬戶余額
100
$ peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","b"]}' #查詢b賬戶余額
200
3.2 轉(zhuǎn)賬測試
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"]}'
參數(shù)說明:
-o: 指定orderer節(jié)點地址
--tls: 開啟TLS驗證
--cafile: 指定TLS_CA證書路徑
-n: 指定鏈碼名稱
-C: 指定通道名稱
-c: 指定調(diào)用鏈碼的所需參數(shù)
func invoke(accoutF string, accountT stirng, amount string)
3.3 查詢當(dāng)前余額
$ peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' #查詢a賬戶余額
90
$ peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","b"]}' #查詢b賬戶余額
210
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。