Fabric开发环境搭建

Author:ljo0412@live.com

更新说明

在根据Fabric手册进行学习的过程中,遇到了一个严重的问题,导致无法向下继续,总结原因为Fabric版本问题。原文选择了Fabric v1.2(master)版本进行开发学习,在build your first network一节中发现无法正常的执行invoke操作。将版本退回到v1.1,发现可以正常运行,故将此篇博客改为v1.1版本。整体步骤不发生改变,仅在执行bootstrap.sh脚本时更改参数。


教程环境及软件版本

OS: ubuntu16.04/ubuntu18.04

  • Docker:18.06.0-ce
  • Go:1.10.3
  • Node.js:8.11.3 && npm:5.6.0
  • Python:2.7
  • Fabric:1.2.0

提示: 以下安装均在普通用户中安装

Docker

安装Docker

这里使用Daocloud镜像进行安装

ubuntu:~$ curl -sSL https://get.daocloud.io/docker | sh

配置用户组

添加$user到docker用户组,免除每次运行docker都需要使用sudo root权限

ubuntu:~$ sudo usermod -aG docker $USER

重新登录系统,检查docker是否安装成功。

ubuntu:~$ docker --version

显示版本信息证明安装成功

ubuntu:~$ docker --version
Docker version 18.06.0-ce, build 0ffa825

这里我所安装的版本18.06.0-ce。

配置Aliyun Docker加速器

由于Docker镜像服务器在国外,所以下载速度非常缓慢甚至失败,阿里云为我们提供了优秀的解决方案。

访问Aliyun Docker Service,点击创建我的容器镜像,点击镜像加速器,选择ubuntu,根据提示执行命令。

命令示例如下(注意替换相应的*******):

ubuntu:~$ sudo mkdir -p /etc/docker
ubuntu:~$ sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://*******.mirror.aliyuncs.com"]
}
EOF
ubuntu:~$ sudo systemctl daemon-reload
ubuntu:~$ sudo systemctl restart docker

安装docker-compose

ubuntu:~$ sudo apt install docker-compose

至此,整个Docker的安装完毕。

Go

下载源码

访问Golang.org下载最新版的GO源码。

这里我选择的go1.10.3.linux-amd64

也可以通过命令行下载

ubuntu:~$ wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz

安装源码

详细教程可以查看官方手册

解压代码到用户自定义目录下,这里选择~/,即主目录

ubuntu:~$ tar -C ~/ -xzf go1.10.3.linux-amd64.tar.gz

添加环境变量

ubuntu:~$ vi ~/.profile
# 在最后添加如下代码
export GOROOT=$HOME/go
export PATH=$PATH:$GOROOT/bin

使环境变量生效

ubuntu:~$ source ~/.profile

注意这里只是使当前终端生效,其他已打开的终端需重新打开

检查是否安装成功

ubuntu:~$ go version
go version go1.10.3 linux/amd64

提示如上版本信息证明,安装成功。

Node.js && NPM

Node.js源码安装

下载最新版的源码,这里我选择8.11.3版本。

注意:Node.js 9.x版本不再被支持,请选择8.9.x 或更新的版本

ubuntu:~$ wget https://nodejs.org/dist/v8.11.3/node-v8.11.3.tar.gz

解压源码

ubuntu:~$ tar -zxf node-v8.11.3.tar.gz

编译安装

ubuntu:~$ cd node-v8.11.3/
ubuntu:~/node-v1.8.11.3$ ./configure
ubuntu:~/node-v1.8.11.3$ make
ubuntu:~/node-v1.8.11.3$ sudo make install

make过程可能会比较长,建议做点有意思的事吧~

验证是否安装成功

ubuntu:~$ node -v
v8.11.3 ubuntu:~$ npm -version
5.6.0

安装Python

ubuntu16.04默认安装了python3.5,而Fabric Node.js SDK需要Python 2.7

ubuntu:~$ sudo apt-get install python

检查Python版本号

ubuntu:~$ python --version

安装Fabric范例、源码和Docker镜像

在执行官方手册中的步骤时,未能正确通过,分析过后应该是curl命令版本太低的问题,未能解决。

错误如下:

ubuntu:~$ curl -sSL http://bit.ly/2ysbOFE | bash -s 1.2.0
curl: (56) Recv failure: Connection reset by peer

这里采用官方手册中的替代解决方案。

复制官方提供的bootstrap.sh脚本内容到本机

2018-7-21版本内容如下:

#!/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

运行该脚本

ubuntu:~$ bash ./bootstrap.sh 1.1.0

该脚本将自动下载fabric-samples源码,下载Fabric Docker镜像。

查看下载的镜像

ubuntu:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hyperledger/fabric-ca 1.2.0 66cc132bd09c 2 weeks ago 252MB
hyperledger/fabric-ca latest 66cc132bd09c 2 weeks ago 252MB
hyperledger/fabric-tools 1.2.0 379602873003 2 weeks ago 1.51GB
hyperledger/fabric-ccenv 1.2.0 6acf31e2d9a4 2 weeks ago 1.43GB
hyperledger/fabric-orderer 1.2.0 4baf7789a8ec 2 weeks ago 152MB
hyperledger/fabric-peer 1.2.0 82c262e65984 2 weeks ago 159MB
hyperledger/fabric-zookeeper 0.4.10 2b51158f3898 3 weeks ago 1.44GB
hyperledger/fabric-zookeeper latest 2b51158f3898 3 weeks ago 1.44GB
hyperledger/fabric-kafka 0.4.10 936aef6db0e6 3 weeks ago 1.45GB
hyperledger/fabric-kafka latest 936aef6db0e6 3 weeks ago 1.45GB
hyperledger/fabric-couchdb 0.4.10 3092eca241fc 3 weeks ago 1.61GB
hyperledger/fabric-couchdb latest 3092eca241fc 3 weeks ago 1.61GB
hyperledger/fabric-baseimage amd64-0.4.10 62513965e238 3 weeks ago 1.39GB
hyperledger/fabric-baseos amd64-0.4.10 52190e831002 3 weeks ago 132MB
hyperledger/fabric-tools latest b7bfddf508bc 4 months ago 1.46GB
hyperledger/fabric-tools x86_64-1.1.0 b7bfddf508bc 4 months ago 1.46GB
hyperledger/fabric-orderer latest ce0c810df36a 4 months ago 180MB
hyperledger/fabric-orderer x86_64-1.1.0 ce0c810df36a 4 months ago 180MB
hyperledger/fabric-peer latest b023f9be0771 4 months ago 187MB
hyperledger/fabric-peer x86_64-1.1.0 b023f9be0771 4 months ago 187MB
hyperledger/fabric-ccenv latest c8b4909d8d46 4 months ago 1.39GB
hyperledger/fabric-ccenv x86_64-1.1.0 c8b4909d8d46 4 months ago 1.39GB
hyperledger/fabric-baseos x86_64-0.4.6 220e5cf3fb7f 5 months ago 151MB
java latest d23bdf5b1b1b 18 months ago 643

因为我执行了v1.1.0和v1.2.0两个版本的命令,所以下载的镜像会更多,读者根据自身情况进行判断,理论上,只要该命令不报错,则将会下载正确的镜像

查看下载的Fabric脚本命令

ubuntu:~$ ls fabric-samples/bin
  • configtxgen
  • configtxlator
  • cryptogen
  • discover
  • fabric-ca-client
  • get-docker-images.sh
  • idemixgen
  • orderer
  • peer

添加这些脚本到环境变量

ubuntu:~$ vi ~/.profile
# 在最后一行添加
export PATH=$PATH:$HOME/fabric-samples/bin

保存文件并退出,使环境变量生效

ubuntu:~$ source ~/.profile

验证是否添加成功,在终端中输入

ubuntu:~$ cryptogen --help
usage: cryptogen [<flags>] <command> [<args> ...]
...

如上显示,则证明环境变量配置成功

总结

至此,整个Fabric的开发环境配置完成。

更多学习记录将会持续更新。


参考文献:

Go语言安装教程: https://golang.org/doc/install

Fabric手册: http://hyperledger-fabric.readthedocs.io/en/latest/

区块链Hyperledger Fabric 学习记录(一)开发环境搭建(ubuntu16.04/ubuntu18.04)的更多相关文章

  1. ubuntu16.04 HyperLedger Fabric 1.2.0 开发环境搭建

    安装准备 1. 安装git.cRUL.gcc/g++和make $ sudo apt-get update $ sudo apt-get install build-essential git cur ...

  2. python学习之python开发环境搭建

    Python简介 Python是一种面向对象.解释型计算机程序设计语言.Python语法简洁而清晰,具有丰富和强大的类库等等众多的特性,这是来自百度百科的介绍,在百度百科还能看到它的更详细的介绍信息, ...

  3. Scala学习1————scala开发环境搭建(windows 10)

    Scala开发环境搭建 先讲几点我学习scala的目的或者原因吧: JVM在企业中的霸主地位,Scala也是JVM上的语言,很有可能未来会从Java过度到Scala也不是不可能. 先进的函数式编程和面 ...

  4. Java - 记录01_开发环境搭建

    时间:2017-07-04 记录:byzqy 一.什么是JDK JDK(Java Development Kit):Java开发工具集,即Java语言的软件开发工具包. SDK(Software De ...

  5. Beaglebone Back学习三(开发环境搭建)

    开发环境搭建 1 Ubuntu环境搭建 2 Window环境搭建 3 开发板环境搭建 1 Ubuntu环境搭建 (1)安装必要的网络工具 samba nfs tftp vmware-tools sam ...

  6. 区块链 Hyperledger Fabric v1.0.0 环境搭建

    前言:最近项目涉及到超级账本,在有些理论知识的基础上,需要整一套环境来. 这是一个特别要注意的事情,笔者之前按照网络上推荐,大部分都是推荐ubuntu系统的,于是下载Ubuntu系统(16.04.5和 ...

  7. java开源项目之IQQ学习记录之项目环境搭建与启动

    本文链接地址:http://blog.csdn.net/sushengmiyan/article/details/18779727 作者:sushengmiyan 现在就码字说说今天晚上搞定的一个项目 ...

  8. Cocos2dx 学习笔记整理----开发环境搭建

    最近在学习cocos2dx,预备将学习过程整理成笔记. 需要的工具和环境整理一下: 使用的版本 cocos2dx目前已经出到了v3.1.1,学习和项目的话还是用2.2.3为宜,毕竟不大想做小白鼠,并且 ...

  9. PHP学习笔记(1) - 开发环境搭建

    运行环境:phpstudy 它基本包括运行php应用需要的一切,php. apache.mysql,一键傻瓜安装 装好之后只需要配置虚拟主机和修改host文件就可以支持多站点 下载: http://w ...

随机推荐

  1. VMware 导出镜像文件供 Virtual Box 使用

    1. 问题描述 Windows 系统安装的 VMware 里的安装配置好的虚拟机需要拷贝到 MAC 的 Virtual Box 中. 需要将 VMware 中的虚拟机导出为镜像文件供 Virtual ...

  2. Android5.0中Material Design的新特性

    最近项目中需要用到Material Design,整理了下面几个常用的控件,以便记忆. 一.Snackbar 1.作用:与Toast类似,但是可以点击监听: 2.使用: (1)Snackbar调用静态 ...

  3. 最短路径Dijkstra matlab

    Dijkstra: function [dist,pre, full_path]=MinRoad_Dijkstra(G,v0) n=0; if isfield(G,'w') && ~i ...

  4. c++ 远程连接局域网内 数据库,并进行操作

    首先尝试利用Windows自带的dos命令窗口操作数据库:参考见https://jingyan.baidu.com/article/3aed632e19b5e8701080918f.html 1.搜索 ...

  5. NOIP模拟赛-2018.11.7

    NOIP模拟赛 如果用命令行编译程序可以发现没加头文件之类的错误. 如果用命令行编译程序可以发现没加头文件之类的错误. 如果用命令行编译程序可以发现没加头文件之类的错误. 编译之前另存一份,听说如果敲 ...

  6. Failed to abandon session scope: Connection timed out

    系统log 出现  Failed to abandon session scope: Connection timed out  错误, reboot无法重启 解决办法就是让postfix只用IPv4 ...

  7. ELK (Elasticsearch+Logstash+Kibana)部署

    部署机器: 服务端:dev-server    X.X.X.X      ( logstash-1.5.4,elasticsearch-1.7.1,kibana-4.1.1 ) 客户端:dev-cli ...

  8. OpenCV——掩膜(又称掩码)mask的原理和作用

    一.什么是掩模mask OpenCV中很多函数都带有一个mask参数,mask被称为掩模.图像掩模一般用来对处理的图像(全部或者局部)进行遮挡,来控制图像处理的区域或处理过程. 二.掩模原理 掩模一般 ...

  9. vector使用小结

    1.创建vector容器: std::vector<int> data; std::vector<int> data(20);大小20,自动赋值为0 std::vector&l ...

  10. JAVA 第一周学习总结

    20175308 2018-2019-2 <Java程序设计>第一周学习总结 教材学习内容总结 1.关于java 2.java开发环境的配置 3.java编译.运行的简单实例 4.git的 ...