环境是个人虚拟机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() file for glibc resolver() generated by resolvconf()
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 100.100.2.136
nameserver 100.100.2.138
# options timeout: attempts: 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 启动网络时,遇到以下错误

-- ::26.153 UTC [msp] GetDefaultSigningIdentity -> DEBU 00d Obtaining default signing identity
-- ::26.153 UTC [msp/identity] Sign -> DEBU 00e Sign: plaintext: 0AC3060A1508021A06089EEDAAD30522...4570C57BBD33F75CA1D12B806981FAF1
-- ::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: +0x95
runtime.sigpanic()
/opt/go/src/runtime/sigpanic_unix.go: +0x2cc
....
....
....
goroutine [select]:
net.cgoLookupIP(0x141ef60, 0xc4203bea20, 0x7ffef3e2fa83, 0x13, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/opt/go/src/net/cgo_unix.go: +0x2f5
net.lookupIP(0x141ef60, 0xc4203bea20, 0x7ffef3e2fa83, 0x13, 0x0, 0x0, 0x0, 0x0, 0x0)
/opt/go/src/net/lookup_unix.go: +0xf9
net.glob..func11(0x141ef60, 0xc4203bea20, 0xe45178, 0x7ffef3e2fa83, 0x13, 0xc4203d46c8, 0x720699, 0xc4203d4708, 0xc4203d4718, 0x455cc0)
/opt/go/src/net/hook.go: +0x52
net.lookupIPContext.func1(0xc42014eea0, 0x7ffef3e2fa83, 0x18, 0x0)
/opt/go/src/net/lookup.go: +0x5c
internal/singleflight.(*Group).doCall(0x143be60, 0xc4203bc870, 0x7ffef3e2fa83, 0x13, 0xc420177c20)
/opt/go/src/internal/singleflight/singleflight.go: +0x3c
created by internal/singleflight.(*Group).DoChan
/opt/go/src/internal/singleflight/singleflight.go: +0x339
!!!!!!!!!!!!!!! Channel creation failed !!!!!!!!!!!!!!!!
================== ERROR !!! FAILED to execute End--End Scenario ==================

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

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

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

-- ::10.812 UTC [msp/identity] Sign -> DEBU 00e Sign: plaintext: 0AC3060A1508021A0608F6EFAAD30522...18EB3B68613F5C67FA2AB9ACD1F9C144
-- ::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 ) 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--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

hyperledger fabric 1.0.5 分布式部署 (一)的更多相关文章

  1. hyperledger fabric 1.0.5 分布式部署 (八)

    gdb debug peer 程序 在开始我们从 github 上download 下来的源码包,实际上已经包含了可执行的 peer 程序,但是该程序是使用 release 方式编译的,并不支持gdb ...

  2. hyperledger fabric 1.0.5 分布式部署 (七)

    fabric 使用 fabric-ca 服务 准备部分 首先需要用户从github上download fabric-ca 的工程代码 cd $GOPATH/src/github.com/hyperle ...

  3. hyperledger fabric 1.0.5 分布式部署 (六)

    如何在相同的peer 节点上创建多个 channel 作者在hyperledger fabric 1.0.5 分布式部署 (五)已经向读者们介绍了一个简单的fabric 的部署流程,那么根据上一篇博客 ...

  4. hyperledger fabric 1.0.5 分布式部署 (五)

    梳理fabric e2e_cli 测试程序的具体步骤 作者在 hyperledger fabric 1.0.5 分布式部署 (一)中给读者们介绍了如何从零开始部署一个测试的 demo 环境,如果细心的 ...

  5. hyperledger fabric 1.0.5 分布式部署 (四)

    chaincode 的开发 作者在hyperledger fabric 1.0.5 分布式部署 (三)中向读者介绍了如何开发fabric 的chaincode,那么实际上chaincode 还有其他的 ...

  6. hyperledger fabric 1.0.5 分布式部署 (二)

    环境:2台 ubuntu 16.04 角色列表 角色 IP地址 宿主端口 docker端口  peer0.org1.example.com  47.93.249.250  7051  7051  pe ...

  7. hyperledger fabric 1.0.5 分布式部署 (三)

    本篇博客主要是向读者介绍 fabric 在部署时的一些细节,还有作者自己学习过程中的心得. 初始化相关密钥的程序,实际上是一个shell脚本,并且结构特别简单 generateArtifacts.sh ...

  8. hyperledger fabric 1.0.5 分布式部署 (九)

    linux 使用vim.ctags 配置fabric 源码阅读环境 首先需要安装 ctags,作者使用apt-get 来安装的,安装的版本是5.9 apt-get install ctags 5.9 ...

  9. Hyperledger Fabric 1.0 从零开始(十三)——orderer分布式方案

    简述 在搭建HyperLedger Fabric环境的过程中,我们会用到一个configtx.yaml文件(可参考Hyperledger Fabric 1.0 从零开始(八)——Fabric多节点集群 ...

随机推荐

  1. c# vs2010 连接access数据库

    第一次在博客园写博文,由于文采不怎么好,即使是自己很熟悉的东西,写起来也会感觉到不知从何讲起,我想写的多了就好了. 这篇文章主要是介绍怎么用c# 语言 vs2010连接access数据库的,连接字符串 ...

  2. mysql的事务隔离级别及其使用场景

    1 什么是事务隔离级别 事务隔离指的是事务之间同步关系. 2 食物隔离级别的分类 第一隔离级别,脏读级别 在脏读级别下,第一个事务修改了某个数据,但是还没有提交,第二个事务可以读取到这个未提及的数据. ...

  3. hdu1015 Safecracker —— 回溯

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1015 代码1: #include<stdio.h>//hdu1015 #include&l ...

  4. 网页兼容性测试(工具使用IETESTER、Firefox、360安全浏览器)

    网页兼容性测试主要是针对不同的浏览器进行的测试.由于用户浏览器的不同,往往都会使我们的网页发生页面样式错乱,图片无法显示等问题.对于前端开发工程师来说,确保代码在各种主流浏览器的各个版本中都能正常显示 ...

  5. hdu 2188 悼念512汶川大地震遇难同胞——选拔志愿者(Bash Game)

    题意:从0开始捐款,每次不超过m元,首先达到n元的获胜 思路:等同于从n开始,每次取不超过m,首先达到0的获胜.(Bash Game) #include<iostream> #includ ...

  6. php的CURL使用及例子

    使用PHP的cURL库可以简单和有效地去抓网页.你只需要运行一个脚本,然后分析一下你所抓取的网页,然后就可以以程序的方式得到你想要的数据了.无论是你想从从一个链接上取部分数据,或是取一个XML文件并把 ...

  7. css 内容超出宽度自动换行

    1. word-break:break-all;只对英文起作用,以字母作为换行依据2. word-wrap:break-word; 只对英文起作用,以单词作为换行依据 PS:要设定宽度!

  8. FFmpeg+FFserver流媒体服务器介绍

    ffmpeg和ffserver配合使用可以实现实时的流媒体服务.   一.理解 里边主要有如下四个东西,搞清楚他们之间的关系就差不多明白了. 1. ffmpeg   2. ffserver   3. ...

  9. js正则匹配字符串

    这里我第一时间想到的就是用 js 的search 和 match ,其中最常见的是match: 1. str.search(regexp):search()方法不支持全局搜索,因为会忽略正则表达式参数 ...

  10. Struts文件上传下载

    Struts配置文件: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PU ...