MacOS下搭建Fabric开发环境

更新日期:20190711
参考fabric文档

文章目录

  • 1. 准备工作
    • 1.1 install cURL
    • 1.2 Docker and Docker Compose
    • 1.3 Go Programming Language
    • 1.4 Node.js Runtime and NPM
    • 1.5 Python
  • 2 安装示例,二进制和镜像
  • 3 BYFN
    • 3.0 help
    • 3.1 generate
    • 3.2 up
    • 3.3 down

1. 准备工作

1.1 install cURL

Mac自带有cUrl,因此我未执行安装。官方文档中建议安装最新版:

Download the latest version of the cURL tool if it is not already installed or if you get errors running the curl commands from the documentation.

查看当前cURL版本

AppledeiMac-2:~ apple$ curl --version
curl 7.54.0 (x86_64-apple-darwin18.0) libcurl/7.54.0 LibreSSL/2.6.5 zlib/1.2.11 nghttp2/1.24.1
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz HTTP2 UnixSockets HTTPS-proxy 

1.2 Docker and Docker Compose

You will need the following installed on the platform on which you will be operating, or developing on (or for), Hyperledger Fabric:

MacOSX, *nix, or Windows 10: Docker Docker version 17.06.2-ce or greater is required.
Older versions of Windows: Docker Toolbox - again, Docker version Docker 17.06.2-ce or greater is required.

按照菜鸟教程中docker的手动下载安装的方式:

下载 Stable 或 Edge 版(此处我安装的是Stable版本),安装过程与普通dmg程序相同。
安装完成后启动一下(刚安装成功,这里有一个启动的按钮):
MacOS下搭建Fabric开发环境_第1张图片

验证安装成功:

AppledeiMac-2:~ apple$ docker --version
Docker version 18.09.2, build 6247962
AppledeiMac-2:~ apple$ docker-compose --version
docker-compose version 1.23.2, build 1110ad01

1.3 Go Programming Language

Hyperledger Fabric uses the Go Programming Language for many of its components.
Go version 1.12.x is required.

采用菜鸟教程:Go语言环境安装
下载对应安装包–执行安装,安装后的路径 /usr/local/go

添加go相关的环境变量:

# 打开配置文件
sudo vi ~/.bash_profile
# 添加环境变量
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
# 保存配置
esc -- :wq

1.4 Node.js Runtime and NPM

If you will be developing applications for Hyperledger Fabric leveraging the Hyperledger Fabric SDK for Node.js, you will need to have version 8.9.x of Node.js installed.

之前装过,验证安装结果:

AppledeiMac-2:~ apple$ node -v
v10.15.0
AppledeiMac-2:~ apple$ npm -v
6.4.1

1.5 Python

MacOS自带有Python 2.7,验证:

AppledeiMac-2:~ apple$ python --version
Python 2.7.10

2 安装示例,二进制和镜像

# 切换到当前苹果用户目录下
cd /Users/apple

# 使用cURL(注意此处使用的https与文档不同)
curl -sSL https://bit.ly/2ysbOFE | bash -s

3 BYFN

cd fabric-samples/first-network

3.0 help

Usage:
byfn.sh  [-c ] [-t ] [-d ] [-f ] [-s ] [-l ] [-o ] [-i ] [-v]"
   - one of 'up', 'down', 'restart', 'generate' or 'upgrade'"
    - 'up' - bring up the network with docker-compose up"
    - 'down' - clear the network with docker-compose down"
    - 'restart' - restart the network"
    - 'generate' - generate required certificates and genesis block"
    - 'upgrade'  - upgrade the network from version 1.3.x to 1.4.0"
  -c  - channel name to use (defaults to \"mychannel\")"
  -t  - CLI timeout duration in seconds (defaults to 10)"
  -d  - delay duration in seconds (defaults to 3)"
  -f  - specify which docker-compose file use (defaults to docker-compose-cli.yaml)"
  -s  - the database backend to use: goleveldb (default) or couchdb"
  -l  - the chaincode language: golang (default), node, or java"
  -o  - the consensus-type of the ordering service: solo (default), kafka, or etcdraft"
  -i  - the tag to be used to launch the network (defaults to \"latest\")"
  -v - verbose mode"
byfn.sh -h (print this message)"

Typically, one would first generate the required certificates and
genesis block, then bring up the network. e.g.:"

  byfn.sh generate -c mychannel"
  byfn.sh up -c mychannel -s couchdb"
  byfn.sh up -c mychannel -s couchdb -i 1.4.0"
  byfn.sh up -l node"
  byfn.sh down -c mychannel"
  byfn.sh upgrade -c mychannel"

Taking all defaults:"
      byfn.sh generate"
      byfn.sh up"
      byfn.sh down"

3.1 generate

./byfn.sh generate

3.2 up

bring the network up with one of the following commands:

./byfn.sh up
The above command will compile Golang chaincode images and spin up the corresponding containers. Go is the default chaincode language, however there is also support for Node.js and Java chaincode. If you’d like to run through this tutorial with node chaincode, pass the following command instead:

# we use the -l flag to specify the chaincode language
# forgoing the -l flag will default to Golang

./byfn.sh up -l node
Note

For more information on the Node.js shim, please refer to its documentation.

Note

For more information on the Java shim, please refer to its documentation.

Тo make the sample run with Java chaincode, you have to specify -l java as follows:

./byfn.sh up -l java
Note

Do not run both of these commands. Only one language can be tried unless you bring down and recreate the network between.

In addition to support for multiple chaincode languages, you can also issue a flag that will bring up a five node Raft ordering service or a Kafka ordering service instead of the one node Solo orderer. For more information about the currently supported ordering service implementations, check out The Ordering Service.

To bring up the network with a Raft ordering service, issue:

./byfn.sh up -o etcdraft
To bring up the network with a Kafka ordering service, issue:

./byfn.sh up -o kafka

显示下面结果时表示执行成功:
MacOS下搭建Fabric开发环境_第2张图片

3.3 down

停掉该网络

./byfn.sh down

你可能感兴趣的:(Mac使用,区块链)