【Fabric】Hyperledger Fabric1.4.1 安装

环境

Centos7

Fabric 1.4.1

Docker 18.3

Docker-compose  1.14.0

GoLang  1.11.5

安装必备工具

git

  • sudo yum install -y git

curl

  • sudo yum install -y curl

golang

(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=$HOME/go
  • export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

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

  • source /etc/profile

使用 go version 命令验证是否安装成功:

  • go version

docker

下载docker-ce rpm文件

  • wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm

安装docker-ce

  • yum install -y docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm

启动docker

  • systemctl start docker
  • systemctl enable docker   (开机自启)

测试 docker version

[root@localhost ~]# docker version
Client:
 Version:      18.03.1-ce
 API version:  1.37
 Go version:   go1.9.5
 Git commit:   9ee9f40
 Built:        Thu Apr 26 07:20:16 2018
 OS/Arch:      linux/amd64
 Experimental: false
 Orchestrator: swarm

Server:
 Engine:
  Version:      18.03.1-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.5
  Git commit:   9ee9f40
  Built:        Thu Apr 26 07:23:58 2018
  OS/Arch:      linux/amd64
  Experimental: false

配置镜像加速器

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

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["加速器地址"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

docker-compose

  • curl -L https://github.com/docker/compose/releases/download/1.14.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
  • sudo chmod +x /usr/local/bin/docker-compose

测试

[root@localhost ~]# docker-compose version
docker-compose version 1.14.0, build c7bdf9e
docker-py version: 2.3.0
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t  3 May 2016

拉取fabric源码

在gopath下创建目录并进入。(gopath 默认为/root/go,可以通过 go env | grep GOPATH查看)

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

拉取1.4.1版本的farbic源码

  • git clone --branch v1.4.1 https://github.com/hyperledger/fabric.git

拉取fabric依赖

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

可以在 fabric/scripts 目录下找到 bootstrap.sh 脚本

  • chmod +x bootstrap.sh

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

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

自动安装

修改bootstrap.sh找到第137行、145行,将".nexus"删除

 执行

  • ./bootstrap.sh 1.4.1 1.4.1 0.4.15

如果下载二进制文件失败,可以如下面手动安装或者拉取得出

进入fabric目录下

  • make release

拉取二进制工具,执行完成后,在fabric/release/linux-amd64/bin的目录下有拉取好的二进制文件

cp cryptogen configtxgen configlator fabric-samples/bin

copy 工具到fabric-samples的bin目录下

手动安装

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

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

下载 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${VERSION} 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} 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
}

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

  • git clone --branch v1.4.1 https://github.com/hyperledger/fabric-samples.git

下载可执行二进制文件

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

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
}

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

下载的 hyperledger-fabric-linux-amd64-1.4.1.tar 压缩包内有 bin 和 config 两个文件夹,hyperledger-fabric-ca-linux-amd64-1.4.1.tar 压缩包内有 bin 文件夹,将两个 bin 文件夹内的二进制文件汇总在一个 bin 文件夹内。 最后将 bin 和 config 文件夹复制到 fabric-samples 文件夹内。

赋予可执行权限

  • chmod +x -R  fabric-samples/bin

由于上面链接无法访问,可以去github相应项目中下载。

  • https://github.com/hyperledger/fabric/releases/download/v1.4.1/hyperledger-fabric-linux-amd64-1.4.1.tar.gz
  • https://github.com/hyperledger/fabric-ca/releases/download/v1.4.1/hyperledger-fabric-ca-linux-amd64-1.4.1.tar.gz

下载 Docker镜像

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

转到 bootstrap.sh 脚本同级目录下,将 bootstrap.sh 中 174、175行SAMPLES、BINARIES改为false,即不执行下载fabric-samples和下载二进制脚本

执行 bootstrap.sh 脚本:

  •  ./bootstrap.sh 1.4.1 1.4.1 0.4.15
===> List out hyperledger docker images
hyperledger/fabric-ca          1.4.1               3a1799cda5d7        15 months ago       252MB
hyperledger/fabric-ca          latest              3a1799cda5d7        15 months ago       252MB
hyperledger/fabric-tools       1.4.1               432c24764fbb        15 months ago       1.55GB
hyperledger/fabric-tools       latest              432c24764fbb        15 months ago       1.55GB
hyperledger/fabric-ccenv       1.4.1               d7433c4b2a1c        15 months ago       1.43GB
hyperledger/fabric-ccenv       latest              d7433c4b2a1c        15 months ago       1.43GB
hyperledger/fabric-orderer     1.4.1               ec4ca236d3d4        15 months ago       173MB
hyperledger/fabric-orderer     latest              ec4ca236d3d4        15 months ago       173MB
hyperledger/fabric-peer        1.4.1               a1e3874f338b        15 months ago       178MB
hyperledger/fabric-peer        latest              a1e3874f338b        15 months ago       178MB
hyperledger/fabric-javaenv     1.4.1               b8c9d7ff6243        15 months ago       1.74GB
hyperledger/fabric-javaenv     latest              b8c9d7ff6243        15 months ago       1.74GB
hyperledger/fabric-zookeeper   0.4.15              20c6045930c8        16 months ago       1.43GB
hyperledger/fabric-zookeeper   latest              20c6045930c8        16 months ago       1.43GB
hyperledger/fabric-kafka       0.4.15              b4ab82bbaf2f        16 months ago       1.44GB
hyperledger/fabric-kafka       latest              b4ab82bbaf2f        16 months ago       1.44GB
hyperledger/fabric-couchdb     0.4.15              8de128a55539        16 months ago       1.5GB
hyperledger/fabric-couchdb     latest              8de128a55539        16 months ago       1.5GB

测试网络

  •  cd ./fabric-samples/first-network/

  • ./byfn.sh up

===================== Query successful on peer1.org2 on channel 'mychannel' ===================== 

========= All GOOD, BYFN execution completed =========== 


 _____   _   _   ____   
| ____| | \ | | |  _ \  
|  _|   |  \| | | | | | 
| |___  | |\  | | |_| | 
|_____| |_| \_| |____/  

查看容器docker ps

[root@localhost first-network]# docker ps
CONTAINER ID        IMAGE                                                                                                  COMMAND                  CREATED             STATUS              PORTS                      NAMES
6a655dde5bb0        dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab   "chaincode -peer.add…"   13 minutes ago      Up 13 minutes                                  dev-peer1.org2.example.com-mycc-1.0
34a8a580a62f        dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9   "chaincode -peer.add…"   13 minutes ago      Up 13 minutes                                  dev-peer0.org1.example.com-mycc-1.0
1f1587e5c1ac        dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b   "chaincode -peer.add…"   14 minutes ago      Up 14 minutes                                  dev-peer0.org2.example.com-mycc-1.0
a72c28627767        hyperledger/fabric-tools:latest                                                                        "/bin/bash"              16 minutes ago      Up 16 minutes                                  cli
d9ffca3a63b8        hyperledger/fabric-peer:latest                                                                         "peer node start"        17 minutes ago      Up 16 minutes       0.0.0.0:8051->8051/tcp     peer1.org1.example.com
3eee4e3bb1eb        hyperledger/fabric-peer:latest                                                                         "peer node start"        17 minutes ago      Up 16 minutes       0.0.0.0:10051->10051/tcp   peer1.org2.example.com
e3feeec711e3        hyperledger/fabric-orderer:latest                                                                      "orderer"                17 minutes ago      Up 16 minutes       0.0.0.0:7050->7050/tcp     orderer.example.com
94acf9259d41        hyperledger/fabric-peer:latest                                                                         "peer node start"        17 minutes ago      Up 16 minutes       0.0.0.0:9051->9051/tcp     peer0.org2.example.com
e97bfcc4bd62        hyperledger/fabric-peer:latest                                                                         "peer node start"        17 minutes ago      Up 16 minutes       0.0.0.0:7051->7051/tcp     peer0.org1.example.com

关闭网络

[root@localhost first-network]# ./byfn.sh down
Stopping for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
Stopping cli ... done
Stopping peer1.org1.example.com ... done
Stopping peer1.org2.example.com ... done
Stopping orderer.example.com ... done
Stopping peer0.org2.example.com ... done
Stopping peer0.org1.example.com ... done
Removing cli ... done
Removing peer1.org1.example.com ... done
Removing peer1.org2.example.com ... done
Removing orderer.example.com ... done
Removing peer0.org2.example.com ... done
Removing peer0.org1.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.

 

参考:https://www.cnblogs.com/zongmin/p/11635686.html#_label0_4

posted @ 2020-07-29 17:23    阅读(868)  评论(0编辑  收藏  举报