http://hyperledger-fabric.readthedocs.io/en/release-1.2/java
注意: 本博客只爲了記錄我的對HyperLedger Fabric的學習,因此省略go,docker,docker-compose,nodejs,python,maven,jdk等基本軟件的安裝和使用,詳細使用請參考相關文檔node
系統信息:python
Linux ubuntu 4.15.0-29-genericlinux
go version go1.10.1 linux/amd64git
Docker version 18.06.0-ce-devgithub
docker-compose version 1.21.1golang
node-v8.11.3docker
npm 5.6.0shell
java version "1.8.0_161"apache
Apache Maven 3.5.3
docker加速器 docker-cn
nnodejs加速器 淘寶NPM鏡像
golang國內鏡像 Go中文網
環境變量設置
#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}
*注意:*具體配置請配置成本身的路徑
爲了快速構建,不用該太多腳本路徑,請保持在$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
若是其餘資源下載安裝包慢,請訪問 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
執行完須要刷新一下環境變量
source /etc/profile
或者註銷重啓
cd ~/fabric-samples/first-network ./byfn.sh generate ./byfn.sh up
一切順利的話,顯示下面的內容
===================== Query successful on peer1.org2 on channel 'mychannel' ===================== ========= All GOOD, BYFN execution completed ===========
關閉的話
./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
正常執行完畢後,會在目錄$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
執行報權限錯誤,使用npm install --unsafe-perm=true
到此步驟,fabric local環境已經初始化.下面安裝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複製一份到$HOME/.hfc-key-store,這一步是解決一個bug
cp -r $HOME/fabric-samples/fabcar/hfc-key-store $HOME/.hfc-key-store
修改配置文件marbles/config/marbles_local.json
"use_events": false,
否則系統會報錯. 修改完配置文件,就能夠執行安裝代碼了
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
正常啓動後訪問http://localhost:3001/home. 其餘細節參考官方文檔
下載主線代碼
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
正常顯示下面內容
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 ===================== _____ _ _ ____ _____ ____ _____ | ____| | \ | | | _ \ | ____| |___ \ | ____| | _| | \| | | | | | _____ | _| __) | | _| | |___ | |\ | | |_| | |_____| | |___ / __/ | |___ |_____| |_| \_| |____/ |_____| |_____| |_____|
關閉執行
sudo ./network_setup.sh down
*注意:*使用sudo,否則order會啓動異常