Hyper ledger在win 10(Win10 Pro, Win10 Education)上的安裝主要有以下幾步(我自己用的Win 10 教育版):
- Docker for Windows 安裝
- Curl for Windows 安裝
- Go 語(yǔ)言安裝
- Node.js 和 NPM 安裝
- Python 2.7安裝
- Windows-build-tools 和 grpc 安裝
- Hyperledger Fabric 1.4.4 Samples, Binaries and Docker Images安裝
- Fabric 網(wǎng)絡(luò)測(cè)試
Step 1: 安裝Docker for Windows 10
現(xiàn)在Docker已經(jīng)支持Win 10孽查,并且有.exe
桌面版可供下載捌肴。
下載鏈接:Docker Desktop and Desktop Enterprise
點(diǎn)擊Download Desktop for Mac and Windows
,需要注冊(cè)docker賬號(hào)才下載。下載完成后就缆,直接打開(kāi)Docker Desktop Installer.exe
即可安裝,默認(rèn)安裝即可。
安裝完成后,啟動(dòng)docker放闺。右鍵docker圖標(biāo),選擇Settings
缕坎。
設(shè)置General
怖侦,勾選Expose daemon on tcp://localhost:2375 without TLS
。
設(shè)置Shared Drives
(可以勾選所有),我設(shè)置了D盤(pán)础钠。
系統(tǒng)要求:Docker for windows 安裝文檔
- Windows 10 64-bit: Pro, Enterprise, or Education (Build 15063 or later).
- Hyper-V and Containers Windows features must be enabled. (參考:如何開(kāi)啟和使用windows 10中的Hyper-v)
- The following hardware prerequisites are required to successfully run Client Hyper-V on Windows 10:
- 64 bit processor with Second Level Address Translation (SLAT)
- 4GB system RAM
- BIOS-level hardware virtualization support must be enabled in the BIOS settings. For more information, see Virtualization.
接下來(lái)的步驟根據(jù)Hyper Ledger 1.4 說(shuō)明文檔的Getting Started
來(lái)操作。
檢查Docker是否安裝成功:
$ docker --version
Docker version 19.03.5, build 633a0ea
$ docker-compose --version
docker-compose version 1.24.1, build 4667896b
可以使用Docker命令pull叉谜,刪除旗吁,查看,運(yùn)行鏡像:
Docker官網(wǎng)上有它們給出的一些官方鏡像停局,例如hello-world
$ docker pull hello-world
$ docker rmi hello-world
$ docker images
$ docker run hello-world
Step 2: 安裝Curl for Windows
現(xiàn)在Curl已經(jīng)提供了比較簡(jiǎn)單的.exe
安裝方式很钓。安裝Curl for 64-bit
,.exe
文件應(yīng)該在bin
文件夾中董栽。
此時(shí)码倦,你可以在cmd
窗口中使用curl
命令檢查是否安裝成功。
curl --help
當(dāng)然也可以安裝Git Bash 64-bit for Windows锭碳,自帶Curl
命令袁稽。在運(yùn)行clone
命令前,要做一些設(shè)置:
$ git config --global core.autocrlf false
$ git config --global core.longpaths true
你可以通過(guò)以下命令檢查設(shè)置是否成功:
$ git config --get core.autocrlf
false
$ git config --get core.longpaths
true
注意:git bash自帶的curl命令無(wú)法在powershell和cmd中使用擒抛。
Step 3: 安裝Go語(yǔ)言
版本要求:Go version 1.12.x is required.
Go語(yǔ)言安裝路徑需要在環(huán)境變量中設(shè)置推汽,在用戶變量中添加,一般win10安裝完已自動(dòng)添加歧沪,檢查一下GOPATH
是否存在即可歹撒。
也可以在命令行中檢查:
$ go help
Go is a tool for managing Go source code.
...
Step 4: 安裝Node.js 和 NPM
因?yàn)槲抑耙呀?jīng)安裝過(guò),所以簡(jiǎn)單給出鏈接诊胞。
下載地址:Node.js Windows Installer (.msi) 64-bit
檢查是否安裝成功:
$ node -v
v10.16.0
$ npm -v
6.9.0
Step 5: 安裝Python 2.7
下載安裝Python 2.7暖夭,并將python.exe
所在路徑添加到系統(tǒng)環(huán)境變量Path
中
檢查是否安裝成功:
$ python --version
Python 2.7.17
Step 6: 安裝Windows-build-tools 和 grpc
使用npm
命令安裝windows-build-tools
:
$ npm install --global windows-build-tools
使用npm
命令安裝grpc
:
$ npm install --global grpc
Step 7: 安裝Hyperledger Fabric Samples, Binaries and Docker Images
前提:已經(jīng)安裝了Git Bash
Clone [hyperledger/fabric-samples]( hyperledger/fabric-samples repository) repository
選擇一個(gè)位置/文件夾,在該文件夾中右鍵打開(kāi)Git Bash
撵孤,輸入以下命令:
$ curl -sSL http://bit.ly/2ysbOFE | bash -s
如果運(yùn)行結(jié)果迈着,關(guān)于curl
命令報(bào)錯(cuò),可能是你的curl版本太低不支持重定向邪码,或者是你的運(yùn)行環(huán)境不支持寥假,還有一種是網(wǎng)絡(luò)不好。
可以直接使用un-shortened URL
代替霞扬,命令如下:
$ curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s
下載完成后糕韧,可以在文件夾中看到fabric-samples
文件夾。
在下載過(guò)程可能會(huì)因?yàn)榫W(wǎng)速不好卡住已經(jīng)docker images下載不成功喻圃。
我嘗試了另一種解決辦法萤彩,根據(jù)區(qū)塊鏈框架hyperledger Fabric1.2,win10斧拍,docker18.6,資產(chǎn)轉(zhuǎn)移實(shí)例雀扶。重新找到一個(gè)新文件夾:
- 直接通過(guò)
git clone
命令下載fabric-samples
。- 找到
fabric-samples/basic-network/.env
文件,增加配置COMPOSE_CONVERT_WINDOWS_PATHS=1
愚墓。- 進(jìn)入fabric-samples/basic-network文件夾予权,
cmd
輸入命令:
docker-compose -f docker-compose.yml up -d
這條命令可以網(wǎng)絡(luò)環(huán)境不好的時(shí)候比較容易的下載docker images,還可以看到實(shí)時(shí)進(jìn)度(git bash 中的curl命令看不到下載進(jìn)度)浪册。而且神奇的是扫腺,當(dāng)cmd
中鏡像下載順利時(shí),之前git bash
中下載艱難的docker images也比較順利的下載下來(lái)了村象。
Git Bash
安裝成功笆环,會(huì)顯示:
...
Digest: sha256:048b7c44c1deaabd0f3d84fbf2f7b649d7b10c54a3241c7354f078ee2eff077c
Status: Downloaded newer image for hyperledger/fabric-couchdb:0.4.18
docker.io/hyperledger/fabric-couchdb:0.4.18
===> List out hyperledger docker images
hyperledger/fabric-ca latest 62a60c5459ae 2 weeks ago 150MB
hyperledger/fabric-orderer latest dbc9f65443aa 2 weeks ago 120MB
hyperledger/fabric-peer 1.4.4 9756aed98c6b 2 weeks ago 128MB
hyperledger/fabric-peer latest 9756aed98c6b 2 weeks ago 128MB
hyperledger/fabric-kafka 0.4.18 caaae0474ef2 4 weeks ago 270MB
hyperledger/fabric-kafka latest caaae0474ef2 4 weeks ago 270MB
hyperledger/fabric-couchdb 0.4.18 d369d4eaa0fd 4 weeks ago 261MB
hyperledger/fabric-couchdb latest d369d4eaa0fd 4 weeks ago 261MB
同時(shí),我們也可以使用docker 命令查看鏡像:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
couchdb 2.3 246ed3915b76 13 days ago 201MB
hyperledger/fabric-ca latest 62a60c5459ae 2 weeks ago 150MB
hyperledger/fabric-tools latest 7552e1968c0b 3 weeks ago 1.49GB
hyperledger/fabric-orderer latest dbc9f65443aa 3 weeks ago 120MB
hyperledger/fabric-peer 1.4.4 9756aed98c6b 3 weeks ago 128MB
hyperledger/fabric-peer latest 9756aed98c6b 3 weeks ago 128MB
hyperledger/fabric-kafka 0.4.18 caaae0474ef2 4 weeks ago 270MB
hyperledger/fabric-kafka latest caaae0474ef2 4 weeks ago 270MB
hyperledger/fabric-couchdb 0.4.18 d369d4eaa0fd 4 weeks ago 261MB
hyperledger/fabric-couchdb latest d369d4eaa0fd 4 weeks ago 261MB
hello-world latest fce289e99eb9 11 months ago 1.84kB
Step 8: 測(cè)試Fabric網(wǎng)絡(luò)
- 進(jìn)入使用
curl -sSL
命令下載的fabric-samples
文件夾厚者。 - 打開(kāi)
first-network
文件夾躁劣,右鍵Git Bash
,輸入命令./byfn.sh up
:
$ ./byfn.sh up
Starting for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] Y
proceeding ...
LOCAL_VERSION=1.4.4
DOCKER_IMAGE_VERSION=1.4.4
/d/Fabric/fabric-samples/bin/cryptogen
##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
+ cryptogen generate --config=./crypto-config.yaml
org1.example.com
org2.example.com
+ res=0
+ set +x
Generate CCP files for Org1 and Org2
/d/Fabric/fabric-samples/bin/configtxgen
##########################################################
######### Generating Orderer Genesis block ##############
##########################################################
...
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c987f06d5472 hyperledger/fabric-tools:latest "/bin/bash" 1 second ago Up Less than a second cli
5f7c1878ec5d hyperledger/fabric-peer:latest "peer node start" 4 seconds ago Up 2 seconds 0.0.0.0:7051->7051/tcp peer0.org1.example.com
197369a05c04 hyperledger/fabric-orderer:latest "orderer" 4 seconds ago Up 2 seconds 0.0.0.0:7050->7050/tcp orderer.example.com
4aa55b8e307e hyperledger/fabric-peer:latest "peer node start" 6 seconds ago Up 3 seconds 0.0.0.0:8051->8051/tcp peer1.org1.example.com
52bca558ece3 hyperledger/fabric-peer:latest "peer node start" 6 seconds ago Up 2 seconds 0.0.0.0:9051->9051/tcp peer0.org2.example.com
8f8cda4cd237 hyperledger/fabric-peer:latest "peer node start" 6 seconds ago Up 3 seconds 0.0.0.0:10051->10051/tcp peer1.org2.example.com
f3150caa214c hyperledger/fabric-ca "sh -c 'fabric-ca-se…" 16 hours ago Up 16 hours 0.0.0.0:7054->7054/tcp ca.example.com
430ce35b0147 couchdb:2.3 "tini -- /docker-ent…" 16 hours ago Up 16 hours 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp couchdb
f588def0ae2b hello-world "/hello" 18 hours ago Exited (0) 18 hours ago dazzling_blackwell
78a7432d31f9 hello-world "/hello" 18 hours ago Exited (0) 18 hours ago blissful_gould
ea4ba133ebbe hello-world "/hello" 18 hours ago Exited (0) 18 hours ago interesting_easley
____ _____ _ ____ _____
/ ___| |_ _| / \ | _ \ |_ _|
\___ \ | | / _ \ | |_) | | |
___) | | | / ___ \ | _ < | |
|____/ |_| /_/ \_\ |_| \_\ |_|
Build your first network (BYFN) end-to-end test
...
===================== Query successful on peer1.org2 on channel 'mychannel' =====================
========= All GOOD, BYFN execution completed ===========
_____ _ _ ____
| ____| | \ | | | _ \
| _| | \| | | | | |
| |___ | |\ | | |_| |
|_____| |_| \_| |____/
byfn.sh
時(shí)一個(gè)測(cè)試腳本库菲,它首先使用2個(gè)organizations org1和org2建立網(wǎng)絡(luò)账忘,每個(gè)organization分別有2個(gè)peer和1個(gè)orderer谚鄙。
注意:區(qū)塊鏈框架hyperledger Fabric1.2损谦,win10,docker18.6,資產(chǎn)轉(zhuǎn)移實(shí)例中測(cè)試網(wǎng)絡(luò)的方式迹蛤,我無(wú)法測(cè)試成功奇颠,并且在first-network
中運(yùn)行./byfn.sh up
也會(huì)報(bào)錯(cuò)败去。我僅用它來(lái)輔助我下載docker images (也就是curl -sSL
那句命令)。
- 當(dāng)你看到上圖end時(shí)烈拒,表示已經(jīng)完成了
first-network
的測(cè)試圆裕,現(xiàn)在可以使用./eyfn.sh down
清理網(wǎng)絡(luò)。
$ ./eyfn.sh down
Stopping with channel 'mychannel' and CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] Y
proceeding ...
Stopping cli ... done
Stopping peer0.org1.example.com ... done
Stopping orderer.example.com ... done
...
Deleted: sha256:68dddcb8c4f18ae92776f71177254ef70b94b3c1567eed6c60d09196b145adc8
Deleted: sha256:c579f2e094f84bd633ae0c0bec275b776ce7394464db5c7968b1b9e08b606e06
注意:網(wǎng)絡(luò)上我看的教程荆几,大多使用
./byfn down
關(guān)閉網(wǎng)絡(luò)吓妆,但是我會(huì)報(bào)錯(cuò):$ ./byfn down bash: ./byfn: No such file or directory`
重新試了
./byfn.sh down
,同樣可以關(guān)閉網(wǎng)絡(luò)吨铸,一定要有.sh
行拢。
本文作者:Joyce
文章來(lái)源:http://www.reibang.com/p/d9dd6fdf2544
版權(quán)聲明:轉(zhuǎn)載請(qǐng)注明出處!