设置环境和测试操作的方法,以便在Hyperledger Fabric v1.1.0上进行试验
请注意
截至目前为止,因为最新版本是v1.4.0,所以很多东西都过时了。
(2019.02) 请务必参考以下文章组。
【运行Hyperledger Fabric 1.2.1,检查和验证区块链的运作】 https://qiita.com/kyoko7tam/items/6e0eea28ac8340f6897e
简要概述
在Hyperledger Fabric(以下简称Fabric)的源代码中包含了用于端到端命令行界面(e2e_cli)的功能测试。一般来说,它用于在构建源代码后进行功能测试,但如果拉取Docker镜像,则无需进行构建即可正常运行。
以下是相应方法。
使用 Fabric v1.1.0 发布版进行实验的环境设置方法。
请按照以下3个步骤进行操作。如果只是想进行简单的示例操作,可以跳过 Fabric 的源码。需要 Docker 镜像、平台二进制文件和 fabric-samples。
-
- 下载Fabric v1.1.0的源代码
-
- 下载Docker镜像和平台二进制文件
下载fabric-samples
尝试运行basic-network进行确认
尝试运行Build Your First Network (BYFN) 进行确认
前置条件
我在Mac OS X El Capitan上进行了测试。
-
- git
-
- Docker CE
- Docker Compose
假设以下操作在合适的工作目录WORK中进行。
cd $WORK
下载Fabric v1.1.0的源代码。
克隆时,关键是将分支指定为 release-1.1。
注意:克隆标签 v1.1.0 会因为一些旧文件而不成功。
# --depth=1 を指定すると過去のコミットを取らないので速い
git clone -b release-1.1 --depth=1 https://github.com/hyperledger/fabric.git
下载Docker镜像和平台二进制文件
# 作業用のディレクトリを別に作っておいたほうがいい
cd $WORK
mkdir work && cd work
# (ローカルでビルドしない場合) Dockerイメージをpullし、platform binariesをダウンロード
# Fabricのイメージはタグ1.1.0、サードパーティのイメージはタグ0.4.6をpullする
# Pullされたイメージにはdocker tagコマンドによりlatestタグが付くので注意
../fabric/scripts/bootstrap.sh
# Platform binariesにパスを通す
export PATH=$WORK/work/bin:$PATH
被提取的图像如下所示:
hyperledger/fabric-ca latest 72617b4fa9b4 2 months ago 299MB
hyperledger/fabric-ca x86_64-1.1.0 72617b4fa9b4 2 months ago 299MB
hyperledger/fabric-tools latest b7bfddf508bc 2 months ago 1.46GB
hyperledger/fabric-tools x86_64-1.1.0 b7bfddf508bc 2 months ago 1.46GB
hyperledger/fabric-orderer latest ce0c810df36a 2 months ago 180MB
hyperledger/fabric-orderer x86_64-1.1.0 ce0c810df36a 2 months ago 180MB
hyperledger/fabric-peer latest b023f9be0771 2 months ago 187MB
hyperledger/fabric-peer x86_64-1.1.0 b023f9be0771 2 months ago 187MB
hyperledger/fabric-javaenv latest 82098abb1a17 2 months ago 1.52GB
hyperledger/fabric-javaenv x86_64-1.1.0 82098abb1a17 2 months ago 1.52GB
hyperledger/fabric-ccenv latest c8b4909d8d46 2 months ago 1.39GB
hyperledger/fabric-ccenv x86_64-1.1.0 c8b4909d8d46 2 months ago 1.39GB
hyperledger/fabric-zookeeper latest 92cbb952b6f8 2 months ago 1.39GB
hyperledger/fabric-zookeeper x86_64-0.4.6 92cbb952b6f8 2 months ago 1.39GB
hyperledger/fabric-kafka latest 554c591b86a8 2 months ago 1.4GB
hyperledger/fabric-kafka x86_64-0.4.6 554c591b86a8 2 months ago 1.4GB
hyperledger/fabric-couchdb latest 7e73c828fc5b 2 months ago 1.56GB
hyperledger/fabric-couchdb x86_64-0.4.6 7e73c828fc5b 2 months ago 1.56GB
此外,平台二进制文件中还包含了peer命令本身,如果要查看版本,可以尝试输入以下命令:
$ peer version
peer:
Version: 1.1.0
Go version: go1.9.2
OS/Arch: darwin/amd64
Experimental features: false
Chaincode:
Base Image Version: 0.4.6
Base Docker Namespace: hyperledger
Base Docker Label: org.hyperledger.fabric
Docker Namespace: hyperledger
2018-05-15 17:11:02.034 JST [main] main -> INFO 001 Exiting.....
例如,要尝试Private Ledger功能,需要重新构建以将”Experimental features”设置为true(可能)。
下载 fabric-samples
cd $WORK
git clone -b release-1.1 --depth=1 https://github.com/hyperledger/fabric-samples.git
为了确认,尝试运行基本网络。
cd $WORK
cd fabric-samples/basic-network
# スタート
start.sh
# ストップ。コンテナを止めるだけ
stop.sh
# 停止したコンテナなどを消すなどしたければこちら。`docker rmi`のエラーが出るけど気にしない
# これはこのスクリプトが他のサンプルと共用のため余計なコマンドが入っている
teardown.sh
基本网络采用简单配置,包括一个peer、一个CouchDB、一个orderer和一个CA。一旦启动,将执行以下操作:
-
- peer0から唯一のチャネルmychannelをpeer channel createコマンドで作成する
- peer0をそのチャネルにpeer channel joinコマンドで参加させる
我并没有特意部署或调用链码。
确认正在移动的货柜。
$ docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------------------------------------
ca.example.com sh -c fabric-ca-server sta ... Up 0.0.0.0:7054->7054/tcp
couchdb tini -- /docker-entrypoint ... Up 4369/tcp, 0.0.0.0:5984->5984/tcp, 9100/tcp
orderer.example.com orderer Up 0.0.0.0:7050->7050/tcp
peer0.org1.example.com peer node start Up 0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp
检查日志
当想要查看特定容器的日志时,请指定其名称。如果指定了“-f”选项,则进入跟随模式。
$ docker-compose logs
peer0.org1.example.com | 2018-05-15 08:32:00.738 UTC [nodeCmd] serve -> INFO 001 Starting peer:
peer0.org1.example.com | Version: 1.1.0
peer0.org1.example.com | Go version: go1.9.2
peer0.org1.example.com | OS/Arch: linux/amd64
peer0.org1.example.com | Experimental features: false
peer0.org1.example.com | Chaincode:
peer0.org1.example.com | Base Image Version: 0.4.6
peer0.org1.example.com | Base Docker Namespace: hyperledger
peer0.org1.example.com | Base Docker Label: org.hyperledger.fabric
peer0.org1.example.com | Docker Namespace: hyperledger
peer0.org1.example.com |
peer0.org1.example.com | 2018-05-15 08:32:00.741 UTC [ledgermgmt] initialize -> INFO 002 Initializing ledger mgmt
peer0.org1.example.com | 2018-05-15 08:32:00.742 UTC [kvledger] NewProvider -> INFO 003 Initializing ledger provider
peer0.org1.example.com | 2018-05-15 08:32:00.801 UTC [couchdb] handleRequest -> WARN 004 Retrying couchdb request in 125ms. Attempt:1 Error:Get http://couchdb:5984/: dial tcp 172.23.0.3:5984: getsockopt: connection refused
(略)
orderer.example.com | 2018-05-15 08:32:18.479 UTC [policies] Evaluate -> DEBU 31c Signature set satisfies policy /Channel/Readers
orderer.example.com | 2018-05-15 08:32:18.480 UTC [policies] Evaluate -> DEBU 31d == Done Evaluating *policies.implicitMetaPolicy Policy /Channel/Readers
orderer.example.com | 2018-05-15 08:32:18.480 UTC [common/deliver] deliverBlocks -> DEBU 31e [channel: mychannel] Received seekInfo (0xc42010c220) start:<specified:<number:1 > > stop:<specified:<number:18446744073709551615 > > from 172.23.0.5:38980
orderer.example.com | 2018-05-15 08:32:18.480 UTC [fsblkstorage] waitForBlock -> DEBU 31f Going to wait for newer blocks. maxAvailaBlockNumber=[0], waitForBlockNum=[1]
同级命令行界面
要获取 peer0 参与的频道列表,可以使用 docker exec 执行 peer channel list 命令。
$ docker exec peer0.org1.example.com peer channel list
2018-05-15 08:48:07.033 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
Channels peers has joined:
mychannel
2018-05-15 08:48:07.059 UTC [main] main -> INFO 002 Exiting.....