自己的硕士研究方向和区块链有关,工程上一直以IBM的Hyperledger Fabric为基础进行开发,对该项目关注也有两年了。目前迎来了Hyperledger Fabric v1.4,这也是Fabric的第一个长期支持版本,因此也比较有代表性,故在此和大家分享一下自己的环境搭建过程。

附上v1.4的官方文档:https://hyperledger-fabric.readthedocs.io/en/release-1.4/

环境说明:

  本人测试环境为腾讯云学生机(1Core/RAM 2G/ROM 50G),CentOS 7.5 64位。

Golang 安装配置(非必须)

下载安装包

  1. mkdir download
  2. cd download
    # 从国内站点下载合适的安装包
  1. wget https://studygolang.com/dl/golang/go1.12.4.linux-amd64.tar.gz

解压

  1. tar -C /usr/local/ -xzvf go1.12.4.linux-amd64.tar.gz #解压到/usr/local/go目录下

配置

  1. vim /etc/profile # 配置系统环境变量
  2.  
  3. # 在最下方插入
  4. # Golang 环境变量
  5. export GOROOT=/usr/local/go
  6. export GOPATH=/root/go
  7. export GOBIN=$GOPATH/bin
  8. export PATH=$PATH:$GOROOT/bin
  9. export PATH=$PATH:$GOPATH/bin
  10.  
  11. #使配置的环境变量生效
  12. source /etc/profile
  13. #检查是否配置正确
    go version

说明:Go的环境并非运行的必须条件,但后期调试智能合约可能会用到,而且官网安装说明也提到了需要安装Go。

Node.js 安装配置(非必须)

通过nvm安装Node.js和npm,该步骤也不是运行的必须条件,但后期如果需要node-sdk来开发应用程序的话就需要node环境。(npm源切换可参考npm 淘宝源切换教程)

安装nvm(官方文档:https://github.com/nvm-sh/nvm)

  1. # 安装后重启该会话或重新开一个会话即可生效
  2. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

通过nvm安装Node.js和npm

  1. # 查看当前支持的版本,fabricv1.4要求只支持8.x
  2. nvm ls-remote
  3. # 安装当前8.x LTS的最新版本(会同时安装npm)
  4. nvm install 8.16.
  5. # 检查node.js安装版本
  6. node -v
  7. # 检查npm的安装版本
  8. npm -v

Docker 安装

Docker安装社区版的就可以,参考官方文档:https://docs.docker.com/install/linux/docker-ce/centos/

参考官方文档的第一种通过仓库安装的方式(傻瓜操作的话第三种直接脚本安装更简单)。

p.s. 由于docker-hub镜像仓库在国外,可能会被墙或者很慢,建议大家参考daocloud加速器配置一下仓库,或者用云服务器的可以参考各家的docker仓库源(阿里Docker镜像库、腾讯Docker镜像库等)。

卸载旧版本

  1. sudo yum remove docker \
  2. docker-client \
  3. docker-client-latest \
  4. docker-common \
  5. docker-latest \
  6. docker-latest-logrotate \
  7. docker-logrotate \
  8. docker-engine

安装docker-ce的必需条件

  1. sudo yum install -y yum-utils \
  2. device-mapper-persistent-data \
  3. lvm2

设置稳定版的仓库

  1. sudo yum-config-manager \
  2. --add-repo \
  3. https://download.docker.com/linux/centos/docker-ce.repo

安装docker-ce

  1. yum install docker-ce docker-ce-cli containerd.io

启动docker

  1. sudo systemctl start docker

测试docker是否安装成功

  1. sudo docker run hello-world

Docker Compose 安装

Fabric中节点容器编排使用的使docker-compose,故需要安装docker-compose。官方文档:https://docs.docker.com/compose/install/

下载docker-compose

  1. sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

为docker-compose配置执行权限

  1. sudo chmod +x /usr/local/bin/docker-compose

检查是否安装成功

  1. docker-compose -v

源码获取

通过go get 的方式获取源码,配合git切换分支

获取fabric源码

  1. # 获取fabric源码
  2. go get -u github.com/hyperledger/fabric
  3. # 进入目录 切换分支
  4. cd go/src/github.com/hyperledger/fabric
  5. git checkout v1.4.1

获取fabric-sample源码

  1. go get github.com/hyperledger/fabric-samples
  2. # 进入目录,切换分支
  3. cd go/src/github.com/hyperledger/fabric-samples/
  4. git checkout v1.4.1

获取镜像和二进制文件

我们通过fabric-sample测试

通过脚本获取docker镜像和可执行文件(建议事先配置好docker仓库)

  1. cd go/src/github.com/hyperledger/fabric-samples/scripts/
  2. #此处可能因为网络问题执行时间比较久
  3. bash bootstrap.sh

运行测试

通过fabric-sample中first-network示例测试,执行了一个A和B转账,中间多次查询余额的一个过程。

docker运行需要权限,最好用root身份运行。

找到first-network示例

  1. cd go/src/github.com/hyperledger/fabric-samples/first-network

生成密钥文件

  1. [root@VM_0_39_centos first-network]# bash byfn.sh generate
    Generating certs and genesis block for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
    Continue? [Y/n] y
    proceeding ...
    /root/go/src/github.com/hyperledger/fabric-samples/bin/cryptogen
  2.  
  3. ##########################################################
    ##### Generate certificates using cryptogen tool #########
    ##########################################################
    + cryptogen generate --config=./crypto-config.yaml
    org1.example.com
    org2.example.com
    + res=0
    + set +x
  4.  
  5. /root/go/src/github.com/hyperledger/fabric-samples/bin/configtxgen
    ##########################################################
    #########  Generating Orderer Genesis block ##############
    ##########################################################
    CONSENSUS_TYPE=solo
    + '[' solo == solo ']'
    + configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
    2019-05-03 21:22:43.122 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
    2019-05-03 21:22:43.232 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo
    2019-05-03 21:22:43.232 CST [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
    2019-05-03 21:22:43.338 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 004 orderer type: solo
    2019-05-03 21:22:43.338 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 005 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
    2019-05-03 21:22:43.347 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Generating genesis block
    2019-05-03 21:22:43.347 CST [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block
    + res=0
    + set +x
  6.  
  7. #################################################################
    ### Generating channel configuration transaction 'channel.tx' ###
    #################################################################
    + configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
    2019-05-03 21:22:43.395 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
    2019-05-03 21:22:43.515 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
    2019-05-03 21:22:43.622 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
    2019-05-03 21:22:43.622 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
    2019-05-03 21:22:43.622 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx
    2019-05-03 21:22:43.657 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 006 Writing new channel tx
    + res=0
    + set +x
  8.  
  9. #################################################################
    #######    Generating anchor peer update for Org1MSP   ##########
    #################################################################
    + configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
    2019-05-03 21:22:43.714 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
    2019-05-03 21:22:43.795 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
    2019-05-03 21:22:43.876 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
    2019-05-03 21:22:43.876 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
    2019-05-03 21:22:43.876 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
    2019-05-03 21:22:43.877 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
    + res=0
    + set +x
  10.  
  11. #################################################################
    #######    Generating anchor peer update for Org2MSP   ##########
    #################################################################
    + configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
    2019-05-03 21:22:43.913 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
    2019-05-03 21:22:43.995 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
    2019-05-03 21:22:44.073 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
    2019-05-03 21:22:44.073 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
    2019-05-03 21:22:44.073 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
    2019-05-03 21:22:44.074 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
    + res=0
    + set +x

启动示例

  1. [root@VM_0_39_centos first-network]# bash byfn.sh up
  2. Starting for channel 'mychannel' with CLI timeout of '' seconds and CLI delay of '' seconds
  3. Continue? [Y/n] y
  4. proceeding ...
  5. LOCAL_VERSION=1.4.
  6. DOCKER_IMAGE_VERSION=1.4.
  7. Creating network "net_byfn" with the default driver
  8. Creating volume "net_orderer.example.com" with default driver
  9. Creating volume "net_peer0.org1.example.com" with default driver
  10. Creating volume "net_peer1.org1.example.com" with default driver
  11. Creating volume "net_peer0.org2.example.com" with default driver
  12. Creating volume "net_peer1.org2.example.com" with default driver
  13. Creating orderer.example.com ... done
  14. Creating peer1.org2.example.com ... done
  15. Creating peer1.org1.example.com ... done
  16. Creating peer0.org2.example.com ... done
  17. Creating peer0.org1.example.com ... done
  18. Creating cli ... done
  19. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  20. 2cf554ced6b0 hyperledger/fabric-tools:latest "/bin/bash" second ago Up Less than a second cli
  21. fec18ca70d8d hyperledger/fabric-peer:latest "peer node start" seconds ago Up second 0.0.0.0:->/tcp peer0.org1.example.com
  22. 95427a7d76ce hyperledger/fabric-peer:latest "peer node start" seconds ago Up second 0.0.0.0:->/tcp peer1.org2.example.com
  23. 8c7084b42ea7 hyperledger/fabric-orderer:latest "orderer" seconds ago Up second 0.0.0.0:->/tcp orderer.example.com
  24. 3456e8793e46 hyperledger/fabric-peer:latest "peer node start" seconds ago Up second 0.0.0.0:->/tcp peer1.org1.example.com
  25. aa167f7fcc27 hyperledger/fabric-peer:latest "peer node start" seconds ago Up second 0.0.0.0:->/tcp peer0.org2.example.com
  26. 95271becf126 hello-world "/hello" days ago Exited () days ago pensive_curie
  27.  
  28. ____ _____ _ ____ _____
  29. / ___| |_ _| / \ | _ \ |_ _|
  30. \___ \ | | / _ \ | |_) | | |
  31. ___) | | | / ___ \ | _ < | |
  32. |____/ |_| /_/ \_\ |_| \_\ |_|
  33.  
  34. Build your first network (BYFN) end-to-end test
  35.  
  36. Channel name : mychannel
  37. Creating channel...
  38. + peer channel create -o orderer.example.com: -c mychannel -f ./channel-artifacts/channel.tx --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
  39. # 此处省略日志输出
  40. Installing chaincode on peer1.org2...
  41. + peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
  42. + res=
  43. + set +x
  44. -- ::47.540 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO Using default escc
  45. -- ::47.540 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO Using default vscc
  46. -- ::47.751 UTC [chaincodeCmd] install -> INFO Installed remotely response:<status: payload:"OK" >
  47. ===================== Chaincode is installed on peer1.org2 =====================
  48.  
  49. Querying chaincode on peer1.org2...
  50. ===================== Querying on peer1.org2 on channel 'mychannel'... =====================
  51. Attempting to Query peer1.org2 ... secs
  52. + peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
  53. + res=
  54. + set +x
  55.  
  56. ===================== Query successful on peer1.org2 on channel 'mychannel' =====================
  57.  
  58. ========= All GOOD, BYFN execution completed ===========
  59.  
  60. _____ _ _ ____
  61. | ____| | \ | | | _ \
  62. | _| | \| | | | | |
  63. | |___ | |\ | | |_| |
  64. |_____| |_| \_| |____/

清除示例

执行删除密钥文件,停止并删除容器等操作

  1. [root@VM_0_39_centos first-network]# bash byfn.sh down
  2. Stopping for channel 'mychannel' with CLI timeout of '' seconds and CLI delay of '' seconds
  3. Continue? [Y/n] y
  4. proceeding ...
  5. Stopping cli ... done
  6. Stopping peer0.org1.example.com ... done
  7. Stopping peer1.org2.example.com ... done
  8. Stopping orderer.example.com ... done
  9. Stopping peer1.org1.example.com ... done
  10. Stopping peer0.org2.example.com ... done
  11. Removing cli ... done
  12. Removing peer0.org1.example.com ... done
  13. Removing peer1.org2.example.com ... done
  14. Removing orderer.example.com ... done
  15. Removing peer1.org1.example.com ... done
  16. Removing peer0.org2.example.com ... done
  17. Removing network net_byfn
  18. Removing volume net_orderer.example.com
  19. Removing volume net_peer0.org1.example.com
  20. Removing volume net_peer1.org1.example.com
  21. Removing volume net_peer0.org2.example.com
  22. Removing volume net_peer1.org2.example.com
  23. Removing volume net_orderer2.example.com
  24. WARNING: Volume net_orderer2.example.com not found.
  25. Removing volume net_orderer3.example.com
  26. WARNING: Volume net_orderer3.example.com not found.
  27. Removing volume net_orderer4.example.com
  28. WARNING: Volume net_orderer4.example.com not found.
  29. Removing volume net_orderer5.example.com
  30. WARNING: Volume net_orderer5.example.com not found.
  31. Removing volume net_peer0.org3.example.com
  32. WARNING: Volume net_peer0.org3.example.com not found.
  33. Removing volume net_peer1.org3.example.com
  34. WARNING: Volume net_peer1.org3.example.com not found.
  35. d58e2eba8e9d
  36. aa7c6c5dd7f7
  37. 15ef69f6b748
  38. Untagged: dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab:latest
  39. Deleted: sha256:044ed90bbd20fbc015f1c75f578d17d327b53c599bfa603cf59f8f2b6a3a2749
  40. Deleted: sha256:4c90c84d87522dde761b147e98d803d61e8dd113dce2d612bac7683b1e95a0f0
  41. Deleted: sha256:5916889234775a9d49d5e5f25c5f3e226076e453c7188e3121271c98709c89bc
  42. Deleted: sha256:7729eea67cc67a9d310f5b53bcb40e83b8496cd954d08230efabaa229cc30c41
  43. Untagged: dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9:latest
  44. Deleted: sha256:f214e2732061d2e21dec13fa499296da861eb7da6a29631ee76c139218083197
  45. Deleted: sha256:a4f9f0680f5b42484c8ae4675aec4d3aaf1c591c27bd375813f71ccbb2afca92
  46. Deleted: sha256:d786c76106b411dd66b2d57904a215ca1dfce30ae2adca1127dc95b588655f15
  47. Deleted: sha256:ba3660f49899db646d6b2a2703c4b73cf7a647b1d3a170fb8909a66fccc48c1d
  48. Untagged: dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b:latest
  49. Deleted: sha256:870943518d7142d03509e589e4ea57837c4b092d60dd3097d9f8d113078498a0
  50. Deleted: sha256:5dc11c2c52f40e2883a450528fdd008b4a372aaebbd9c2aec548eb3b8a0b610a
  51. Deleted: sha256:528ba6c50b298c20b9a408fda4284372d0d0c031bbc595b8a309d3513497c355
  52. Deleted: sha256:e85509bd000d5685db47a5031d4e929b08cebdff050f5dd35c903dbd1eabc0a4

Hyperledger Fabric 1.4 快速环境搭建的更多相关文章

  1. HyperLedger Fabric 1.4 基础环境搭建(7)

    学习了前面几章理论知识后,本章开始介绍实践操作,先介绍Fabric基础环境搭建,采用的操作系统为Centos 7 64位,依次介绍Docker安装.Docker-Compose安装.GO语言环境安装. ...

  2. 区块链 Hyperledger Fabric v1.0.0 环境搭建

    前言:最近项目涉及到超级账本,在有些理论知识的基础上,需要整一套环境来. 这是一个特别要注意的事情,笔者之前按照网络上推荐,大部分都是推荐ubuntu系统的,于是下载Ubuntu系统(16.04.5和 ...

  3. Centos7 HyperLedger Fabric 1.4 生产环境部署

    Kafka生产环境部署案例采用三个排序(orderer)服务.四个kafka.三个zookeeper和四个节点(peer)组成,共准备八台服务器,每台服务器对应的服务如下所示: kafka案例网络拓扑 ...

  4. 基于Debian搭建Hyperledger Fabric 2.4开发环境及运行简单案例

    相关实验源码已上传:https://github.com/wefantasy/FabricLearn 前言 在基于truffle框架实现以太坊公开拍卖智能合约中我们已经实现了以太坊智能合约的编写及部署 ...

  5. 区块链之Hyperledger(超级账本)Fabric v1.0 的环境搭建(更新)

    参考链接:https://blog.csdn.net/so5418418/article/details/78355868   https://blog.csdn.net/wgh1015398431/ ...

  6. Hyperledger Fabric手动生成CA证书搭建Fabric网络

    之前介绍了使用官方脚本自动化启动一个Fabric网络,并且所有的证书都是通过官方的命令行工具cryptogen直接生成网络中的所有节点的证书.在开发环境可以这么简单进行,但是生成环境下还是需要我们自定 ...

  7. HyperLedger Fabric 1.4 生产环境动态添加组织及节点

    网易云课堂视频在线教学,地址:https://study.163.com/course/introduction/1209401942.htm 1.1 操作概述      在“kafka生产环境部署” ...

  8. 区块链之Hyperledger(超级账本)Fabric v1.0 的环境搭建(超详细教程)

    https://blog.csdn.net/so5418418/article/details/78355868

  9. HyperLedger Fabric 1.4 生产环境使用ca生成msp和tls(12)

    在上一章:Fabric kafka生产环境部署的基础上部署Fabric CA,使用Fabric CA进行生成公私钥和证书等文件,全部替换cryptogen工具,包括生成TLS相关的私钥和证书等文件.  ...

随机推荐

  1. mini QQ(项目一)

    一个多人聊天工具(C/S结构),实现了如下功能: 一个可视化窗口,支持鼠标点击事件 注册功能,用户可以注册自己的聊天账号, 注册信息包括: 账号名(可以用姓名来替代账号,支持中文), 密码(聊天框输入 ...

  2. .NET CORE 控制台应用程序配置log4net日志文件

    使用文件格式记录日志 1.新建一个.NET CORE控制台应用程序,添加log4net.dll引用,打开工具->NuGet包管理器->管理解决方案的NuGet程序包. 2.在NuGet-解 ...

  3. beyond compare全文件夹比较,仅显示变化的文件

    beyond  compare是一款非常优秀的文件夹同步比较工具,赞. 非常强大的一点就是给定两个文件夹可以自动列出所有不同的文件和子文件夹,但是有一点可能很多人碰到过,也就是需要一个个点开才能重新比 ...

  4. js联动三级

    自己研究三级加看网上的例子得出来的 <select id="province">   <option value="">----请选择- ...

  5. REDELK的安装和使用

    0x00 前言简介 红队的SIEM有两个主要目标: 通过创建一个集中管理中心,收集和丰富来自多个 teamservers的所有相关操作日志,增强了红队人员的可用性和概述.这对于在操作中进行历史搜索以及 ...

  6. WC.exe(Java实现)

    一.GitHub项目地址:https://github.com/nullcjm/mypage 二.项目相关要求: wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数.这个项目要求写 ...

  7. Java操作ElasticSearch之创建客户端连接

    Java操作ElasticSearch之创建客户端连接 3 发布时间:『 2017-09-11 17:02』  博客类别:elasticsearch  阅读(3157) Java操作ElasticSe ...

  8. django framework插件类视图分页

    分页 继承APIView类的视图中添加分页 from rest_framework.pagination import PageNumberPagination class MyPageNumberP ...

  9. 七、Docker启动tocmat 8

    七.Docker启动tocmat 8 tomcat官方镜像中tomcat:7 和tomcat:8的目录. CATALINA_BASE: /usr/local/tomcat CATALINA_HOME: ...

  10. 04、rpm+yum+tar解压

    Linux 下安装软件: 1.rpm 软件包的安装 一般安装都用 rpm -ivh 包路径及名字 如:rpm -ivh /soft/RealPlayer11GOLD.rpm   --安装/soft下 ...