Hyperledger Fabric development environment construction (transfer)

Build a development environment

Overview

The Hyperledge fabric project is an open source blockchain project from IBM. Github address: https://github.com/hyperledger/fabric

The development environment of Hyperledge fabric is an Ubuntu image running in vagrant (a virtual machine skin on a layer of virtualbox), and running several Docker containers inside the virtual machine. Conceptually, you start a virtual machine on a host, and then start a Docker container on the virtual machine.

Host -> VM -> Docker

i.e.  host -> virtual machine -> Docker

Using vagrant's integrated development environment development allows developers to use their favorite operating system and editor to develop, while allowing the system to run in a development environment consistent with the development team.

  • Note that the host cannot run in a virtual machine, otherwise you will get the error message that VT-x is not available

Environment configuration

Tip: The Virtualization option of the BIOS should be in the CPU or Security settings

step

set GOPATH

The fabric project is developed in Go language, please make sure the GOPATH environment variable is set .

Note for Windows users

If your system is windows, then git clonebefore, do the following:

git config --get core.autocrlf
  • 1

If it  core.autocrlf is  true, it must first be set to false

git config --global core.autocrlf false
  • 1

如果你的core.autocrlf是true的话,运行`vagrant up时,会出现错误 ./setup.sh: /bin/bash^M: bad interpreter: No such file or directory

拷贝Fabric项目

Fabric项目基于 Go语言开发,是一个GO 项目, 我们需要将仓库clone到 GOPATH/src.IfyourGOPATH has multiple path components, then you will want to use the first one. There’s a little bit of setup needed:

cd $GOPATH/src
mkdir -p github.com/hyperledger
cd github.com/hyperledger
  • 1
  • 2
  • 3
git clone https://github.com/hyperledger/fabric.git
  • 1

使用Vagrant启动虚拟机

启动vagrant

cd $GOPATH/src/github.com/hyperledger/fabric/devenv
vagrant up
  • 1
  • 2

运行到这一步时,可能会因为qiang的缘故,不能下载box,我保存了一份在百度云中,可以通过 点击这里 下载,下载了之后,需要使用vagrant添加box,命令如下:

vagrant box add hyperledger/fabric-baseimage virtualbox.box
  • 1

因为我们使用的是本地添加box,但本地添加的box版本号为0,这里fabric的Vagrantfile文件里为我们做了些处理,只要在环境变量中添加一个变量USE_LOCAL_BASEIMAGE,并将其值设置为1即可。这一步很重要,如果不加这一步,那么vagrant仍然会去网上下载(如果的确是去网上直接下载,网速能行的话就无需这么麻烦)。

添加完成后,再次进入devenv目录,然后运行

vagrant up
  • 1

就行了。

等待一段时间,等到虚拟机启动后,就可以进行登录了。

Linux可以使用下面的命令

vagrant ssh
  • 1

SSH登录:

address:127.0.0.1:2222
username:vagrant
password:vagrant
  • 1
  • 2
  • 3

Windows用户的登录则需通过Putty或者Xshell等软件进行。

关于vagrant的使用可以看一下我写这篇简单的教程:http://www.zgljl2012.com/vagrantan-zhuang/

构建fabric

搭建好vagrant开发环境后,接下来就可以build and test fabric了。在你的虚拟机里,也有一个同样的fabric项目,可以通过以下命令打开文件夹:

cd $GOPATH/src/github.com/hyperledger/fabric
  • 1

只要宿主机上的文件一修改,虚拟机里的fabric也就立刻同步修改了,极大的便利了我们的开发过程(可以自己修改一下README.md测试一下)。

注意

Windows 10 用户注意: Windows 10 用户在运行vagrant up时可能会发生错误mitchellh/vagrant#6754,那是因为没有安装Micsoft Visual C++ 下面是下载地址: http://www.microsoft.com/en-us/download/details.aspx?id=8328


转载请注明原文地址:http://blog.csdn.net/zgljl2012/article/details/52896372

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326207856&siteId=291194637