【Hyper ledger学习】Windows 10安装部署Hyper ledger记录(一)

Hyper ledger在win 10(Win10 Pro, Win10 Education)上的安装主要有以下几步(我自己用的Win 10 教育版):

  1. Docker for Windows 安装
  2. Curl for Windows 安装
  3. Go 语言安装
  4. Node.js 和 NPM 安装
  5. Python 2.7安装
  6. Windows-build-tools 和 grpc 安装
  7. Hyperledger Fabric 1.4.4 Samples, Binaries and Docker Images安装
  8. Fabric 网络测试

Step 1: 安装Docker for Windows 10

现在Docker已经支持Win 10,并且有.exe桌面版可供下载。

下载链接:Docker Desktop and Desktop Enterprise

点击Download Desktop for Mac and Windows,需要注册docker账号才下载。下载完成后,直接打开Docker Desktop Installer.exe即可安装,默认安装即可。

docker.PNG
docker.PNG

安装完成后,启动docker。右键docker图标,选择Settings

设置General,勾选Expose daemon on tcp://localhost:2375 without TLS

docker.PNG

设置Shared Drives(可以勾选所有),我设置了D盘。

docker.PNG

系统要求:Docker for windows 安装文档

  • Windows 10 64-bit: Pro, Enterprise, or Education (Build 15063 or later).
  • Hyper-V and Containers Windows features must be enabled. (参考:如何开启和使用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.

接下来的步骤根据Hyper Ledger 1.4 说明文档Getting Started来操作。

检查Docker是否安装成功:

$ docker --version
Docker version 19.03.5, build 633a0ea
$ docker-compose --version
docker-compose version 1.24.1, build 4667896b

可以使用Docker命令pull,删除,查看,运行镜像:
Docker官网上有它们给出的一些官方镜像,例如hello-world

$ docker pull hello-world
$ docker rmi hello-world
$ docker images
$ docker run hello-world

Step 2: 安装Curl for Windows

现在Curl已经提供了比较简单的.exe安装方式。安装Curl for 64-bit.exe文件应该在bin文件夹中。

此时,你可以在cmd窗口中使用curl命令检查是否安装成功。

curl --help

当然也可以安装Git Bash 64-bit for Windows,自带Curl命令。在运行clone命令前,要做一些设置:

$ git config --global core.autocrlf false
$ git config --global core.longpaths true

你可以通过以下命令检查设置是否成功:

$ git config --get core.autocrlf
false
$ git config --get core.longpaths
true

注意:git bash自带的curl命令无法在powershell和cmd中使用。

Step 3: 安装Go语言

版本要求:Go version 1.12.x is required.

Go语言安装路径需要在环境变量中设置,在用户变量中添加,一般win10安装完已自动添加,检查一下GOPATH是否存在即可。

也可以在命令行中检查:

$ go help
Go is a tool for managing Go source code.
...
2 Go.PNG

Step 4: 安装Node.js 和 NPM

因为我之前已经安装过,所以简单给出链接。

下载地址: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所在路径添加到系统环境变量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

前提:已经安装了Git Bash

Clone [hyperledger/fabric-samples]( hyperledger/fabric-samples repository) repository
选择一个位置/文件夹,在该文件夹中右键打开Git Bash,输入以下命令:

$ curl -sSL http://bit.ly/2ysbOFE | bash -s

如果运行结果,关于curl命令报错,可能是你的curl版本太低不支持重定向,或者是你的运行环境不支持,还有一种是网络不好。

可以直接使用un-shortened URL代替,命令如下:

$ curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s

下载完成后,可以在文件夹中看到fabric-samples文件夹。

在下载过程可能会因为网速不好卡住已经docker images下载不成功。
我尝试了另一种解决办法,根据区块链框架hyperledger Fabric1.2,win10,docker18.6,资产转移实例。重新找到一个新文件夹:

  1. 直接通过git clone命令下载fabric-samples
  2. 找到fabric-samples/basic-network/.env文件,增加配置COMPOSE_CONVERT_WINDOWS_PATHS=1
  3. 进入fabric-samples/basic-network文件夹,cmd输入命令:
    docker-compose -f docker-compose.yml up -d
    这条命令可以网络环境不好的时候比较容易的下载docker images,还可以看到实时进度(git bash 中的curl命令看不到下载进度)。而且神奇的是,当cmd中镜像下载顺利时,之前git bash中下载艰难的docker images也比较顺利的下载下来了。

Git Bash安装成功,会显示:

...
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

同时,我们也可以使用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: 测试Fabric网络

  1. 进入使用curl -sSL命令下载的fabric-samples文件夹。
  2. 打开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时一个测试脚本,它首先使用2个organizations org1和org2建立网络,每个organization分别有2个peer和1个orderer。

注意区块链框架hyperledger Fabric1.2,win10,docker18.6,资产转移实例中测试网络的方式,我无法测试成功,并且在first-network中运行./byfn.sh up也会报错。我仅用它来辅助我下载docker images (也就是curl -sSL那句命令)。

  1. 当你看到上图end时,表示已经完成了first-network的测试,现在可以使用./eyfn.sh down清理网络。
$ ./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

注意:网络上我看的教程,大多使用./byfn down关闭网络,但是我会报错:

$ ./byfn down
bash: ./byfn: No such file or directory`

重新试了./byfn.sh down,同样可以关闭网络,一定要有.sh


本文作者:Joyce
文章来源:https://www.jianshu.com/p/d9dd6fdf2544
版权声明:转载请注明出处!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,390评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,821评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,632评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,170评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,033评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,098评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,511评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,204评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,479评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,572评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,341评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,213评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,576评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,893评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,171评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,486评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,676评论 2 335