环境是个人虚拟机ubuntu 16.04 64 位版本

前期用户需要先安装好:gcc、g++、git 软件

  • 安装 golang

首先给环境安装一个 go 语言环境,版本最好在1.8 以上

golang 下载地址:https://golang.org/doc/install?download=go1.8.5.linux-amd64.tar.gz (貌似要***)

解压 golang 包

tar -zxvf /root/go1.8.5.linux-amd64.tar.gz  -C /opt

设置GOPATH

创建一个GOPATH 目录

mkdir -p /opt/gopath

设置 ~/.bashrc 环境配置文件

export GOROOT=/opt/go
export GOPATH=/opt/gopath
export PATH=$PATH:$GOROOT/bin:${GOPATH}/bin

然后source 让其生效

source ~/.bashrc

下载 gopm,gopm 执行文件将在 /opt/gopath/bin 目录下,执行以下go 命令前,需要确保系统已经安装了 git 命令

go get -u github.com/gpmgo/gopm

  • 修改apt-get 的软件源,调整为国内源
sed -i "s/us./cn./g" /etc/apt/sources.list

或者直接使用 aliyun 的apt-get 源,直接将以下内容写入到  /etc/apt/source.list 文件

deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
##测试版源
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
# 源码
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
##测试版源
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
# Canonical 合作伙伴和附加
deb http://archive.canonical.com/ubuntu/ xenial partner

然后更新以下apt-get 的库表

apt-get update

  • ubuntu 安装系统依赖库,如果安装失败,可以先apt-get update 一下
apt-get install -y libsnappy-dev zlib1g-dev libbz2-dev libltdl-dev libtool 

  • ubuntu 安装docker

安装一些基础库

apt-get install apt-transport-https ca-certificates

新增GPG 密钥

apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

增加docker 的下载源

echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" > /etc/apt/sources.list.d/docker.list

更新apt-get 源

apt-get update

查看可以安装的 docker 版本

apt-cache policy docker-engine

安装docker

apt-get install docker-engine

查看docker 版本

docker version

启动 docker 服务

service docker start

安装 docker-compose

由于 docker-compose 需要依赖 python-pip ,利用apt-get 安装python-pip

apt-get install python-pip

利用 pip 安装 docker-compose

pip install docker-compose

安装完成后,执行以下命令验证是否安装成功

docker-compose version

  • 从 github 上获取代码

创建目录

mkdir -p $GOPATH/src/github.com/hyperledger ; \
cd $GOPATH/src/github.com/hyperledger 

使用 git download 源码

git clone https://github.com/hyperledger/fabric.git

切换一下路径

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

切换 fabric 的版本

git checkout v1.0.5

安装一些 golang 的库

(如果是利用docker 镜像源下载fabric 镜像的话,这些依赖包貌似没有太大的用处,用户可以不安装)

go get -u github.com/gpmgo/gopm ;
go get github.com/golang/protobuf/protoc-gen-go ;
go get github.com/kardianos/govendor ;
go get github.com/golang/lint/golint ;
go get github.com/onsi/ginkgo/ginkgo ;
go get github.com/axw/gocov/... ; go get github.com/client9/misspell/cmd/misspell ; go get github.com/Aleksi/gocov-xml ; gopm get -g -d golang.org/x/tools/cmd/goimports ; go install golang.org/x/tools/cmd/goimports ;

配置aliyun 的docker 镜像源,加速下载

aliyun的 docker 镜像仓库地址:

https://cr.console.aliyun.com/?spm=5176.2020520152.1001.13.2d9d45eej2T7DB#/accelerator

注册登录后,按照下图操作,获取到属于自己的镜像地址

在shell 中执行

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{"registry-mirrors": ["https://********.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

切换路径

cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli

修改download-dockerimages.sh 文件权限

chmod 755 download-dockerimages.sh

下载fabric 的相关docker 镜像,由于修改了docker 源,所以整体来说下载速度还挺快

./download-dockerimages.sh -c x86_64-1.0.5 -f x86_64-1.0.5

  • 部署和测试 e2e 应用

切换路径

cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli 

修改 /etc/resolv.conf 配置,将 options timeout:2 attempts:3 rotate single-request-reopen 内容注释掉,作者修改后的内容如下

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 100.100.2.136
nameserver 100.100.2.138
# options timeout:2 attempts:3 rotate single-request-reopen

执行启动命令,它会启动一个 mychannel 的channel

./network_setup.sh up mychannel

成功后有如下截图

进入到docker 的shell 中

docker exec -it cli bash

查看a 用户有多少余额

peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'

显示下图

如果要转帐20 元给b,执行以下命令

peer chaincode invoke -o orderer.example.com:7050  --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem  -C mychannel -n mycc -c '{"Args":["invoke","a","b","20"]}'

再来查看a的余额,就变为70元

  • 关闭e2e_cli 的demo服务

退出docker 容器的命令行模式

exit

关闭 myChannel

./network_setup.sh down myChannel

到此,fabric 环境的搭建和演示就结束了。

错误解决:

1 在对 fabric 进行编译时,make docker 出错,错误信息如下

mkdir -p build/image/ccenv/payload
cp build/docker/gotools/bin/protoc-gen-go build/bin/chaintool build/goshim.tar.bz2 build/image/ccenv/payload
cp: 无法获取"build/docker/gotools/bin/protoc-gen-go" 的文件状态(stat): 没有那个文件或目录
make: *** [build/image/ccenv/payload] 错误 1

解决方法,将 protoc-gen-go 工具到对应的目录

cp /opt/gopath/bin/protoc-gen-go build/docker/gotools/bin/

2 在启动 e2e 应用时出错

如果出现以下错误,则证明 docker-compose 工具没有成功安装,需要用户自己安装

./network_setup.sh:行66: docker-compose: 未找到命令
ERROR !!!! Unable to pull the images 

3 在启动 e2e 应用时出错

如果出现以下错误

2018-01-25 08:11:11.384 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
Error: Error getting endorser client channel: PER:404 - Error trying to connect to local peer
/opt/gopath/src/github.com/hyperledger/fabric/peer/common/common.go:116 github.com/hyperledger/fabric/peer/common.GetEndorserClient
/opt/gopath/src/github.com/hyperledger/fabric/peer/channel/channel.go:149 github.com/hyperledger/fabric/peer/channel.InitCmdFactory
/opt/gopath/src/github.com/hyperledger/fabric/peer/channel/join.go:138 github.com/hyperledger/fabric/peer/channel.join
/opt/gopath/src/github.com/hyperledger/fabric/peer/channel/join.go:42 github.com/hyperledger/fabric/peer/channel.joinCmd.func1
/opt/gopath/src/github.com/hyperledger/fabric/vendor/github.com/spf13/cobra/command.go:599 github.com/hyperledger/fabric/vendor/github.com/spf13/cobra.(*Command).execute /opt/gopath/src/github.com/hyperledger/fabric/vendor/github.com/spf13/cobra/command.go:689 github.com/hyperledger/fabric/vendor/github.com/spf13/cobra.(*Command).ExecuteC /opt/gopath/src/github.com/hyperledger/fabric/vendor/github.com/spf13/cobra/command.go:648 github.com/hyperledger/fabric/vendor/github.com/spf13/cobra.(*Command).Execute /opt/gopath/src/github.com/hyperledger/fabric/peer/main.go:118 main.main /opt/go/src/runtime/proc.go:192 runtime.main /opt/go/src/runtime/asm_amd64.s:2087 runtime.goexit Caused by: x509: certificate is valid for peer0.org1.example.com, peer0, not peer1.org1.example.com Usage: peer channel join [flags] Flags: -b, --blockpath string Path to file containing genesis block Global Flags: --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint --logging-level string Default logging level and overrides, see core.yaml for full syntax -o, --orderer string Ordering service endpoint --test.coverprofile string Done (default "coverage.cov") --tls Use TLS when communicating with the orderer endpoint -v, --version Display current version of fabric peer server !!!!!!!!!!!!!!! After 5 attempts, PEER1 has failed to Join the Channel !!!!!!!!!!!!!!!! ================== ERROR !!! FAILED to execute End-2-End Scenario ==================

和以下错误

2018-01-25 08:12:03.436 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-01-25 08:12:03.436 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-01-25 08:12:03.442 UTC [grpc] Printf -> DEBU 003 Failed to dial orderer.example.com:7050: connection error: desc = "transport: authentication handshake failed: x509: certificate signed by unknown authority (possibly because of \"x509: ECDSA verification failure\" while trying to verify candidate authority certificate \"tlsca.example.com\")"; please retry.
Error: Error connecting due to  rpc error: code = Internal desc = connection error: desc = "transport: authentication handshake failed: x509: certificate signed by unknown authority (possibly because of \"x509: ECDSA verification failure\" while trying to verify candidate authority certificate \"tlsca.example.com\")"
Usage:peer channel create [flags]Flags:-c, --channelID string   In case of a newChain command, the channel ID to create.-f, --file string        Configuration transaction file generated by a tool such as configtxgen for submitting to orderer -t, --timeout int Channel creation timeout (default 5) Global Flags: --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint --logging-level string Default logging level and overrides, see core.yaml for full syntax -o, --orderer string Ordering service endpoint --test.coverprofile string Done (default "coverage.cov") --tls Use TLS when communicating with the orderer endpoint -v, --version Display current version of fabric peer server !!!!!!!!!!!!!!! Channel creation failed !!!!!!!!!!!!!!!! ================== ERROR !!! FAILED to execute End-2-End Scenario ==================

都是因为环境遗留的问题

解决方式,重新关闭网络

./network_setup.sh down mychannel

如果是在阿里云机器上部署fabric ,在e2e_cli 启动网络时,遇到以下错误

2018-01-26 05:03:26.153 UTC [msp] GetDefaultSigningIdentity -> DEBU 00d Obtaining default signing identity
2018-01-26 05:03:26.153 UTC [msp/identity] Sign -> DEBU 00e Sign: plaintext: 0AC3060A1508021A06089EEDAAD30522...4570C57BBD33F75CA1D12B806981FAF1
2018-01-26 05:03:26.153 UTC [msp/identity] Sign -> DEBU 00f Sign: digest: A5892BF4C08D07882B34D959932CFA784DE00E1B29D40411B1CF8B59C16DF557
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x63 pc=0x7ff4023cb259]runtime stack:
runtime.throw(0xddc771, 0x2a)/opt/go/src/runtime/panic.go:566 +0x95
runtime.sigpanic()/opt/go/src/runtime/sigpanic_unix.go:12 +0x2cc
....
....
....
goroutine 34 [select]:
net.cgoLookupIP(0x141ef60, 0xc4203bea20, 0x7ffef3e2fa83, 0x13, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)/opt/go/src/net/cgo_unix.go:209 +0x2f5
net.lookupIP(0x141ef60, 0xc4203bea20, 0x7ffef3e2fa83, 0x13, 0x0, 0x0, 0x0, 0x0, 0x0)/opt/go/src/net/lookup_unix.go:70 +0xf9
net.glob..func11(0x141ef60, 0xc4203bea20, 0xe45178, 0x7ffef3e2fa83, 0x13, 0xc4203d46c8, 0x720699, 0xc4203d4708, 0xc4203d4718, 0x455cc0)/opt/go/src/net/hook.go:19 +0x52
net.lookupIPContext.func1(0xc42014eea0, 0x7ffef3e2fa83, 0x18, 0x0)/opt/go/src/net/lookup.go:119 +0x5c
internal/singleflight.(*Group).doCall(0x143be60, 0xc4203bc870, 0x7ffef3e2fa83, 0x13, 0xc420177c20)/opt/go/src/internal/singleflight/singleflight.go:93 +0x3c
created by internal/singleflight.(*Group).DoChan/opt/go/src/internal/singleflight/singleflight.go:86 +0x339
!!!!!!!!!!!!!!! Channel creation failed !!!!!!!!!!!!!!!!
================== ERROR !!! FAILED to execute End-2-End Scenario ==================

用户则需要修改 /etc/resolv.conf 配置,将 options timeout:2 attempts:3 rotate single-request-reopen 这一行内容注释掉

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 100.100.2.136
nameserver 100.100.2.138
# options timeout:2 attempts:3 rotate single-request-reopen

这个解决方法是从 https://yq.aliyun.com/articles/238940 看到的,作者试过,给增加 GODEBUG=netdns=go 环境变量也不好使,只会又出现以下问题

2018-01-26 05:09:10.812 UTC [msp/identity] Sign -> DEBU 00e Sign: plaintext: 0AC3060A1508021A0608F6EFAAD30522...18EB3B68613F5C67FA2AB9ACD1F9C144
2018-01-26 05:09:10.812 UTC [msp/identity] Sign -> DEBU 00f Sign: digest: E5BC4EB4ED536D53AC743587E0AD9FD2BAB2EFC9C6A1775D5BA8ADFC9252566C
Error: Got unexpected status: BAD_REQUEST
Usage:peer channel create [flags]Flags:-c, --channelID string   In case of a newChain command, the channel ID to create.-f, --file string        Configuration transaction file generated by a tool such as configtxgen for submitting to orderer-t, --timeout int        Channel creation timeout (default 5)Global Flags:--cafile string              Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint--logging-level string       Default logging level and overrides, see core.yaml for full syntax-o, --orderer string             Ordering service endpoint--test.coverprofile string   Done (default "coverage.cov")--tls                        Use TLS when communicating with the orderer endpoint-v, --version                    Display current version of fabric peer server!!!!!!!!!!!!!!! Channel creation failed !!!!!!!!!!!!!!!!
================== ERROR !!! FAILED to execute End-2-End Scenario ==================

而真正能够彻底解决的方法,就是将 /etc/resolv.conf 注释掉  options timeout:2 attempts:3 rotate single-request-reopen ,就能够正常启动了

参考博客:

源码编译fabric hyperledger 1.0:

http://www.tk4479.net/oliverlyn/article/details/78443686

http://www.tk4479.net/remote_roamer/article/details/73733426

http://www.tk4479.net/so5418418/article/details/78355868

一个系列文档,值得学习:

http://www.bijishequ.com/authorarticle.html?author=Aberic

ubuntu 安装 fabric 教程:

http://www.cnblogs.com/studyzy/p/7437157.html

离线安装 docker :

http://www.yunweipai.com/archives/20324.html

安装docker-compose:

http://blog.csdn.net/womenrendeme/article/details/76904553

错误文件解答:

http://blog.csdn.net/iflow/article/details/77951610

启动 docker 的7050 和 7051 等端口的方式:

http://shouce.jb51.net/blockchain_guide/fabric/v0.6/install.html

解决 阿里云上 启动 e2e_cli demo 失败的问题 【重要】

https://yq.aliyun.com/articles/238940

转载于:https://www.cnblogs.com/chenfool/p/8353425.html

hyperledger fabric 1.0.5 分布式部署 (一)相关推荐

  1. Hyperledger Fabric 1.0 从零开始(八)——Fabric多节点集群生产部署

    6.1.平台特定使用的二进制文件配置 该方案与Hyperledger Fabric 1.0 从零开始(五)--运行测试e2e类似,根据企业需要,可以控制各节点的域名,及联盟链的统一域名.可以指定单独节 ...

  2. Hyperledger Fabric 2.0 官方文档中文版 第6章 教程(上)

    Hyperledger Fabric 2.0 官方文档中文版第6章 教程上 总目录 6.教程(上) 将智能合约部署到通道 启动网络 Logspout设置 打包智能合约 安装链码包 批准链码定义 将链码 ...

  3. Hyperledger Fabric 2.0 官方文档中文版 第3章 关键概念

    Hyperledger Fabric 2.0 官方文档中文版 第3章 关键概念 总目录 3.关键概念 引言 什么是区块链? 区块链为什么有用? 什么是Hyperledger Fabric? Hyper ...

  4. Hyperledger Fabric 2.0 官方文档中文版 第5章 开发应用程序

    Hyperledger Fabric 2.0 官方文档中文版 第5章 开发应用程序 总目录 5.开发应用程序 情景 PaperNet网络 介绍参与者 分析 商业票据生命周期 交易 账本 过程和数据设计 ...

  5. Hyperledger Fabric 2.0 官方文档中文版 第1章 引言

    Hyperledger Fabric 2.0 官方文档中文版 第1章 引言 总目录 1.引言 Hyperledger Fabric 模块化 许可区块链与无许可区块链 智能合约 新途径 隐私和保密 可插 ...

  6. Hyperledger Fabric 1.0 从零开始(十二)——fabric-sdk-java应用

    Hyperledger Fabric 1.0 从零开始(十)--智能合约(参阅:Hyperledger Fabric Chaincode for Operators--实操智能合约) Hyperled ...

  7. 搭建区块链浏览器——基于hyperledger fabric 1.0,MySQL容器

    搭建区块链浏览器--基于hyperledger fabric 1.0,MySQL容器 区块链 hyperledger fabric 浏览器 MySQL docker  Contents 环境要求 分支 ...

  8. 3.Hyperledger Fabric v2.0 CA组件

    Hyperledger Fabric v2.0 CA组件 目的: 通过CA服务生成msp证书和tls证书,并启动fabric网络 由于使用CA生成证书时,需要注册为各个组织生成证书,为了便于理解,所以 ...

  9. Hyperledger Fabric 2.0 官方文档中文版 第6章 教程(下)

    Hyperledger Fabric 2.0 官方文档中文版 第6章 教程下 总目录 6.教程(下) 使用CouchDB 为什么使用CouchDB? 在Hyperledger Fabric中启用Cou ...

最新文章

  1. [蓝桥杯2016初赛]交换瓶子
  2. 面试突击第 3 期 | Redis 如何实现查询附近的人?视频实战版
  3. 关于数据预处理的7个重要知识点,全在这儿了!
  4. Python 进阶 之 enumerate()函数
  5. ASP.NET Web 页面生命历程中的一天
  6. 拖动布局之保存布局页面
  7. 2018年计算机职称考试冲刺,2018年中级会计职称考试冲刺阶段学习计划
  8. 计算机网络按信息传输介质的性能来划分,第3章 计算机网络基础和 Internet 应用...
  9. 前端 linux ps,Linux ps命令
  10. c语言驾校信息管理系统,驾校综合信息管理系统下载_驾校综合信息管理系统v1.1免费版-这家软件站...
  11. php服务器搬迁失败原因
  12. quot;多看nbsp;fornbsp;kindle3”升级包下载
  13. 红米6A刷LineageOS17.1
  14. 东华大学专业英语 词汇学习
  15. python保存图片的常用方法
  16. perl linux yum,Linux CentOS6.5(x86_64)安装Perl5.26
  17. mysql安装卡在最后一步解决方案(附带万能安装方案)
  18. 简单解释“DNA动了”是什么意思?
  19. mybatis的日志打印关闭
  20. C/C++实习面试(一)

热门文章

  1. 达梦查询一周内,一月内,一年内的数据
  2. 八进制、十六进制,补码
  3. Linux波浪号含义
  4. sweetalert2中ajax用法,SweetAlert2 使用教程
  5. 转载:设计模式之装饰模式(Decorator)
  6. Java FileReader
  7. 即使没有翅膀,心。。。。。。也要飞翔
  8. 谈Spring的事务管理
  9. Vue中Vuex的五个属性和基本用法
  10. 杭电oj HDOJ 1018 Big Number(斯特林公式求大数阶乘的位数)