MacOS下搭建Fabric开发环境

更新日期:20190711
参考fabric文档

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的手动下载安装的方式:

下载 StableEdge 版(此处我安装的是Stable版本),安装过程与普通dmg程序相同。
安装完成后启动一下(刚安装成功,这里有一个启动的按钮):
在这里插入图片描述

验证安装成功:

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 <mode> [-c <channel name>] [-t <timeout>] [-d <delay>] [-f <docker-compose-file>] [-s <dbtype>] [-l <language>] [-o <consensus-type>] [-i <imagetag>] [-v]"
  <mode> - 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> - channel name to use (defaults to \"mychannel\")"
  -t <timeout> - CLI timeout duration in seconds (defaults to 10)"
  -d <delay> - delay duration in seconds (defaults to 3)"
  -f <docker-compose-file> - specify which docker-compose file use (defaults to docker-compose-cli.yaml)"
  -s <dbtype> - the database backend to use: goleveldb (default) or couchdb"
  -l <language> - the chaincode language: golang (default), node, or java"
  -o <consensus-type> - the consensus-type of the ordering service: solo (default), kafka, or etcdraft"
  -i <imagetag> - 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

显示下面结果时表示执行成功:
在这里插入图片描述

3.3 down

停掉该网络

./byfn.sh down
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值