Fabric 1.4安装

阅读目录

1 安装依赖工具
    1.1 安装 git
    1.2 安装 cURL
    1.3 安装 Docker
    1.4 安装 docker-compose
    1.5 安装 Golang
2 拉取 fabric 源码
3 拉取 fabric-samples
    3.1 配置镜像加速器
    3.2 拉取依赖
    3.3 设置环境变量(可选)
4 测试网络
    4.1 启动网络
    4.2 关闭网络

Hyperledger Fabric 依赖的软件版本查看官方 github 地址 https://github.com/hyperledger/fabric 下文件 /docs/source/prereqs.rst,软件版本要求根据安装的 Fabric 的版本差异而略有不同。

Return Top

为了下载方便,最好将 Ubuntu 的软件镜像源更换为国内,点击 “软件和更新” 将镜像源更换为国内,最好是华为或者阿里的源。更换之后,使用如下命令进行更新:

$ sudo apt update

安装 git 工具使用如下命令:

$ sudo apt install git

安装 cURL 使用如下命令:

$ sudo apt install curl

查看系统是否已经安装 Docker:

$ docker --version

未安装,使用如下命令安装最新版本的 Docker:

$ sudo apt install docker.io

安装完之后,查看版本,出现如下字样则安装成功:

$ docker --version
Docker version 18.09.7, build 2d0083d

设置成非 root 用户也能执行 docker,需要将普通用户加入 docker 组:

$ sudo usermod -aG docker 你的用户名 (重启生效)

查看系统是否已经安装 docker-compose:

$ docker-compose --version

未安装,使用如下命令安装 docker-compose 工具:

$ sudo apt install docker-compose

安装完之后,查看版本,出现如下字样则安装成功:

$ docker-compose --version
docker-compose version 1.17.1, build unknown

允许其他用户执行 compose 相关命令:

$ sudo chmod +x /usr/share/doc/docker-compose

1> 下载 Golang

可以 wget 工具安装 Golang:

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

Golang 的版本要求查看 Fabric 依赖的软件版本,不是越新版本越好,新版本会出现不兼容的情况,Fabric1.4 要求 Golang 版本为 go1.11.x。

如果网络不行,上述命令执行失败,可以直接从 https://studygolang.com/dl 下载相应的 Golang 版本压缩包,拷贝到虚拟机。

2> 解压文件

下载完 Golang 压缩包之后,使用 tar 命令将压缩包解压到指定的 /usr/local/ 路径下:

$ sudo tar -zxvf go1.11.11.linux-amd64.tar.gz -C /usr/local/

3> 配置环境变量

如果想让系统所有用户使用 Golang,则编辑 /etc/profile 文件;如果只是想让当前用户使用 Golang,则编辑当前用户 $HOME 目录下的 .bashrc 或 .profile 文件。

$ sudo gedit /etc/profile

在 profile 文件最后添加如下内容:

export GOROOT=/usr/local/go
export GOPATH= H O M E / g o e x p o r t P A T H = HOME/go export PATH= HOME/goexportPATH=PATH: G O R O O T / b i n : GOROOT/bin: GOROOT/bin:GOPATH/bin

使用 source 命令,使刚刚添加的配置信息生效:

$ source /etc/profile

使用 go version 命令验证是否安装成功(没有成功,重启下虚拟机):

$ go version
go version go1.11.11 linux/amd64

4> 卸载旧版本 Golang 的命令

如果 Ubuntu 中已经有 Golang,则使用如下命令卸载旧版本:

$ su -

apt-get remove golang-go --purge && apt-get autoremove --purge && apt-get clean

Return Top

创建一个空目录并进入该目录:

$ mkdir -p ~/go/src/github.com/hyperledger
$ cd ~/go/src/github.com/hyperledger

拉取 fabric 的源码,通过以下命令拉取:

$ git clone https://github.com/hyperledger/fabric.git

查看并切换当前分支,本人写本博客时的最新分支为 v1.4.3:

$ cd ./fabric
$ git branch -a
$ git checkout v1.4.3

Return Top

这里选择的是阿里云的镜像加速器:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors,不配置镜像加速器下载速度很慢。

$ sudo mkdir -p /etc/docker
sudo vim /etc/docker/daemon.json
(两者二选一)
$ sudo tee /etc/docker/daemon.json <<-‘EOF’
{
“registry-mirrors”: [“https://obou6wyb.mirror.aliyuncs.com”]
}
EOF
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

由于 e2e 网络在 Fabric1.4 已经移除,所以测试网络使用 fabric-samples 中的 first-network。

方式一(要求网速好,最好挂 VPN 下):

可以在 fabric/scripts 目录下找到 bootstrap.sh 脚本,复制到与 fabric 同级目录下,执行脚本:

$ ./bootstrap.sh 1.4.3 1.4.3 0.4.15

该脚本会帮你干很多事情:

如果当前目录没有 hyperledger/fabric-samples,会从 github.com 克隆 hyperledger/fabric-samples 存储库;
使用 checkout 签出对应指定的版本标签;
将指定版本的 Hyperledger Fabric 平台特定的二进制文件和配置文件安装到 fabric-samples 存储库的根目录中;
下载指定版本的 Hyperledger Fabric Docker 镜像文件;
将下载的 Docker 镜像文件标记为 “lastest"。

方式二:

查看 bootstrap.sh 脚本,该脚本主要帮我们干以下三件事,一般会卡在 binariesInstall 步骤,我们可以手动完成这三个步骤。

if [ “ S A M P L E S " = = " t r u e " ] ; t h e n e c h o e c h o " I n s t a l l i n g h y p e r l e d g e r / f a b r i c − s a m p l e s r e p o " e c h o s a m p l e s I n s t a l l f i i f [ " SAMPLES" == "true" ]; then echo echo "Installing hyperledger/fabric-samples repo" echo samplesInstall fi if [ " SAMPLES"=="true"];thenechoecho"Installinghyperledger/fabricsamplesrepo"echosamplesInstallfiif["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

1> 下载 fabric-samples 源码

查看 bootstrap.sh 脚本:

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 V E R S I O N o f h y p e r l e d g e r / f a b r i c − s a m p l e s " g i t c h e c k o u t v {VERSION} of hyperledger/fabric-samples" git checkout v VERSIONofhyperledger/fabricsamples"gitcheckoutv{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 vKaTeX parse error: Expected 'EOF', got '&' at position 64: …fabric-samples &̲& git checkout …{VERSION}
else
echo "===> Cloning hyperledger/fabric-samples repo and checkout vKaTeX parse error: Expected 'EOF', got '&' at position 86: …ic-samples.git &̲& cd fabric-sam…{VERSION}
fi
}

其实就是将 fabric-samples 源码克隆到当前目录下,并切换到指定版本:

$ git clone https://github.com/hyperledger/fabric-samples.git
$ cd ./fabric-samples
$ git branch -a
$ git checkout v1.4.3

2> 下载可执行二进制文件

下载指定版本的 Hyperledger Fabric 平台特定的二进制文件和配置文件,查看 bootstrap.sh 脚本:

binariesInstall() {
echo “===> Downloading version F A B R I C T A G p l a t f o r m s p e c i f i c f a b r i c b i n a r i e s " b i n a r y D o w n l o a d " {FABRIC_TAG} platform specific fabric binaries" binaryDownload " FABRICTAGplatformspecificfabricbinaries"binaryDownload"{BINARY_FILE}” “https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/ A R C H − {ARCH}- 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

}

该脚本从下面两个链接中下载二进制文件,我们直接访问该页面,选择相应的版本下载即可,此处选择的是 linux-amd64-1.4.3 版本

https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric

https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca

下载的 hyperledger-fabric-linux-amd64-1.4.3.tar 压缩包内有 bin 和 config 两个文件夹,hyperledger-fabric-ca-linux-amd64-1.4.3.tar 压缩包内有 bin 文件夹,将两个 bin 文件夹内的二进制文件汇总在一个 bin 文件夹内。 最后将 bin 和 config 文件夹复制到 fabric-samples 文件夹内。
或者直接用这个命令
wget https://github.com/hyperledger/fabric/releases/download/v1.4.3/hyperledger-fabric-linux-amd64-1.4.3.tar.gz

3> 下载 Docker镜像

上一个步骤的下载 hyperledger-fabric-linux-amd64-1.4.3.tar 的 bin 文件夹下还有一个 get-docker-images.sh 脚本,可以运行该脚本下载镜像,但是该脚本不会下载 fabric-ca 和 fabric-javaenv 镜像,所以不推荐。

转到 bootstrap.sh 脚本同级目录下,删除 bootstrap.sh 中 samplesInstall 和 binariesInstall 步骤。

if [ “$DOCKER” == “true” ]; then
echo
echo “Installing Hyperledger Fabric docker images”
echo
dockerInstall
fi

执行 bootstrap.sh 脚本:

$ ./bootstrap.sh 1.4.3 1.4.3 0.4.15

===> List out hyperledger docker images
hyperledger/fabric-tools 1.4.3 18ed4db0cd57 7 weeks ago 1.55GB
hyperledger/fabric-tools latest 18ed4db0cd57 7 weeks ago 1.55GB
hyperledger/fabric-ca 1.4.3 c18a0d3cc958 7 weeks ago 253MB
hyperledger/fabric-ca latest c18a0d3cc958 7 weeks ago 253MB
hyperledger/fabric-ccenv 1.4.3 3d31661a812a 7 weeks ago 1.45GB
hyperledger/fabric-ccenv latest 3d31661a812a 7 weeks ago 1.45GB
hyperledger/fabric-orderer 1.4.3 b666a6ebbe09 7 weeks ago 173MB
hyperledger/fabric-orderer latest b666a6ebbe09 7 weeks ago 173MB
hyperledger/fabric-peer 1.4.3 fa87ccaed0ef 7 weeks ago 179MB
hyperledger/fabric-peer latest fa87ccaed0ef 7 weeks ago 179MB
hyperledger/fabric-javaenv 1.4.3 5ba5ba09db8f 2 months ago 1.76GB
hyperledger/fabric-javaenv latest 5ba5ba09db8f 2 months ago 1.76GB
hyperledger/fabric-zookeeper 0.4.15 20c6045930c8 7 months ago 1.43GB
hyperledger/fabric-zookeeper latest 20c6045930c8 7 months ago 1.43GB
hyperledger/fabric-kafka 0.4.15 b4ab82bbaf2f 7 months ago 1.44GB
hyperledger/fabric-kafka latest b4ab82bbaf2f 7 months ago 1.44GB
hyperledger/fabric-couchdb 0.4.15 8de128a55539 7 months ago 1.5GB
hyperledger/fabric-couchdb latest 8de128a55539 7 months ago 1.5GB
hyperledger/fabric-baseos amd64-0.4.15 9d6ec11c60ff 7 months ago 145MB

至此,Fabric 网络启动所需依赖全部下载完成。

启动 fabric-samples/first-network 网络所需二进制文件的默认路径为 fabric-samples/bin,可以将该路径添加入环境变量中:

$ sudo gedit /etc/profile

在 profile 文件最后添加:

export PATH= P A T H : PATH: PATH:GOROOT/bin: G O P A T H / b i n : GOPATH/bin: GOPATH/bin:HOME/go/src/github.com/hyperledger/fabric-samples/bin

使用 source 命令使文件生效:

$ source /etc/profile

检验环境变量是否成功(没有成功,重启下虚拟机):

$ fabric-ca-client version
fabric-ca-client:
Version: 1.4.3
Go version: go1.11.5
OS/Arch: linux/amd64

Return Top

$ cd ./fabric-samples/first-network/
$ ./byfn.sh up
可能出现的问题

通过 docker ps 命令可以查看到节点的启动情况。

$ ./byfn.sh down
Stopping for channel ‘mychannel’ with CLI timeout of ‘10’ seconds and CLI delay of ‘3’ seconds
Continue? [Y/n] y
proceeding …
WARNING: The BYFN_CA2_PRIVATE_KEY variable is not set. Defaulting to a blank string.
WARNING: The BYFN_CA1_PRIVATE_KEY variable is not set. Defaulting to a blank string.
Stopping cli … done
Stopping peer1.org1.example.com … done
Stopping peer1.org2.example.com … done
Stopping peer0.org1.example.com … done
Stopping peer0.org2.example.com … done
Stopping orderer.example.com … done
Removing cli … done
Removing peer1.org1.example.com … done
Removing peer1.org2.example.com … done
Removing peer0.org1.example.com … done
Removing peer0.org2.example.com … done
Removing orderer.example.com … done
Removing network net_byfn
Removing volume net_peer0.org3.example.com
WARNING: Volume net_peer0.org3.example.com not found.
Removing volume net_peer1.org3.example.com
WARNING: Volume net_peer1.org3.example.com not found.
Removing volume net_orderer2.example.com
WARNING: Volume net_orderer2.example.com not found.
Removing volume net_orderer.example.com
Removing volume net_peer0.org2.example.com
Removing volume net_peer0.org1.example.com
Removing volume net_peer1.org1.example.com
Removing volume net_peer1.org2.example.com
Removing volume net_orderer5.example.com
WARNING: Volume net_orderer5.example.com not found.
Removing volume net_orderer4.example.com
WARNING: Volume net_orderer4.example.com not found.
Removing volume net_orderer3.example.com
WARNING: Volume net_orderer3.example.com not found.

猜你喜欢

转载自blog.csdn.net/zhuiyunzhugang/article/details/118176531