Fabric开发(二)ubuntu下编译Fabric2.2.0

今天我们用Ubuntu16.04.6在本地编译一下Fabric2.2.0版本。因为在编译过程中有很多细节,需要注意。
1、安装前准备:
安装 git、curl、pip

sudo apt-get install git
sudo apt-get install curl
sudo apt-get install python-pip
pip install --upgrade pip

2、安装go
我这次安装的是go14.4,因为要编译Fabric2.2.0,对Go版本需要>14.1

wget https://storage.googleapis.com/golang/go1.14.4.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.14.4.linux-amd64.tar.gz

接下来编辑当前用户的环境变量:

vi ~/.profile

编辑保存并退出vi后,记得把这些环境载入:

source ~/.profile

我们把go的目录GOPATH设置为当前用户的文件夹下,所以记得创建go文件夹

cd ~
mkdir go

这里强调一下,编译Fabric需要安装go的工具包。安装如下:

mkdir –p $GOPATH/src/golang.org/x
cd $GOPATH/src/golang.org/x
git clone https://github.com/golang/tools.git

等tools下载完毕,我们可以运行以下命令来安装Fabric可能用到的Go工具:

go get github.com/kardianos/govendor
go get github.com/golang/lint/golint
go get golang.org/x/tools/cmd/goimports
go get github.com/onsi/ginkgo/ginkgo
go get github.com/axw/gocov/...
go get github.com/client9/misspell/cmd/misspell
go get github.com/AlekSi/gocov-xml
go get github.com/golang/protobuf/protoc-gen-go

3. 第三方库安装
Fabric依赖的第三方库里面,有些库又依赖了其他库,而这些库是需要我们先手动准备好的。比如libltdl-dev,这是PKCS11用到的一个库,我们需要安装:

sudo apt-get install libltdl-dev 

4.Docker安装
卸载旧版本docker

sudo apt-get remove docker docker-engine docker.io

更新系统软件

sudo apt-get update

安装依赖包

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

添加官方密钥
执行该命令时,如遇到长时间没有响应说明网络连接不到docker网站,需要使用代-理进行。

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

显示OK,表示添加成功.
添加仓库

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

再次更新软件

sudo apt-get update

安装docker
如果想指定安装某一版本,可使用 sudo apt-get install docker-ce= 命令,把替换为具体版本即可。

以下命令没有指定版本,默认就会安装最新版

sudo apt-get install docker-ce

查看docker版本

docker -v

5…docker-compose安装
下载docker-compose

sudo curl -L https://github.com/docker/compose/releases/download/1.17.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

授权

sudo chmod +x /usr/local/bin/docker-compose

查看版本信息

docker-compose --version

6.下载 fabric源码、fabric-samples源码、fabric镜像
我们可以使用Git命令下载源码,首先需要建立对应的目录,然后进入该目录,Git下载源码:

mkdir -p ~/go/src/github.com/hyperledger 
cd ~/go/src/github.com/hyperledger 
git clone https://github.com/hyperledger/fabric.git

由于Fabric一直在更新,所有我们并不需要最新最新的源码,需要切换到v2.2.0版本的源码即可:

cd ~/go/src/github.com/hyperledger/fabric
git checkout v2.2.0

我们现在开始编译

cd ~/go/src/github.com/hyperledger/fabric
make release

显示如下,编译完成

cuijb@cuijb-VirtualBox:~/go/src/github.com/hyperledger/fabric$ make release
Building release/linux-amd64/bin/orderer for linux-amd64
mkdir -p release/linux-amd64/bin
GOOS=linux GOARCH=amd64 go build -o release/linux-amd64/bin/orderer -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=2.2.0 -X github.com/hyperledger/fabric/common/metadata.CommitSHA=5ea85bc -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger" github.com/hyperledger/fabric/cmd/orderer
Building release/linux-amd64/bin/configtxgen for linux-amd64
mkdir -p release/linux-amd64/bin
GOOS=linux GOARCH=amd64 go build -o release/linux-amd64/bin/configtxgen -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=2.2.0 -X github.com/hyperledger/fabric/common/metadata.CommitSHA=5ea85bc -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger" github.com/hyperledger/fabric/cmd/configtxgen
Building release/linux-amd64/bin/configtxlator for linux-amd64
mkdir -p release/linux-amd64/bin
GOOS=linux GOARCH=amd64 go build -o release/linux-amd64/bin/configtxlator -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=2.2.0 -X github.com/hyperledger/fabric/common/metadata.CommitSHA=5ea85bc -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger" github.com/hyperledger/fabric/cmd/configtxlator
Building release/linux-amd64/bin/cryptogen for linux-amd64
mkdir -p release/linux-amd64/bin
GOOS=linux GOARCH=amd64 go build -o release/linux-amd64/bin/cryptogen -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=2.2.0 -X github.com/hyperledger/fabric/common/metadata.CommitSHA=5ea85bc -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger" github.com/hyperledger/fabric/cmd/cryptogen
Building release/linux-amd64/bin/discover for linux-amd64
mkdir -p release/linux-amd64/bin
GOOS=linux GOARCH=amd64 go build -o release/linux-amd64/bin/discover -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=2.2.0 -X github.com/hyperledger/fabric/common/metadata.CommitSHA=5ea85bc -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger" github.com/hyperledger/fabric/cmd/discover
Building release/linux-amd64/bin/idemixgen for linux-amd64
mkdir -p release/linux-amd64/bin
GOOS=linux GOARCH=amd64 go build -o release/linux-amd64/bin/idemixgen -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=2.2.0 -X github.com/hyperledger/fabric/common/metadata.CommitSHA=5ea85bc -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger" github.com/hyperledger/fabric/cmd/idemixgen
Building release/linux-amd64/bin/peer for linux-amd64
mkdir -p release/linux-amd64/bin
GOOS=linux GOARCH=amd64 go build -o release/linux-amd64/bin/peer -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=2.2.0 -X github.com/hyperledger/fabric/common/metadata.CommitSHA=5ea85bc -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger" github.com/hyperledger/fabric/cmd/peer

fabric 2.2.0编译完成。

你可能感兴趣的:(区块链开发,区块链,技术篇,区块链)