fabric1.2安装教程

写在前面

因为项目组统一的要求,所以在fabric已经发布2时仍然需要安装1.2。
nexus.hyperledger.org网站已经不再维护,按照太早的教程安装1.2会有问题,故根据自己的安装过程整理一个完整的可安装成功的教程。
系统环境:ubuntu18.04(最好是一个新的系统,不“干净”可能会带来各种问题)
参考:
https://www.lizenghai.com/archives/11044.html.
https://blog.csdn.net/qq_39800434/article/details/105094313

前期准备

修改下载源(这里用阿里源,其它国内源自行查找)

#备份配置文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
#编辑配置文件(没有vim可以用gedit)
sudo vim /etc/apt/sources.list
#在配置文件开头添加以下内容
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
#更新一下
sudo apt-get update
sudo apt-get upgrade

安装GOLANG

下载GO语言安装包,并复制到/usr/local路径下
下载地址https://studygolang.com/dl.

cd /usr/local
#解压
tar zxvf go*.tar.gz
#配置GO的环境变量
sudo vim ~/.bashrc
#在文末添加以下内容
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
#环境变量生效
source ~/.profile
#查看GO版本(若无GO的版本信息,尝试在~/.profile中添加GO路径,操作类似)
cd ~
go version

安装Docker

#卸载旧版本Docker
sudo apt-get remove docker  docker-engine docker.io
#安装必要的系统工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
#安装GPG证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
#写入软件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
#安装并更新Docker-ce
sudo apt-get -y update
sudo apt-get -y install docker-ce
#创建Docker用户组
sudo groupadd docker
#将当前用户添加到docker用户组
sudo gpasswd -a ${USER} docker
#更新用户组
newgrp - docker
#编辑/etc/docker/daemon.json
sudo gedit /etc/docker/daemon.json
#在文件中添加以下内容(这里用的阿里云的镜像地址,其它自行百度)
{
  "registry-mirrors": [
    "https://6kx4zyno.mirror.aliyuncs.com"
  ]
}
#重启docker
sudo systemctl daemon-reload
sudo systemctl restart docker
#查看版本信息
docker -v
#查看镜像是否配置成功
docker info
#若输出中含有刚配置的镜像地址说明配置成功,若需要sudo docker info才能查看docker信息说明将当前用户添加到docker用户组时未成功

安装Docker-Compose

#安装python pip
sudo apt-get install python-pip
#下载docker-compose的二进制包(我curl下载不下来,转而去docker官网下载后放到/usr/local/bin路径下,重命名为docker-compose)
curl -L https://github.com/docker/compose/releases/download/1.25.0-rc1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
#更改权限
sudo chmod +x /usr/local/bin/docker-compose
#查看docker-compose版本
docker-compose -v

Fabric环境搭建

cd $HOME
mkdir -p go/src/github.com/hyperledger/
cd go/src/github.com/hyperledger/
#git fabric代码(如果git太慢,可以去gitee上新建一个仓库然后在gitee上git下来代码,或者手动下载)
git clone "https://gerrit.hyperledger.org/r/fabric".git
cd fabric/
#本文使用fabric-1.2,所以检出版本为1.2的分支
git checkout release-1.2
#修改bootstrap.sh文件

###修改binariesInstall()函数中两处nexus.hyperledger.org网址,nexus网站已不再维护,示例如下

binariesInstall() {
  echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries"
  binaryDownload ${BINARY_FILE} https://github.com/hyperledger/fabric/releases/download/v${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://github.com/hyperledger/fabric-ca/releases/download/v${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
}

###注释掉md5码校验部分,示例如下

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
}
cd scripts/
sudo ./bootstrap.sh

#执行bootstrap.sh,其完成三件事情
###1.   git fabric-samples
###2.  在fabric-samples目录下安装二进制可执行文件和配置文件
###3.  下载指定版本fabric的docker镜像 
#也可以不借助bootstrap.sh,手动完成其功能
#这里提供第二步手动操作介绍
#第二步可科学上网手动下载,放到/home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples目录下。之后再运行bootstrap.sh。这里提供的下载连接为1.4版本,可以按照个人需求下载相应版本
###fabric下载链接为:https://github.com/hyperledger/fabric/releases/download/v1.4.4/hyperledger-fabric-linux-amd64-1.4.4.tar.gz
###fabric-ca的下载链接为:https://github.com/hyperledger/fabric-ca/releases/download/v1.4.4/hyperledger-fabric-ca-linux-amd64-1.4.4.tar.gz

cd ~/go/src/github.com/hyperledger/fabric/
make release
#编译源码
#如果release/linux-amd64/bin文件夹内有以下文件说明编译成功
#configtxgen  configtxlator  cryptogen  discover  idemixgen  orderer  peer

#添加环境变量
sudo gedit ~/.bashrc
#文末添加以下内容
export PATH=$PATH:$GOPATH/src/github.com/hyperledger/fabric/release/linux-amd64/bin
source ~/.bashrc

#测试fabric
cd ~/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/
 ./byfn.sh up
 #如果最后输出以下内容,说明第一个fabric网络启动成功,fabric搭建完毕。
 ===================== Query successful on peer1.org2 on channel 'mychannel' ===================== 
========= All GOOD, BYFN execution completed =========== 
 _____   _   _   ____   
| ____| | \ | | |  _ \  
|  _|   |  \| | | | | | 
| |___  | |\  | | |_| | 
|_____| |_| \_| |____/  

#关闭网络
./byfn.sh down

猜你喜欢

转载自blog.csdn.net/xu926419/article/details/106986861