您好,登錄后才能下訂單哦!
目錄
一.Fabric 簡介
在介紹我們的主角Fabric之前,我們先來介紹一下它的父項目:Hyperledger-超級賬本
Hyperledger 項目是首個面向企業的開放區塊鏈技術的重要探索。在 Linux 基金會的支持下,吸引了包括 IBM、Intel、摩根等在內的眾多科技和金融巨頭的參與。
1.發展歷史
區塊鏈已經成為當下最受人關注的開源技術,有人說它將顛覆金融行業的未來。然而對很多人來說,區塊鏈技術難以理解和實現,而且缺乏統一的規范。
2015 年 12 月,開源世界的旗艦——Linux 基金 會牽頭,聯合 30 家初始企業成員(包括 IBM、Accenture、Intel、J.P.Morgan、R3、DAH、DTCC、FUJITSU、HITACHI、SWIFT、Cisco 等),共同 宣告 了 Hyperledger 項目的成立。該項目試圖打造一個透明、公開、去中心化的分布式賬本項目,作為區塊鏈技術的開源規范和標準,讓更多的應用能更容易的建立在區塊鏈技術之上。項目官方信息網站在 hyperledger.org,
目前已經有超過 120 家全球知名企業和機構(大部分均為各自行業的領導者)宣布加入 Hyperledger 項目,其中包括 30 家來自中國本土的企業,包括艾億新融旗下的艾億數融科技公司(2016.05.19)、Onchain(2016.06.22)、比鄰共贏(Belink)信息技術有限公司(2016.06.22)、BitSE(2016.06.22)、布比(2016.07.27)、三一重工(2016.08.30)、萬達金融(2016.09.08)、華為(2016.10.24)等。
如果說以比特幣為代表的貨幣區塊鏈技術為 1.0,以以太坊為代表的合同區塊鏈技術為 2.0,那么實現了完備的權限控制和安全保障的 Hyperledger 項目毫無疑問代表著 3.0 時代的到來。
IBM 貢獻了數萬行已有的 Open Blockchain 代碼,Digital Asset 則貢獻了企業和開發者相關資源,R3 貢獻了新的金融交易架構,Intel 也剛貢獻了跟分布式賬本相關的代碼。
Hyperledger 社區由技術委員會(Technical Steering Committee,TSC)指導,首任主席由來自 IBM 開源技術部 CTO 的 Chris Ferris 擔任,管理組主席則由來自 Digital Asset Holdings 的 CEO Blythe Masters 擔任。另外,自 2016 年 5 月起,Apache 基金會創始人 Brian Behlendorf 擔任超級賬本項目的首位執行董事。2016 年 12 月,中國技術工作組 正式成立,負責本土社區組織和技術引導工作。官方網站也提供了十分詳細的 組織結構信息。
該項目的出現,實際上宣布區塊鏈技術已經不再是僅面向“社會實驗”性質的應用場景,它已經正式被主流機構和企業市場認可;同時,Hyperledger 首次提出和實現的完備權限管理、創新的一致性算法和可拔插、可擴展的框架,對于區塊鏈相關技術和產業的發展都將產生深遠的影響。
2.項目組成
目前主要包括三大賬本平臺項目和若干其它項目。
賬本平臺項目:
其它項目:
項目約定共同遵守的 基本原則 為:
3.聯盟鏈VS公鏈
公鏈:
針對所有用戶
激勵機制->代幣
聯盟鏈
針對特定的組織用戶
沒有激勵機制
應用程序
數據共享
每一個行業都可以組成一個聯盟
二.Fabric環境搭建
1.安裝環境
推薦在 Linux(如 Ubuntu 16.04+)或 MacOS 環境中開發代碼,并安裝如下工具。
git:用來獲取代碼。
vim: 用來進行文本編輯
curl: 部署腳本中會使用curl命令
$ sudo apt update
$ sudo apt install git vim curl -y
Docker 1.12+:用來支持容器環境,注意 MacOS 下要用 Docker for Mac。
$ sudo apt install docker.io docker-compose -y
golang 1.10+安裝成功后需要配置 $GOPATH 等環境變量。
Fabric1.0.0版本要求Go1.7+
$ tar -zxvf go1.10.3.linux-amd64.tar.gz -C /usr/local/
2.配置環境變量
$ sudo vim /etc/profile
添加如下內容
export GOPATH=$HOME/go
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH
讓配置生效
$ source /etc/profile
$ go version
3.下載源碼和鏡像
3.1 創建存放目錄
$ mkdir hyfa ;cd hyfa
3.2 下載源碼與鏡像
https://github.com/hyperledger/fabric/blob/master/scripts/bootstrap.sh
bootstrap.sh 腳本內容,默認版本為最新的版本:1.2.0
如果需要下載不同的版本號,$1=指定版本號即可,如./bootstrap.sh 1.1.0
#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# if version not passed in, default to latest released version
export VERSION=1.2.0
# if ca version not passed in, default to latest released version
export CA_VERSION=$VERSION
# current version of thirdparty images (couchdb, kafka and zookeeper) released
export THIRDPARTY_IMAGE_VERSION=0.4.10
export ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')")
export MARCH=$(uname -m)
printHelp() {
echo "Usage: bootstrap.sh [<version>] [<ca_version>] [<thirdparty_version>][-d -s -b]"
echo
echo "-d - bypass docker image download"
echo "-s - bypass fabric-samples repo clone"
echo "-b - bypass download of platform-specific binaries"
echo
echo "e.g. bootstrap.sh 1.2.0 -s"
echo "would download docker images and binaries for version 1.2.0"
}
dockerFabricPull() {
local FABRIC_TAG=$1
for IMAGES in peer orderer ccenv tools; do
echo "==> FABRIC IMAGE: $IMAGES"
echo
docker pull hyperledger/fabric-$IMAGES:$FABRIC_TAG
docker tag hyperledger/fabric-$IMAGES:$FABRIC_TAG hyperledger/fabric-$IMAGES
done
}
dockerThirdPartyImagesPull() {
local THIRDPARTY_TAG=$1
for IMAGES in couchdb kafka zookeeper; do
echo "==> THIRDPARTY DOCKER IMAGE: $IMAGES"
echo
docker pull hyperledger/fabric-$IMAGES:$THIRDPARTY_TAG
docker tag hyperledger/fabric-$IMAGES:$THIRDPARTY_TAG hyperledger/fabric-$IMAGES
done
}
dockerCaPull() {
local CA_TAG=$1
echo "==> FABRIC CA IMAGE"
echo
docker pull hyperledger/fabric-ca:$CA_TAG
docker tag hyperledger/fabric-ca:$CA_TAG hyperledger/fabric-ca
}
samplesInstall() {
# clone (if needed) hyperledger/fabric-samples and checkout corresponding
# version to the binaries and docker images to be downloaded
if [ -d first-network ]; then
# if we are in the fabric-samples repo, checkout corresponding version
echo "===> Checking out v${VERSION} branch of hyperledger/fabric-samples"
git checkout v${VERSION}
elif [ -d fabric-samples ]; then
# if fabric-samples repo already cloned and in current directory,
# cd fabric-samples and checkout corresponding version
echo "===> Checking out v${VERSION} branch of hyperledger/fabric-samples"
cd fabric-samples && git checkout v${VERSION}
else
echo "===> Cloning hyperledger/fabric-samples repo and checkout v${VERSION}"
git clone -b master https://github.com/hyperledger/fabric-samples.git && cd fabric-samples && git checkout v${VERSION}
fi
}
# Incrementally downloads the .tar.gz file locally first, only decompressing it
# after the download is complete. This is slower than binaryDownload() but
# allows the download to be resumed.
binaryIncrementalDownload() {
local BINARY_FILE=$1
local URL=$2
curl -f -s -C - ${URL} -o ${BINARY_FILE} || rc=$?
# Due to limitations in the current Nexus repo:
# curl returns 33 when there's a resume attempt with no more bytes to download
# curl returns 2 after finishing a resumed download
# with -f curl returns 22 on a 404
if [ "$rc" = 22 ]; then
# looks like the requested file doesn't actually exist so stop here
return 22
fi
if [ -z "$rc" ] || [ $rc -eq 33 ] || [ $rc -eq 2 ]; then
# The checksum validates that RC 33 or 2 are not real failures
echo "==> File downloaded. Verifying the md5sum..."
localMd5sum=$(md5sum ${BINARY_FILE} | awk '{print $1}')
remoteMd5sum=$(curl -s ${URL}.md5)
if [ "$localMd5sum" == "$remoteMd5sum" ]; then
echo "==> Extracting ${BINARY_FILE}..."
tar xzf ./${BINARY_FILE} --overwrite
echo "==> Done."
rm -f ${BINARY_FILE} ${BINARY_FILE}.md5
else
echo "Download failed: the local md5sum is different from the remote md5sum. Please try again."
rm -f ${BINARY_FILE} ${BINARY_FILE}.md5
exit 1
fi
else
echo "Failure downloading binaries (curl RC=$rc). Please try again and the download will resume from where it stopped."
exit 1
fi
}
# This will attempt to download the .tar.gz all at once, but will trigger the
# binaryIncrementalDownload() function upon a failure, allowing for resume
# if there are network failures.
binaryDownload() {
local BINARY_FILE=$1
local URL=$2
echo "===> Downloading: " ${URL}
# Check if a previous failure occurred and the file was partially downloaded
if [ -e ${BINARY_FILE} ]; then
echo "==> Partial binary file found. Resuming download..."
binaryIncrementalDownload ${BINARY_FILE} ${URL}
else
curl ${URL} | tar xz || rc=$?
if [ ! -z "$rc" ]; then
echo "==> There was an error downloading the binary file. Switching to incremental download."
echo "==> Downloading file..."
binaryIncrementalDownload ${BINARY_FILE} ${URL}
else
echo "==> Done."
fi
fi
}
binariesInstall() {
echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries"
binaryDownload ${BINARY_FILE} https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/${ARCH}-${VERSION}/${BINARY_FILE}
if [ $? -eq 22 ]; then
echo
echo "------> ${FABRIC_TAG} platform specific fabric binary is not available to download <----"
echo
fi
echo "===> Downloading version ${CA_TAG} platform specific fabric-ca-client binary"
binaryDownload ${CA_BINARY_FILE} https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/${ARCH}-${CA_VERSION}/${CA_BINARY_FILE}
if [ $? -eq 22 ]; then
echo
echo "------> ${CA_TAG} fabric-ca-client binary is not available to download (Available from 1.1.0-rc1) <----"
echo
fi
}
dockerInstall() {
which docker >& /dev/null
NODOCKER=$?
if [ "${NODOCKER}" == 0 ]; then
echo "===> Pulling fabric Images"
dockerFabricPull ${FABRIC_TAG}
echo "===> Pulling fabric ca Image"
dockerCaPull ${CA_TAG}
echo "===> Pulling thirdparty docker images"
dockerThirdPartyImagesPull ${THIRDPARTY_TAG}
echo
echo "===> List out hyperledger docker images"
docker images | grep hyperledger*
else
echo "========================================================="
echo "Docker not installed, bypassing download of Fabric images"
echo "========================================================="
fi
}
DOCKER=true
SAMPLES=true
BINARIES=true
# Parse commandline args pull out
# version and/or ca-version strings first
if [ ! -z $1 ]; then
VERSION=$1;shift
if [ ! -z $1 ]; then
CA_VERSION=$1;shift
if [ ! -z $1 ]; then
THIRDPARTY_IMAGE_VERSION=$1;shift
fi
fi
fi
# prior to 1.2.0 architecture was determined by uname -m
if [[ $VERSION =~ ^1\.[0-1]\.* ]]; then
export FABRIC_TAG=${MARCH}-${VERSION}
export CA_TAG=${MARCH}-${CA_VERSION}
export THIRDPARTY_TAG=${MARCH}-${THIRDPARTY_IMAGE_VERSION}
else
# starting with 1.2.0, multi-arch images will be default
: ${CA_TAG:="$CA_VERSION"}
: ${FABRIC_TAG:="$VERSION"}
: ${THIRDPARTY_TAG:="$THIRDPARTY_IMAGE_VERSION"}
fi
BINARY_FILE=hyperledger-fabric-${ARCH}-${VERSION}.tar.gz
CA_BINARY_FILE=hyperledger-fabric-ca-${ARCH}-${CA_VERSION}.tar.gz
# then parse opts
while getopts "h?dsb" opt; do
case "$opt" in
h|\?)
printHelp
exit 0
;;
d) DOCKER=false
;;
s) SAMPLES=false
;;
b) BINARIES=false
;;
esac
done
if [ "$SAMPLES" == "true" ]; then
echo
echo "Installing hyperledger/fabric-samples repo"
echo
samplesInstall
fi
if [ "$BINARIES" == "true" ]; then
echo
echo "Installing Hyperledger Fabric binaries"
echo
binariesInstall
fi
if [ "$DOCKER" == "true" ]; then
echo
echo "Installing Hyperledger Fabric docker images"
echo
dockerInstall
fi
3.3 執行腳本
$chmod +x bootstrap.sh ; ./bootstrap.sh
(1) 下載源碼包
下載fabric壓縮包
===> Downloading version 1.2.0 platform specific fabric binaries
===> Downloading: https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.2.0/hyperledger-fabric-linux-amd64-1.2.0.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 39.0M 100 39.0M 0 0 482k 0 0:01:22 0:01:22 --:--:-- 450k
==> Done.
下載fabric-ca-client壓縮包
===> Downloading version 1.2.0 platform specific fabric-ca-client binary
===> Downloading: https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/linux-amd64-1.2.0/hyperledger-fabric-ca-linux-amd64-1.2.0.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4940k 100 4940k 0 0 435k 0 0:00:11 0:00:11 --:--:-- 538k
==> Done.
(2)下載Fabric核心模塊鏡像
peer :fabric環境中的peer容器, 主要用來背書, 記賬
peer模塊是主節點模塊,負責存儲區塊鏈數據,運行維護鏈碼
==> FABRIC IMAGE: peer
1.2.0: Pulling from hyperledger/fabric-peer
b234f539f7a1: Pull complete
55172d420b43: Pull complete
5ba5bbeb6b91: Pull complete
43ae2841ad7a: Pull complete
f6c9c6de4190: Pull complete
c6af77e36488: Pull complete
964f7f4f22f3: Pull complete
d4a3f4cfba3d: Pull complete
73782018d902: Pull complete
039eb34e730e: Pull complete
Digest: sha256:949b38bad9496d7694b54d30b90b72653804d761a44d721c4dc7a16a5cbcabe8
Status: Downloaded newer image for hyperledger/fabric-peer:1.2.0
orderer模塊負責對交易進行排序,并將排序好的交易打包成區塊。
==> FABRIC IMAGE: orderer
1.2.0: Pulling from hyperledger/fabric-orderer
b234f539f7a1: Already exists
55172d420b43: Already exists
5ba5bbeb6b91: Already exists
43ae2841ad7a: Already exists
f6c9c6de4190: Already exists
c6af77e36488: Already exists
964f7f4f22f3: Already exists
d4a3f4cfba3d: Already exists
8d0e11f5a0f7: Pull complete
0bda0f004d88: Pull complete
Digest: sha256:1a8cbe6abef245432730035d08ea1d1aa54a50717136fa3be58f8af4570ad57e
Status: Downloaded newer image for hyperledger/fabric-orderer:1.2.0
ccenv:針對Go語言的容器
==> FABRIC IMAGE: ccenv
1.2.0: Pulling from hyperledger/fabric-ccenv
b234f539f7a1: Already exists
55172d420b43: Already exists
5ba5bbeb6b91: Already exists
43ae2841ad7a: Already exists
f6c9c6de4190: Already exists
c6af77e36488: Already exists
964f7f4f22f3: Already exists
13cd31405e09: Pull complete
e03b35c19d96: Pull complete
96c2920985e3: Pull complete
e91461be8304: Pull complete
950c3368692b: Pull complete
c5de8d20c137: Pull complete
5536b64bc67b: Pull complete
Digest: sha256:0a7fb37111cafce79cf89ca8d1af5ca6f721e60a8bd1b2b93521e671e3348af2
Status: Downloaded newer image for hyperledger/fabric-ccenv:1.2.0
tools:fabric環境中的工具容器, 主要用來測試客戶端
==> FABRIC IMAGE: tools
1.2.0: Pulling from hyperledger/fabric-tools
b234f539f7a1: Already exists
55172d420b43: Already exists
5ba5bbeb6b91: Already exists
43ae2841ad7a: Already exists
f6c9c6de4190: Already exists
c6af77e36488: Already exists
964f7f4f22f3: Already exists
13cd31405e09: Already exists
e03b35c19d96: Already exists
96c2920985e3: Already exists
e91461be8304: Already exists
314928def9dd: Pull complete
d5b68ae13f8d: Pull complete
dde25187799d: Pull complete
Digest: sha256:284f997b33d6745b52d378f8c7ba1a208b8c13633f3ef63e68377b1986077cb6
Status: Downloaded newer image for hyperledger/fabric-tools:1.2.0
(3)下載Fabric的CA鏡像
Fabric環境中的CA容器(fabric-ca: 用于認證, 根據配置文件中指定的路徑檢查當前用戶是否合法)
===> Pulling fabric ca Image
==> FABRIC CA IMAGE
1.2.0: Pulling from hyperledger/fabric-ca
b234f539f7a1: Already exists
55172d420b43: Already exists
5ba5bbeb6b91: Already exists
43ae2841ad7a: Already exists
f6c9c6de4190: Already exists
c6af77e36488: Already exists
964f7f4f22f3: Already exists
f7a6370a6f7f: Pull complete
37cc94e973b2: Pull complete
a80e45d2f608: Pull complete
8feb19f73d3a: Pull complete
5f3ea048e0c0: Pull complete
Digest: sha256:0a6f8b3af8537fa725dc40d09565c77b1b284f848f653c32cb4125b3134a8726
Status: Downloaded newer image for hyperledger/fabric-ca:1.2.0
(4) 下載第三方鏡像
couchdb:是一個可選DB,可選, 可將Fabric中默認的DB替代為couchDB
Apache CouchDB是一個開源數據庫,它是一個使用JSON作為存儲格式,JavaScript作為查詢語言,MapReduce和HTTP作為API的NoSQL數據庫。
===> Pulling thirdparty docker images
==> THIRDPARTY DOCKER IMAGE: couchdb
0.4.10: Pulling from hyperledger/fabric-couchdb
b234f539f7a1: Already exists
55172d420b43: Already exists
5ba5bbeb6b91: Already exists
43ae2841ad7a: Already exists
f6c9c6de4190: Already exists
c6af77e36488: Already exists
964f7f4f22f3: Already exists
13cd31405e09: Already exists
e03b35c19d96: Already exists
96c2920985e3: Already exists
e91461be8304: Already exists
6a752ce8f7fe: Pull complete
a49e2cb854b0: Pull complete
493b25e70e6d: Pull complete
2721753a3e7c: Pull complete
adede0f2a5f1: Pull complete
9eb593f76305: Pull complete
bb49a3450e11: Pull complete
929b9bb5d788: Pull complete
Digest: sha256:d7eb3fd24acafaeaaae94a44659409270b89bd599d017cf9d5b75d8f21438b51
Status: Downloaded newer image for hyperledger/fabric-couchdb:0.4.10
kafka :
Kafka是一個消息系統,原本開發自LinkedIn,用作LinkedIn的活動流(Activity Stream)和運營數據處理管道(Pipeline)的基礎。現在它已被多家不同類型的公司 作為多種類型的數據管道和消息系統使用。
==> THIRDPARTY DOCKER IMAGE: kafka
0.4.10: Pulling from hyperledger/fabric-kafka
b234f539f7a1: Already exists
55172d420b43: Already exists
5ba5bbeb6b91: Already exists
43ae2841ad7a: Already exists
f6c9c6de4190: Already exists
c6af77e36488: Already exists
964f7f4f22f3: Already exists
13cd31405e09: Already exists
e03b35c19d96: Already exists
96c2920985e3: Already exists
e91461be8304: Already exists
146aa6695f33: Pull complete
954e41d8cd46: Pull complete
9d750070047f: Pull complete
Digest: sha256:7c07db5b38ca3259528b3e53691ecd273e44d1521218aa8f3a5dc34ab6947ff5
Status: Downloaded newer image for hyperledger/fabric-kafka:0.4.10
ZooKeeper曾是Hadoop的正式子項目,后發展成為Apache頂級項目,與Hadoop密切相關但卻沒有任何依賴。它是一個針對大型應用提供高可用的數據管理、應用程序協調服務的分布式服務框架,基于對Paxos算法的實現,使該框架保證了分布式環境中數據的強一致性,提供的功能包括:配置維護、統一命名服務、狀態同步服務、集群管理等。
==> THIRDPARTY DOCKER IMAGE: zookeeper
0.4.10: Pulling from hyperledger/fabric-zookeeper
b234f539f7a1: Already exists
55172d420b43: Already exists
5ba5bbeb6b91: Already exists
43ae2841ad7a: Already exists
f6c9c6de4190: Already exists
c6af77e36488: Already exists
964f7f4f22f3: Already exists
13cd31405e09: Already exists
e03b35c19d96: Already exists
96c2920985e3: Already exists
e91461be8304: Already exists
c335e6e59168: Pull complete
016e000b0cc8: Pull complete
e716b0c9790c: Pull complete
390f47e71470: Pull complete
Digest: sha256:151fe67421663fe860c1aba4b80877a22b6b8fa18cbc97990c309c603cd6f5f1
Status: Downloaded newer image for hyperledger/fabric-zookeeper:0.4.10
3.4 腳本執行結果
(1) 源碼包文件結構
bruce@ubuntu:~$ls hyfa/fabric-samples/ -l
返回結果
total 76
drwxrwxr-x 5 bruce bruce 4096 Jul 10 00:59 balance-transfer
drwxrwxr-x 4 bruce bruce 4096 Jul 10 00:59 basic-network
drwxrwxr-x 2 1001 1001 4096 Jul 3 13:41 bin
drwxrwxr-x 8 bruce bruce 4096 Jul 10 00:59 chaincode
drwxrwxr-x 3 bruce bruce 4096 Jul 10 00:59 chaincode-docker-devmode
-rw-rw-r-- 1 bruce bruce 597 Jul 10 00:59 CODE_OF_CONDUCT.md
drwxrwxr-x 2 1001 1001 4096 Jul 3 12:04 config
-rw-rw-r-- 1 bruce bruce 961 Jul 10 00:59 CONTRIBUTING.md
drwxrwxr-x 2 bruce bruce 4096 Jul 10 00:59 fabcar
drwxrwxr-x 3 bruce bruce 4096 Jul 10 00:59 fabric-ca
drwxrwxr-x 6 bruce bruce 4096 Jul 10 00:59 first-network
drwxrwxr-x 4 bruce bruce 4096 Jul 10 00:59 high-throughput
-rw-rw-r-- 1 bruce bruce 3095 Jul 10 00:59 Jenkinsfile
-rw-rw-r-- 1 bruce bruce 11358 Jul 10 00:59 LICENSE
-rw-rw-r-- 1 bruce bruce 470 Jul 10 00:59 MAINTAINERS.md
-rw-rw-r-- 1 bruce bruce 1229 Jul 10 00:59 README.md
drwxrwxr-x 3 bruce bruce 4096 Jul 10 00:59 scripts
(2) 查看docker鏡像
bruce@ubuntu:~$ sudo docker images
返回結果
REPOSITORY TAG IMAGE ID CREATED SIZE
hyperledger/fabric-ca 1.2.0 66cc132bd09c 6 days ago 252MB
hyperledger/fabric-ca latest 66cc132bd09c 6 days ago 252MB
hyperledger/fabric-tools 1.2.0 379602873003 6 days ago 1.51GB
hyperledger/fabric-tools latest 379602873003 6 days ago 1.51GB
hyperledger/fabric-ccenv 1.2.0 6acf31e2d9a4 6 days ago 1.43GB
hyperledger/fabric-ccenv latest 6acf31e2d9a4 6 days ago 1.43GB
hyperledger/fabric-orderer 1.2.0 4baf7789a8ec 6 days ago 152MB
hyperledger/fabric-orderer latest 4baf7789a8ec 6 days ago 152MB
hyperledger/fabric-peer 1.2.0 82c262e65984 6 days ago 159MB
hyperledger/fabric-peer latest 82c262e65984 6 days ago 159MB
hyperledger/fabric-zookeeper 0.4.10 2b51158f3898 11 days ago 1.44GB
hyperledger/fabric-zookeeper latest 2b51158f3898 11 days ago 1.44GB
hyperledger/fabric-kafka 0.4.10 936aef6db0e6 11 days ago 1.45GB
hyperledger/fabric-kafka latest 936aef6db0e6 11 days ago 1.45GB
hyperledger/fabric-couchdb 0.4.10 3092eca241fc 11 days ago 1.61GB
hyperledger/fabric-couchdb latest 3092eca241fc 11 days ago 1.61GB
4.再次配置環境變量
為fabric的相關命令配置環境變量
$ sudo vim /etc/profile
添加如下內容:
FabricSampleDir="/home/bruce/hyfa/fabric-samples"
export PATH=${FabricSampleDir}/bin:$PATH
讓配置生效
$ source /etc/profile
三.Fabric目錄結構
1.三大核心工具
fabric-samples/bin/cryptogen
cryptogen: 根據指定的配置文件,生成組織結構及×××書的工具
fabric-samples/bin/configtxgen
configtxgen: 主要生成三種配置文件
1. 生成Orderer初始區塊
2. 生成應用通道交易配置文件
3. 錨節點更新配置文件
錨節點: 數據交換
fabric-samples/bin/configtxlator
configtxlator: 用來在正在運行的網絡聯盟鏈中添加一個新的組織
2.關鍵目錄
chaincode/
Fabric示例鏈碼所在目錄
chaincode-docker-devmode/
開啟開發測試模式
在開發測試模式下鏈碼的存放目錄
config/
關于orderer及peer配置信息的文件存放目錄
configtx.yaml: 生成初始區塊及應用通道交易配置文件的參考
core.yaml: peer配置信息的參考
orderer.yaml: orderer配置信息的參考
fabcar/
測試Node環境的所在目錄
有一個小汽車的應用示例
fabric-ca/
fabric基礎環境提供的一個簡單fabric-ca
first-network/
與Fabric網絡相關的所有內容
3.其他概念
聯盟:
org1:
peer0.org1.example.com
peer1.org1.example.com
org2:
peer0.org2.example.com
peer1.org2.example.com
應用通道:
用于隔離不同聯盟之間交易
Peer節點角色:
1. 背書節點
-- 在fabric中只能部分節點是背書節點
2. 記賬節點(commiter)
-- 在fabric中所有的Peer節點都是記賬節點
3. 錨節點
-- 通過配置文件指定
-- 作用: 用于跨組織交換數據
背書: 在fabric中, 就是簽名的概念
四.Node環境搭建
后期我們需要使用Fabric SDK做應用程序的開發,官方雖然提供了Node.JS,Java,Go,Python等多種語言的SDK,但是由于整個Fabric太新了,很多SDK還不成熟和完善,所以一般采用Node JS的SDK,畢竟這個是功能畢竟齊全,而且也是官方示例的時候使用的SDK。
1.安裝nvm
由于Node版本的迭代速度很快,版本很多,不同項目對node的依賴不同,故需要切換不同node版本目前有n和nvm這兩個工具可以對Node進行平滑升級,n 命令是作為一個 node 的模塊而存在,而 nvm 是一個獨立于 node/npm 的外部 shell 腳本,因此 nvm 命令相比 n更加全面,n更有局限性。
nvm 是 node 管理工具,有點類似管理 Ruby 的 rvm,如果是需要管理 Windows 下的 node,官方推薦是使用 nvmw 或 nvm-windows 。
$ sudo apt update
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.10/install.sh | bash
$ export NVM_DIR="$HOME/.nvm"
$ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
2.安裝Node與npm
NPM是隨同NodeJS一起安裝的包管理工具,能解決NodeJS代碼部署上的很多問題,常見的使用場景有以下幾種:
允許用戶將自己編寫的包或命令行程序上傳到NPM服務器供別人使用。
$ nvm install v8.11.1
檢查Node版本
$ node -v
v8.11.1
檢查npm版本
$ npm -v
5.6.0
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。