安裝過程參照Hyperledger Fabric的官方文檔,文檔地址:http://hyperledger-fabric.readthedocs.io/en/latest/prereqs.htmlhtml
0x00 環境介紹,升級系統軟件java
搭建了一個vm,操做系統版本:node
[root@fd240 ~]# cat /proc/version
Linux version 4.11.5-200.fc25.x86_64 (mockbuild@bkernel02.phx2.fedoraproject.org) (gcc version 6.3.1 20161221 (Red Hat 6.3.1-1) (GCC) ) #1 SMP Wed Jun 14 17:17:29 UTC 2017linux
搭建完畢,配置好網絡後,升級系統軟件:git
[root@fd240 ~]# dnf updategithub
0x01 安裝依賴項golang
安裝dockerweb
此步驟參照官方文檔:https://docs.docker.com/engine/installation/linux/fedora/#os-requirementsdocker
基本步驟以下:shell
添加docker的源:
$ sudo dnf config-manager \ --add-repo \ https://download.docker.com/linux/fedora/docker-ce.repo
更新dnf的包的索引:
sudo dnf makecache fast
安裝:
sudo dnf install docker-ce
至少須要 Docker v1.12 以上版本。安裝完以後檢查版本號:
[root@fd240 ~]# docker -v
Docker version 17.03.1-ce, build c6d412e
而後安裝docker-compose:
使用curl方式安裝,安裝過程當中會出錯,安裝過程及解決辦法參考個人這篇博客。
安裝完畢後查看版本號:
[root@fd240 ~]# docker-compose version
docker-compose version 1.14.0-rc2, build 24dae73
docker-py version: 2.3.0
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t 3 May 2016
安裝go:
go的下載須要FQ,我安裝的是這個版本:https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz
下載完畢後,解壓縮:
tar -C /usr/local -xzf go1.8.3.linux-amd64.tar.gz
解壓縮完畢後,配置環境變量:
[root@fd240 ~]# vim /etc/profile
增長下列配置:
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
保存退出後,使之生效:
source /etc/profile
安裝node.js,目前只支持 6.9.x版本的node.js, 可是7.x不支持。
我安裝的是這個版本:https://nodejs.org/dist/v6.11.0/node-v6.11.0.tar.gz
從上面的官方下載地址下載巨慢,我依然選擇了正確的上網姿式。
下載完畢後,解壓縮:
tar -xJvf node-v6.11.0-linux-x64.tar.xz
我是放到$HOME 下的,由於我使用的是root用戶,因此是在/root目錄下。這不是個好習慣,因此操做的時候你必定要謹慎,由於正如Fedora所說」權力越大,責任就越大「。
cd node-v6.11.0-linux-x64/
而後建立軟鏈接:
ln -s /root/node-v6.11.0-linux-x64/bin/node /usr/local/bin/node
ln -s /root/node-v6.11.0-linux-x64/bin/npm /usr/local/bin/npm
而後更新npm:
npm install npm@latest -g
查看已安裝的node的版本:
[root@fd240 ~]# node -v
v6.11.0
0x02 安裝Hyperledger Fabric
按照"搭建第一個網絡"裏的介紹來測試:
下面的這些步驟都須要你用正確的姿式上網, 我目前的搭配是: 安裝ss的客戶端,而後使用proxychains來代理shell, 安裝proxychains的方法:http://www.tuicool.com/articles/rUNFF3
安裝並設置完畢後, 運行:
proxychains4 bash
以後,你的本次shell會話中全部的鏈接都走了代理了.
好的,接下來繼續:
遷出示例代碼:
git clone https://github.com/hyperledger/fabric-samples.git
而後進入代碼目錄:
cd fabric-samples
而後下來安裝二進制文件;
curl -sSL https://goo.gl/PabWJX | bash
這個時間是看你和你的服務器之間的速度了, 等待結束便可,必定得確保你是用正確的姿式上網的,否則這兩步你都沒辦法成功.
我下載的已是rc1版本的包了,前幾天同時的仍是alpha和beta,而且官方文檔也在同步更改.
我本地庫裏下載好的鏡像:
[root@fd240 ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE hyperledger/fabric-tools latest 85d6d3ca0a30 2 days ago 1.32 GB hyperledger/fabric-tools x86_64-1.0.0-rc1 85d6d3ca0a30 2 days ago 1.32 GB hyperledger/fabric-kafka latest dbb5796d915f 2 days ago 1.3 GB hyperledger/fabric-kafka x86_64-1.0.0-rc1 dbb5796d915f 2 days ago 1.3 GB hyperledger/fabric-zookeeper latest d2efbb01a999 2 days ago 1.31 GB hyperledger/fabric-zookeeper x86_64-1.0.0-rc1 d2efbb01a999 2 days ago 1.31 GB hyperledger/fabric-orderer latest 5ec6333eae10 2 days ago 179 MB hyperledger/fabric-orderer x86_64-1.0.0-rc1 5ec6333eae10 2 days ago 179 MB hyperledger/fabric-peer latest cf6bedc2935e 2 days ago 182 MB hyperledger/fabric-peer x86_64-1.0.0-rc1 cf6bedc2935e 2 days ago 182 MB hyperledger/fabric-javaenv latest 7cbe6aca3956 2 days ago 1.42 GB hyperledger/fabric-javaenv x86_64-1.0.0-rc1 7cbe6aca3956 2 days ago 1.42 GB hyperledger/fabric-ca latest cea779a46670 2 days ago 238 MB hyperledger/fabric-ca x86_64-1.0.0-rc1 cea779a46670 2 days ago 238 MB hyperledger/fabric-ccenv latest 13ed472038d2 2 days ago 1.29 GB hyperledger/fabric-ccenv x86_64-1.0.0-rc1 13ed472038d2 2 days ago 1.29 GB
0x03 測試
先進入first-network目錄:
cd first-network
看一下腳本使用說明:
./byfn.sh -h
若是您選擇不提供頻道名稱,則腳本將使用默認的mychannel名稱。 CLI超時參數(用-t標誌指定)是可選值; 若是您選擇不設置它,則CLI腳本結束後將退出CLI容器。
建立:
./byfn.sh -m generate
啓動:
./byfn.sh -m up
默認是60秒後退出. 使用-t 參數能夠指定時間,例如:
./byfn.sh -m up -t 864000
我這裏在執行上面兩條命令的時候都出現了一些警告信息.可是最終仍是成功執行完畢了:
========= All GOOD, BYFN execution completed =========== _____ _ _ ____ | ____| | \ | | | _ \ | _| | \| | | | | | | |___ | |\ | | |_| | |_____| |_| \_| |____/
若是你想中止網絡的話, 運行下面的命令便可,固然如今咱們不中止,繼續測試:
./byfn.sh -m down
[root@fd240 first-network]# ./byfn.sh -m down Stopping with channel 'mychannel' and CLI timeout of '10000' Continue (y/n)? y proceeding ... WARNING: The CHANNEL_NAME variable is not set. Defaulting to a blank string. WARNING: The TIMEOUT variable is not set. Defaulting to a blank string. Stopping peer0.org1.example.com ... done Stopping peer1.org1.example.com ... done Stopping peer0.org2.example.com ... done Stopping orderer.example.com ... done Stopping peer1.org2.example.com ... done Removing cli ... done Removing peer0.org1.example.com ... done Removing peer1.org1.example.com ... done Removing peer0.org2.example.com ... done Removing orderer.example.com ... done Removing peer1.org2.example.com ... done Removing network net_byfn 1529eb06e34a b3a370df312e 273c5a467ebe Untagged: dev-peer1.org2.example.com-mycc-1.0:latest Deleted: sha256:8956d45d168352dea31d87f04edc1d9f34bc3ca0eb252b84cb44a607cf467e13 Deleted: sha256:a300ff593826845fc3f37020f7d58e7d437d7f73c6c4b65ea8c69917466b10c2 Deleted: sha256:e2dd4be84d6e44020ae7b5bdd39b79d79c27e0a9968accbaf836ad1343af84e9 Deleted: sha256:0e0313aa04f0bb0f36ad20dcc0ef7a551c3c367c33a494c5e612166887a7c034 Deleted: sha256:2bf6cb6e8ac1fb3ba3e57ba0c68c501a5ad33fed5e8c12499f30d5663d190062 Deleted: sha256:418485d6bf1587104a8da149f0aca34c39d2f918bbe46ebb99faff5c6e3fcb51 Deleted: sha256:888f5aa1c8a2ac0c77f603d4615596d029283cb7bde123eb091453c75fabd861 Untagged: dev-peer0.org1.example.com-mycc-1.0:latest Deleted: sha256:b58a292485c9c5b4da68f386f16e68293acd359291de6b91366d91723ffb4539 Deleted: sha256:559e3d2ed00a62d04391098816f7e64fae22d570387e7803ce219e4dcf9740d8 Deleted: sha256:d4ef0076f7bd41a531adf905797ddf9adcef1293d08a70dbb5390b6fbdb9af8f Deleted: sha256:353bc73b0c1820dad8a843dc45adcdac91fcfc60fb7b4b5a9285c135304ee000 Deleted: sha256:c3a93a92e095820188f28ec7c3da9321395440575a0ebddc6bb132611e67563f Deleted: sha256:e5adc4ad9fb7421406a1569d289c2d28719fa0e701c0b11be2bc700c5055eb36 Deleted: sha256:c67868aa025bfa7d183c5a1ba247d69be1a27cda71965deb37dc1c457167d09d Untagged: dev-peer0.org2.example.com-mycc-1.0:latest Deleted: sha256:7b936afdf0318126c3717970e8de7a16f015357b1c7049a68e85e38fa4bae233 Deleted: sha256:699ed77d140a2ea756a3640deac9ffd974ffc6171255426c0733d8a69859e4d7 Deleted: sha256:abcee9f3c60732acfc3c7d4726880869c5b9baea4ac208a6c47c2103cbe6cf2e Deleted: sha256:26729e91b6f4a9ab8178eb214faeec74cd06105c8e908125fbf2f111b8c8e0ca Deleted: sha256:de987082ebc0969410072f3bf55bb1ca7f094b0e47540b23e905b483a8119e64 Deleted: sha256:9cfd630b066875bb3c9677fd67a905dfee4b4a8269b3d06cdc372da270569383 Deleted: sha256:d41355d4700c66467e926e121197428ae9150ca11369ca18caaa4b6b58cfcd89
進入節點的cli:
[root@fd240 first-network]# docker exec -it cli bash
root@33e3432d74b8:/opt/gopath/src/github.com/hyperledger/fabric/peer#
設置環境變量:
export CHANNEL_NAME=mychannel
byfn.sh中往這個 mychannel裏初始化了兩個變量,a和b, 默認值是90. 就相似執行了下列命令:
peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --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.member','Org2MSP.member')"
下面咱們執行一些操做:
查詢:
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
應該返回90
減10:
peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --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"]}'
應該返回200 OK
再查詢:
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
應該返回80
升級1.0.0以後遇到的問題:
在執行
./byfn.sh -m up
時,遇到一個錯誤提示:
[root@fedora26test first-network]# ./byfn.sh -m up Starting with channel 'mychannel' and CLI timeout of '10000' Continue (y/n)? y proceeding ... Starting peer1.org2.example.com ... Starting peer1.org1.example.com ... Starting peer1.org2.example.com Starting peer0.org2.example.com ... Starting peer1.org1.example.com Starting peer0.org2.example.com Starting peer0.org1.example.com ... Starting orderer.example.com ... Starting peer0.org1.example.com Starting peer1.org2.example.com ... done Starting cli ... Starting cli ... done /bin/bash: ./scripts/script.sh: Permission denied
我嘗試把全部文件及子文件夾的權限都改成777,從新嘗試執行腳本依然報這個錯誤。因而就懷疑是不是SELinux的問題,打開Fedora的SELinux的錯誤報告程序,果真發現了,關掉SELinux,重啓機器,OK。