hyperledger fabric 1.0.5 分布式部署 (一)
环境是个人虚拟机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 分布式部署 (一)的更多相关文章
- hyperledger fabric 1.0.5 分布式部署 (八)
gdb debug peer 程序 在开始我们从 github 上download 下来的源码包,实际上已经包含了可执行的 peer 程序,但是该程序是使用 release 方式编译的,并不支持gdb ...
- hyperledger fabric 1.0.5 分布式部署 (七)
fabric 使用 fabric-ca 服务 准备部分 首先需要用户从github上download fabric-ca 的工程代码 cd $GOPATH/src/github.com/hyperle ...
- hyperledger fabric 1.0.5 分布式部署 (六)
如何在相同的peer 节点上创建多个 channel 作者在hyperledger fabric 1.0.5 分布式部署 (五)已经向读者们介绍了一个简单的fabric 的部署流程,那么根据上一篇博客 ...
- hyperledger fabric 1.0.5 分布式部署 (五)
梳理fabric e2e_cli 测试程序的具体步骤 作者在 hyperledger fabric 1.0.5 分布式部署 (一)中给读者们介绍了如何从零开始部署一个测试的 demo 环境,如果细心的 ...
- hyperledger fabric 1.0.5 分布式部署 (四)
chaincode 的开发 作者在hyperledger fabric 1.0.5 分布式部署 (三)中向读者介绍了如何开发fabric 的chaincode,那么实际上chaincode 还有其他的 ...
- hyperledger fabric 1.0.5 分布式部署 (二)
环境:2台 ubuntu 16.04 角色列表 角色 IP地址 宿主端口 docker端口 peer0.org1.example.com 47.93.249.250 7051 7051 pe ...
- hyperledger fabric 1.0.5 分布式部署 (三)
本篇博客主要是向读者介绍 fabric 在部署时的一些细节,还有作者自己学习过程中的心得. 初始化相关密钥的程序,实际上是一个shell脚本,并且结构特别简单 generateArtifacts.sh ...
- hyperledger fabric 1.0.5 分布式部署 (九)
linux 使用vim.ctags 配置fabric 源码阅读环境 首先需要安装 ctags,作者使用apt-get 来安装的,安装的版本是5.9 apt-get install ctags 5.9 ...
- Hyperledger Fabric 1.0 从零开始(十三)——orderer分布式方案
简述 在搭建HyperLedger Fabric环境的过程中,我们会用到一个configtx.yaml文件(可参考Hyperledger Fabric 1.0 从零开始(八)——Fabric多节点集群 ...
随机推荐
- java读流方式,下载网络上的图片
本工具类支持url的list集合,具体实现如下所示: public static void download(ArrayList<String> listUrl, String downl ...
- HZNU 与班尼特·胡迪一起攻破浮空城 【DP】
题目链接 http://acm.hznu.edu.cn/OJ/problem.php?id=2264 思路 从终点往起点走 然后每次更新状态 因为要满足 最短路线 所以其实 只能是 往左走,往下走 或 ...
- delphi如何让程序最小化到任务栏(使用Shell_NotifyIcon API函数)
现在很多的应用程序都有这样一种功能,当用户选择最小化窗口时,窗口不是象平常那样最小化到任务栏上,而是“最小化”成一个任务栏图标.象FoxMail 3.0 NetVampire 3.0等都提供了这样的功 ...
- POJ 1611 The Suspects (并查集+数组记录子孙个数 )
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 24134 Accepted: 11787 De ...
- hdu1010 Tempter of the Bone —— dfs+奇偶性剪枝
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Ja ...
- CSU1553 Good subsequence —— 二分 + RMQ/线段树
题目链接: http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1553 Description Give you a sequence of n n ...
- CISCO-路由器交换机密码恢复
路由器密码恢复: 准备工作:一台PC跟一台路由器用console线相连 工作原理:如果忘记密码被锁在路由器外,通过修复寄存器值来进行修复 默认的寄存器值为0x2102(关闭的),若要恢复口令需要开启这 ...
- NVIDIA GPU 计算能力
Tesla V100# ARCH= -gencode arch=compute_70,code=[sm_70,compute_70] GTX 1080, GTX 1070, GTX 1060, GTX ...
- ubuntu下网络性能测试
iperf的主要功能 TCP 测量网络带宽 报告MSS/MTU值的大小和观测值 支持TCP窗口值通过套接字缓冲 当P线程或Win32线程可用时,支持多线程.客户端与服务端支持同时多重连接 UDP 客户 ...
- atom 的一些东东
一. 配置atom atom 有些插件被墙了, 往往导致无法下载插件, 网上查了一些解决方案, 大部分就两种解决方案. 配置国内源 离线下载插件 1. 配置国内源 Linux 在 /home/user ...