Hyperledger Fabric开发环境搭建

Hyperledger Fabric开发环境搭建

centos环境下安装

相关软件和工具下载

  1. 下载git
    yum install -y git
    查看版本号:yum --version
  2. 安装docker
    • 安装相关软件包:yum install -y yum-utils device-mapper-persistent-data lvm2
    • 设置yum源:yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    • 查看所有仓库中所有docker版本,并选择特定版本安装: yum list docker-ce --showduplicates | sort -r
    • 安装特定版本的docker:yum install docker-ce-17.12.1.ce
    • 查看是否安装成功:docker --version
    • 将docker加入开机自启动:
      [root@localhost ~]# systemctl start docker
      [root@localhost ~]# systemctl enable docker
  3. 安装pip
    yum -y install epel-release
    yum -y install python-pip
    是否安装成功:pip --version
    更新pip: pip install --upgrade pip
    出现bug:

    先卸载安装的python-pip: sudo yum remove python-pip
    下载get-pip.py文件
    wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
    sudo python get-pip.py

  4. 安装docker-compose
    • 使用pip安装:pip install docker-compose
    • 检查是否安装成功:docker-compose version
    • 如果上述方法安装失败,则使用下述方法:

      sudo curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
      添加可执行权限: sudo chmod +x /usr/local/bin/docker-compose
      测试安装是否成功: sudo docker-compose --version

CLI应用

  1. 创建fabric工作空间
    cd /root/go
    mkdir -p src/github.com/hyperledger
  2. 克隆fabric-samples项目
    cd src/github.com/hyperledger
    git clone https://github.com/hyperledger/fabric-samples.git
  3. 安装特定文件并拉取docker镜像
    cd fabric-samples
    curl -sSL https://bit.ly/2ysbOFE | bash -s
    上述命令无效换为:curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s
    如果还是无法连接到github,则先将bootstrap.sh文件下载下来,再传输到虚拟机上,最后执行下述命令:
    cat bootstrap.sh | bash -s
  4. 拉取docker镜像成功后,显示所有的已下载镜像列表:
  5. 修改go环境变量,添加一个GOPATH环境配置
    export GOPATH=$HOME/go
  6. 将fabric-samples的bin文件夹下上传的这些二进制文件添加到系统PATH中
    export PATH=$GOPATH/src/github.com/hyperledger/fabric-samples/bin:$PATH

ubuntu环境下安装

安装Golang

因为Fabric是基于Go语言开发的,所以首先需要配置好Golang开发环境。

由于某些原因,国内无法从Golang官网上下载Golang,不过好在国内的Golang开发者们搭建的可供国内Golang爱好者分享的平台,可以从这里下载Golang的开发包。

下载完成后,执行如下操作:

$ sudo tar -zxvf ./go1.14.2.linux-amd64.tar.gz -C /usr/local
$ sudo echo "export GOPATH=$HOME/go" >> /etc/profile
$ sudo echo "export GOROOT=/usr/local/go" >> /etc/profile
$ sudo echo "export PATH=$GOPATH/bin:$GOROOT/bin:$PATH" >> /etc/profile
$ source /etc/profile

安装docker

在Fabric网络中,通过docker启动的话,可以简化很多设置,所以接下来我们来安装docker。这里使用阿里源,操作如下:

# 安装一些必要的系统工具  
$ sudo apt update
$ sudo apt install -y git apt-transport-https ca-certificates curl software-properties-common
# 安装GPG证书
$ curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# 更新并安装docker-ce
$ sudo apt update -y
$ sudo apt install -y docker-ce docker-compose
$ sudo systemctl enable docker
$ sudo systemctl start docker
$ sudo usermod -aG docker $(whoami)

下载Fabric-samples

对于初学者,Fabric官方提供了可供初学者学习使用的Fabric-samples。该repo中提供了first-network,执行其中的byfn.sh脚本,可以确认fabric环境是否配置完成。

Fabric-samples提供了bootstrap.sh脚本,执行该脚本不仅可以完成Fabric-samples的下载,还能将fabric网络运行时需要的docker镜像下载完成,操作如下:

$ cd $GOPATH/src/github.com/hyperledger
$ curl -sS https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh -o bootstrap.sh
$ chmod +x bootstrap.sh  
$ ./bootstrap.sh

默认情况下,bootstrap.sh会下载最新版本的fabric。当然也可以通过bootstrap.sh --help来查看更多选项。

bootstrap.sh执行完后,执行如下命令来查看环境是否搭建完成:

$ cd $GOPATH/src/github.com/hyperledger/fabric-samples/test-network  
$ ./network.sh up

posted @ 2021-09-23 20:41  Garrett_Wale  阅读(227)  评论(0编辑  收藏  举报