Hyperledger Fabric 环境搭建

2022-02-19 09:33:47 浏览数 (1)

需要的环境

ubuntu golang docker docker-compose fabric 源码

1.安装依赖

sudo apt-get install git sudo apt-get install vim sudo apt-get install -y curl

2.更换系统软件源

sudo vim /etc/apt/sources.list 把下面的源填进去

代码语言:javascript复制
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 && sudo apt-get clean

3.安装golang

golang下载 下载到/usr/local 解压

sudo tar zxvf go1.15.8.linux-amd64.tar.gz 配置环境 sudo gedit /etc/profile 添加以下内容

代码语言:javascript复制
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin

source /etc/profile 重启 go version

4.安装docker

添加Docker官方的GPG密钥:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 往下载源中添加stable存储库: sudo add-apt-repository "deb[arch=amd64] https://download.docker.com/linux/ubuntu$(lsb_release-cs)stable" 再次更新下载源: sudo apt-get update 安装最新版本的Docker CE: sudo apt-get install -y docker-ce 将当前用户加入docker用户组: sudo gpasswd -a $USER docker 更新docker用户组: newgrp docker 验证docker: docker -v docker ps -a docker设为开机自启动: sudo systemctl enable docker 将docker镜像库更改为国内的地址,编辑/etc/docker/daemon.json文件: sudo gedit /etc/docker/daemon.json 添加以下内容:

代码语言:javascript复制
{
    "registry-mirrors": ["https://obou6wyb.mirror.aliyuncs.com"]
}

最后重启服务:

sudo systemctl daemon-reload sudo systemctl restart docker.service docker info

5.安装docker-compose

sudo apt install docker-compose docker-compose -v

6.fabric源码

创建文件夹:

cd $HOME mkdir -p go/src/github.com/hyperledger/ cd go/src/github.com/hyperledger/ 从github上拉取fabric的源码: git clone https://github.com/hyperledger/fabric.git 如果clone 速度太慢,也可以上github.com上下载源码压缩包 切换到fabric 1.4 版本: cd fabric/ git checkout release-1.4 下载docker 镜像 和 fabric-samples: cd scripts/ ./bootstrap.sh -b [RainBowText]这这里拉取速度很慢,并且有些文件被墙,这里提供这两个二进制文件[/RainBowText] 此处内容需要评论回复后(审核通过)方可阅读。 下载的 hyperledger-fabric-linux-amd64-1.4.0.tar 压缩包内有 bin 和 config 两个文件夹,hyperledger-fabric-ca-linux-amd64-1.4.0.tar 压缩包内有 bin 文件夹,将两个 bin 文件夹内的二进制文件汇总在一个 bin 文件夹内。 最后将 bin 和 config 文件夹复制到 fabric-samples 文件夹内。 打开bootstrap.sh sudo vim bootstrap.sh 将

代码语言:javascript复制
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

替换为

代码语言:javascript复制
#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

再运行

./bootstrap.sh -b 等待有关的文件下载完 测试环境 ./byfn.sh up 关闭网络 ./byfn.sh down 编译fabric源码得到相关的二进制组件(需有golang语言环境支持): cd $HOME/go/src/github.com/hyperledger/fabric/ make release cd release/linux-amd64/bin 刚才执行./bootstrap.sh -b 命令时,会在scripts目录下生成fabric-samples,将fabric- samples放置到home目录下: cd $HOME/go/src/github.com/hyperledger/fabric/scripts mv ./fabric-samples $HOME/ 在fabric-smaples目录下新建bin目录: cd $HOME/fabric-samples mkdir -p bin/ 将fabric的二进制组件复制到fabric-samples的bin目录下: mv $HOME/go/src/github.com/hyperledger/fabric/release/linux- amd64/bin/* $HOME/fabric-samples/bin/ 将fabric二进制文件配置到环境变量中: sudo gedit /etc/profile 文件中最后添加以下内容: export PATH=$PATH:$HOME/fabric-samples/bin 更新一下: source /etc/profile 重启

0 人点赞