Hyperledger Fabric当前最新版本为1.2, 自行参考官方安装文档
https://hyperledger-fabric.readthedocs.io/en/release-1.2/prereqs.html
http://www.javatree.cn/news/e10340bfc0644215a7886bb629f84adc
以Centos7安装为例, 简单说明注意事项。
1. 安装或更新curl
yum install curl
yum update curl
保证尽量新的版本, 后面步骤安装脚本使用curl下载文件
2.docker安装
(1) Docker CE安装参考官方文档
https://docs.docker.com/install/linux/docker-ce/centos/
如果官方的源采访有限制则可使用阿里的源
yum install yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce
官方镜像下载会比较慢,最好修改为国内的镜像地址。 docker存储镜像的目录最好不放系统盘下,最好指向数据盘.
新建或编辑/etc/docker/daemon.json
{
"data-root": "/mnt/sda3/docker-root",
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
启动docker服务
systemctl start docker
(2) Docker Compose
参考官方文档
https://docs.docker.com/compose/install/#install-compose
最好到gitub的release page下载, 当前最新版本1.22.0
https://github.com/docker/compose/releases
curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
3. Go语言
版本需要1.10.x或以上, yum能搜出来的是1.9.4的, 国内是不能直接装的了, 到go语言中文网下载.
https://studygolang.com/dl
wget https://studygolang.com/dl/golang/go1.10.3.linux-amd64.tar.gz
tar -zvxf go1.10.3.linux-amd64.tar.gz
设置GOPATH, 这里编辑全局环境变量/etc/profile
export GOPATH=/mnt/sda3/go
PATH=$GOPATH/bin:$PATH
环境变量生效source /etc/profile
验证下是否生效
echo $GOPATH
go version
4. Node.js
官方下载解压设置到环境变量即可, 注意9.x版本不支持, 需要安装8.9.x或更新
wget https://nodejs.org/dist/v8.11.3/node-v8.11.3-linux-x64.tar.xz
xz -d node-v8.11.3-linux-x64.tar.xz
tar -xvf node-v8.11.3-linux-x64.tar
编辑/etc/profile
export NODE_HOME=/mnt/sda3/node-v8.11.3-linux-x64
PATH=$NODE_HOME/bin:$PATH
生效source /etc/profile
验证是否生效, npm需要5.6版本或更新
node -v
npm -v
5. bootsrap.sh安装fabric-sample
wget https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh
chmod u+x bootstrap.sh
确保docker服务启动 systemctl start docker
确保安装了git客户端 yum install git
执行./bootstrap.sh 进行安装
当前目录下载fabric-samples目录, 里面的bin目录包含了fabric-tools常用的的cryptogen, peer等工具, 这里我们移动bin到一个外部目录并配置到/etc/profile环境变量中
PATH=/mnt/sda3/hyperledger-fabric/bin:$PATH
Export PATH
在阿里云碰到多下载很慢的问题, 这个时候可以尝试手工下载控制台提示下载的文件, 终止bootstrap.sh运行, 手工上传这两个压缩包放fabric-samples目录下, 再运行bootstrap.sh即可跳过。
https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.2.0/hyperledger-fabric-linux-amd64-1.2.0.tar.gz
https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/linux-amd64-1.2.0/hyperledger-fabric-ca-linux-amd64-1.2.0.tar.gz
6. 运行例子
进去/mnt/sda3/fabric-samples/first-network
执行./byfn.sh down先清理下防止以前运行过
再执行./byfn.sh up 如果能看到以下结果就是两个Org,四个Peer的区块链网络运行成功了
Creating network "net_byfn" with the default driver
Creating volume "net_orderer.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_peer1.org1.example.com" with default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating volume "net_peer1.org2.example.com" with default driver
Creating peer0.org1.example.com ... done
Creating peer0.org2.example.com ... done
Creating peer1.org2.example.com ... done
Creating peer1.org1.example.com ... done
Creating orderer.example.com ... done
Creating cli ... done
____ _____ _ ____ _____
/ ___| |_ _| / \ | _ \ |_ _|
\___ \ | | / _ \ | |_) | | |
___) | | | / ___ \ | _ < | |
|____/ |_| /_/ \_\ |_| \_\ |_|
========= All GOOD, BYFN execution completed ===========
_____ _ _ ____
| ____| | \ | | | _ \
| _| | \| | | | | |
| |___ | |\ | | |_| |
|_____| |_| \_| |____/
在阿里云一些环境可能会抛出getaddrinfo异常
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x63 pc=0x7f9d15ded259]
runtime stack:
runtime.throw(0xdc37a7, 0x2a)
/opt/go/src/runtime/panic.go:566 +0x95
runtime.sigpanic()
/opt/go/src/runtime/sigpanic_unix.go:12 +0x2cc
goroutine 64 [syscall, locked to thread]:
runtime.cgocall(0xb08d50, 0xc4203bcdf8, 0xc400000000)
/opt/go/src/runtime/cgocall.go:131 +0x110 fp=0xc4203bcdb0 sp=0xc4203bcd70
net._C2func_getaddrinfo(0x7f9d000008c0, 0x0, 0xc420323110, 0xc4201a01e8, 0x0, 0x0, 0x0)
可以去把/etc/resolv.conf的options配置去掉, 具体原因参考
https://yq.aliyun.com/articles/238940
最后我们看下docker跑了哪些进程,有四个peer,一个orderer,fabric-tool,还有chaincode,我们的实践要开始了。
我将持续分享Hyperledger Fabric的实践心得, 也可以关注微信订阅号"Hyperledger实践"