您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)HyperLedger Fabric如何使用,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
系統(tǒng)信息:
Linux ubuntu 4.15.0-29-generic
go version go1.10.1 linux/amd64
Docker version 18.06.0-ce-dev
docker-compose version 1.21.1
node-v8.11.3
npm 5.6.0
java version "1.8.0_161"
Apache Maven 3.5.3
docker加速器 docker-cn
nnodejs加速器 淘寶NPM鏡像
golang國內(nèi)鏡像 Go中文網(wǎng)
環(huán)境變量設(shè)置
#jdk export JAVA_HOME=/opt/jdk1.8.0_161 export CLASSPATH=${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib export PATH=${JAVA_HOME}/bin:${PATH} #maven export MAVEN_HOME=/opt/apache-maven-3.5.3 export PATH=${MAVEN_HOME}/bin:${PATH} # #全局命令 export SHELL_HOME=/opt/shell export PATH=${SHELL_HOME}:${PATH} #nodejs export NODE_HOME=/opt/node-v8.11.3-linux-x64 export NODE_PATH=${NODE_HOME}/lib/node_modules export PATH=${NODE_HOME}/bin:${PATH} alias cnpm="npm --registry=https://registry.npm.taobao.org --cache=${HOME}/.npm/.cache/cnpm --disturl=https://npm.taobao.org/dist --userconfig=${HOME}/.cnpmrc" #go export GOPATH=${HOME}/go export PATH=${GOPATH}/bin:${PATH} #fabric export PATH=${HOME}/fabric-samples/bin:${PATH}
*注意:*具體配置請(qǐng)配置成自己的路徑
為了快速構(gòu)建,不用該太多腳本路徑,請(qǐng)保持在$HOME目錄下
cd ~/
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/release-1.3/scripts/bootstrap.sh -o bootstrap.sh chmod +x bootstrap.sh ./bootstrap.sh
如果github下載速度慢:
sed -i 's#https://github.com/hyperledger/fabric-samples.git#git@gitee.com:fansinZhao/fabric-samples.git#g' bootstrap.sh
如果其他資源下載安裝包慢,請(qǐng)?jiān)L問 fabric離線包
耐心等待下載,下載成功后顯示如下
===> List out hyperledger docker images hyperledger/fabric-ca 1.2.0 66cc132bd09c 4 weeks ago 252MB hyperledger/fabric-ca latest 66cc132bd09c 4 weeks ago 252MB hyperledger/fabric-tools 1.2.0 379602873003 4 weeks ago 1.51GB hyperledger/fabric-tools latest 379602873003 4 weeks ago 1.51GB hyperledger/fabric-ccenv 1.2.0 6acf31e2d9a4 4 weeks ago 1.43GB hyperledger/fabric-ccenv latest 6acf31e2d9a4 4 weeks ago 1.43GB hyperledger/fabric-orderer 1.2.0 4baf7789a8ec 4 weeks ago 152MB hyperledger/fabric-orderer latest 4baf7789a8ec 4 weeks ago 152MB hyperledger/fabric-peer 1.2.0 82c262e65984 4 weeks ago 159MB hyperledger/fabric-peer latest 82c262e65984 4 weeks ago 159MB hyperledger/fabric-zookeeper 0.4.10 2b51158f3898 5 weeks ago 1.44GB hyperledger/fabric-zookeeper latest 2b51158f3898 5 weeks ago 1.44GB hyperledger/fabric-kafka 0.4.10 936aef6db0e6 5 weeks ago 1.45GB hyperledger/fabric-kafka latest 936aef6db0e6 5 weeks ago 1.45GB hyperledger/fabric-couchdb 0.4.10 3092eca241fc 5 weeks ago 1.61GB hyperledger/fabric-couchdb latest 3092eca241fc 5 weeks ago 1.61GB
執(zhí)行完需要刷新一下環(huán)境變量
source /etc/profile
或者注銷重啟
cd ~/fabric-samples/first-network ./byfn.sh generate ./byfn.sh up
一切順利的話,顯示下面的內(nèi)容
===================== Query successful on peer1.org2 on channel 'mychannel' ===================== ========= All GOOD, BYFN execution completed ===========
關(guān)閉的話
./byfn.sh down _____ _ _ ____ | ____| | \ | | | _ \ | _| | \| | | | | | | |___ | |\ | | |_| | |_____| |_| \_| |____/
cd ~/fabric-samples/fabcar ./startFabric.sh npm install npm audit fix node enrollAdmin.js node registerUser.js node invoke.js node query.js
正常執(zhí)行完畢后,會(huì)在目錄$HOME/fabric-samples/fabcar/hfc-key-store
下有文件存在.類似下面
zhaofeng[@ubuntu](https://my.oschina.net/u/555627):~/fabric-samples/fabcar$ tree hfc-key-store/ hfc-key-store/ ├── 51da36ca8deb87c1cefa30ae686c5addb67cff53739b859c63ba708581cb6640-priv ├── 51da36ca8deb87c1cefa30ae686c5addb67cff53739b859c63ba708581cb6640-pub ├── 95d4a6c61e4b503269b5d525e2c876c22cf0038bfa8b3396f3d5f8a5c53055a8-priv ├── 95d4a6c61e4b503269b5d525e2c876c22cf0038bfa8b3396f3d5f8a5c53055a8-pub ├── admin └── user1 0 directories, 6 files
使用docker查看鏡像
zhaofeng[@ubuntu](https://my.oschina.net/u/555627):~/fabric-samples/fabcar$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f2aa240d4298 dev-peer0.org1.example.com-marbles-v4-f704f1411b52539123b5920f0c3d59dc4c88aa255a82cd002be690a5a6a8150e "chaincode -peer.add…" 8 hours ago Up 8 hours dev-peer0.org1.example.com-marbles-v4 127aac75b9bb dev-peer0.org1.example.com-fabcar-1.0-5c906e402ed29f20260ae42283216aa75549c571e2e380f3615826365d8269ba "chaincode -peer.add…" 8 hours ago Up 8 hours dev-peer0.org1.example.com-fabcar-1.0 d9d7172e9043 hyperledger/fabric-tools "/bin/bash" 8 hours ago Up 8 hours cli 04bcf025450c hyperledger/fabric-peer "peer node start" 8 hours ago Up 8 hours 0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp peer0.org1.example.com 2ddca7b27e38 hyperledger/fabric-ca "sh -c 'fabric-ca-se…" 8 hours ago Up 8 hours 0.0.0.0:7054->7054/tcp ca.example.com 5454667897c4 hyperledger/fabric-couchdb "tini -- /docker-ent…" 8 hours ago Up 8 hours 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp couchdb 0a23230a291e hyperledger/fabric-orderer "orderer" 8 hours ago Up 8 hours 0.0.0.0:7050->7050/tcp orderer.example.com
注意:npm install
執(zhí)行報(bào)權(quán)限錯(cuò)誤,使用npm install --unsafe-perm=true
到此步驟,fabric local環(huán)境已經(jīng)初始化.下面安裝IBM marbles
cd ~ git clone git@github.com:IBM-Blockchain/marbles.git --depth 1
修改配置文件marbles/config/connection_profile_local.json
"client": { "organization": "Org1MSP", "credentialStore": { "path": "/$HOME/.hfc-key-store" } }
將$HOME/fabric-samples/fabcar/hfc-key-store復(fù)制一份到$HOME/.hfc-key-store,這一步是解決一個(gè)bug
cp -r $HOME/fabric-samples/fabcar/hfc-key-store $HOME/.hfc-key-store
修改配置文件marbles/config/marbles_local.json
"use_events": false,
不然系統(tǒng)會(huì)報(bào)錯(cuò). 修改完配置文件,就可以執(zhí)行安裝代碼了
cd marbles/ npm install npm audit fix cd scripts/ node install_chaincode.js node instantiate_chaincode.js npm install gulp -g npm install npm audit fix gulp marbles_local
正常啟動(dòng)后訪問http://localhost:3001/home. 其他細(xì)節(jié)參考官方文檔
下載主線代碼
cd ~ git clone https://github.com/hyperledger/fabric.git
或者 cd ~ git clone https://gitee.com/fansinZhao/fabric.git
下載完畢后 cd fabric git checkout -b v1.2.0 cp -r ../fabric $GOPATH/src/github.com/hyperledger/fabric sudo ./network_setup.sh up
正常顯示下面內(nèi)容
2018-08-15 08:41:55.473 UTC [bccsp] GetDefault -> WARN 02d Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP. 2018-08-15 08:41:55.473 UTC [msp] Sign -> DEBU 02e Idemix identity &{Org3MSP x: "\004\0249R\035\017$$\251n \023\352\365\250j\201\354\316\255\200\035\325E\001r\347\257\311\347\2230" y: "z\014\025O\\\301\233\231\3773\342\372]TO\327\003Xer4\221\267\"VI}\203\345\2260W" } is signing Error: error endorsing query: rpc error: code = Unknown desc = Failed evaluating policy on signed data during check policy on channel [mychannel] with policy [/Channel/Application/Writers]: [Failed to reach implicit threshold of 1 sub-policies, required 1 remaining] - proposal response: <nil> ===================== Query successful on peer1.org3 on channel 'mychannel' ===================== ===================== All GOOD, End-2-End execution completed ===================== _____ _ _ ____ _____ ____ _____ | ____| | \ | | | _ \ | ____| |___ \ | ____| | _| | \| | | | | | _____ | _| __) | | _| | |___ | |\ | | |_| | |_____| | |___ / __/ | |___ |_____| |_| \_| |____/ |_____| |_____| |_____|
關(guān)閉執(zhí)行
sudo ./network_setup.sh down
*注意:*使用sudo,不然order會(huì)啟動(dòng)異常
關(guān)于“HyperLedger Fabric如何使用”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。