本文介绍Ubuntu 18.04环境下如何配置Fabric开发环境。

安装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"
$ 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/first-network
$ ./byfn up

之后,脚本会自动创建一个fabric网络,创建一个chaincode以及执行简单的操作。最后,执行成功之后,会出现下面的内容:


......
===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' ===================== Installing chaincode on peer1.org2...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
2020-04-25 07:12:55.347 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-04-25 07:12:55.347 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2020-04-25 07:12:55.637 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
===================== Chaincode is installed on peer1.org2 ===================== Querying chaincode on peer1.org2...
===================== Querying on peer1.org2 on channel 'mychannel'... =====================
Attempting to Query peer1.org2 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x 90
===================== Query successful on peer1.org2 on channel 'mychannel' ===================== ========= All GOOD, BYFN execution completed =========== _____ _ _ ____
| ____| | \ | | | _ \
| _| | \| | | | | |
| |___ | |\ | | |_| |
|_____| |_| \_| |____/

要关闭刚才启动的fabric网络,操作如下:

$ ./byfn down

本文采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可。

Ubuntu18.04安装Fabric的更多相关文章

  1. Ubuntu18.04 安装 Fabric & 使用 Fabric 测试网络

    前言: 本文介绍在 Ubuntu 18.04 中安装 Fabric, 并对 官方文档中的一个小案例(Using the Fabric test network)进行测试. 目的: 初步了解 Fabri ...

  2. Ubuntu18.04安装mysql5.7

    Ubuntu18.04安装mysql5.7 1.1安装 首先执行下面三条命令: # 安装mysql服务 sudo apt-get install mysql-server # 安装客户端 sudo a ...

  3. Ubuntu18.04安装RabbitMQ

    Ubuntu18.04安装RabbitMQ 2018年06月10日 19:32:38 dmfrm 阅读数:2492    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog ...

  4. ubuntu18.04 安装mysql不出现设置 root 帐户的密码问题(装)

    ubuntu18.04 安装mysql不出现设置 root 帐户的密码问题      https://blog.csdn.net/NeptuneClouds/article/details/80995 ...

  5. ubuntu18.04 安装hadoop 2.7.3+hive 2.3.4

    1. 安装hadoop 详细请参见本人的另外一片博文<Hadoop 2.7.3 分布式集群安装> 2. 下载hive 2.3.4 解压文件到/opt/software -bin.tar.g ...

  6. Ubuntu18.04安装Virtualenv虚拟环境

    在Ubuntu18.04安装Virtualenv虚拟环境 [实验环境]: 在这台电脑上已经安装了python3 [安装参考] 1.查看是否已安装virtualenv virtualenv --vers ...

  7. Ubuntu18.04安装thunderbird并设置中文

    Ubuntu18.04安装thunderbird并设置中文 安装thunderbird sudo apt-get install thunderbird 安装中文包 sudo apt-get inst ...

  8. Ubuntu18.04安装Docker, centos7安装Docker

    Ubuntu18.04安装Docker 第一种方法从Ubuntu的仓库直接下载安装: 安装比较简单,这种安装的Docker不是最新版本,不过对于学习够用了,依次执行下面命令进行安装. $ sudo a ...

  9. Ubuntu18.04安装和配置Java JDK11并卸载自带OpenJDK

    卸载自带的OpenJDK方法: 在终端执行命令:sudo apt-get remove openjdk* Ubuntu18.04安装JDK11.0.2 前面步骤一样,可参考:https://www.c ...

随机推荐

  1. 886A. ACM ICPC#均值分配问题(暴力)

    题目出处:http://codeforces.com/problemset/problem/886/A 题目大意:已知六个人得分,问是否能分成两个三人队使得每个队伍得分加和相等 #include< ...

  2. SLAM资料

    当下SLAM方案的总体介绍 http://wwwbuild.net/roboteasy/908066.html slam基础知识 https://www.zhihu.com/question/3518 ...

  3. 0x10 - PostgreSQL 安装之 CentOS7 + Patroni

    PostgreSQL + CentOS7 + Patroni 背景 PostgreSQL 的高可用环境 环境 CentOS 7 pg01 (192.168.1.120) pg02 (192.168.1 ...

  4. [GX/GZOI2019]特技飞行(扫描线+置换)

    感觉是6题中最难的一题,其实这题是一个二合一: 第一问:给定平面上若干点和k个关键点,关键点覆盖一个45°倾斜的正方形范围r,求有多少点被至少一个关键点覆盖.这个可以曼哈顿转切比雪夫距离,然后再扫描线 ...

  5. rsync配置文件

    vim /etc/rsyncd.conf motd file = /etc/rsyncd.motd #设置服务器信息提示文件,在该文件中编写提示信息 transfer logging = yes #开 ...

  6. day18-5个内置方法

    # 1. __str__方法: 必须return class Goods: def __str__(self): return 'apple' g = Goods() print(g) #apple, ...

  7. 2017Google开发者大会

    2017年12月14日有幸去上海跨国采购中心参加了2017Google开发者大会,这个大会有很多很有意思的展会以及技术分享.主题涵盖 Android.移动网络.Firebase.机器学习.云服务.AR ...

  8. ubuntu .bashrc文件添加jdk后无法登录的解决方案

    1. 快捷键(ctl-alt-f2)进入虚拟终端 2. 执行export PATH=/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/ ...

  9. 常用JS图片滚动(无缝、平滑、上下左右滚动)

    常用JS图片滚动(无缝.平滑.上下左右滚动)代码大全 <head><-----></head><body> <!--向下滚动代码开始-->& ...

  10. C#函数的基础应用

    C#函数的基础应用 函数之前的知识回顾 数据类型--变量常量--运算符表达式--语句(顺序,分支,循环)--数组--函数 程序里的函数:能完成一个相对独立功能的代码模块. 数学里的函数:高度抽象. 函 ...