hyperledger fabric 1.0.5 分布式部署 (二)
环境:2台 ubuntu 16.04
角色列表
| 角色 | IP地址 | 宿主端口 | docker端口 |
| peer0.org1.example.com | 47.93.249.250 | 7051 | 7051 |
| peer1.org1.example.com | 47.93.249.250 | 7051 | 8051 |
| peer0.org2.example.com | 47.93.249.250 | 7051 | 9051 |
| peer1.org2.example.com | 47.93.249.250 | 7051 | 10051 |
| cli | 47.93.249.250 | NULL | NULL |
| orderer.example.com | 47.94.244.156 | 7050 | 7050 |
- 环境初始化
2台机器的fabric 环境初始化方法,读者参考作者之前写的一片文章:http://www.cnblogs.com/chenfool/p/8353425.html,并且确保两台机器都能够正常运行 e2e_cli 的测试程序。
在完成e2e_cli 程序的测试后,读者一定要清理环境。
./network_setup.sh down mychannel
- 分布式部署(1)
按照角色列表,首先在 47.94.244.156 机器上,目录切换到 /opt/gopath/src/github.com/hyperledger/fabric/examples/e2e_cli ,然后复制一份 docker-compose 的配置文件
cp docker-compose-cli.yaml docker-compose-test.yaml
对 docker-compose-test.yaml 配置进行修改,修改后的内容如下
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
# version: '' services: orderer.example.com:
extends:
file: base/docker-compose-base.yaml
service: orderer.example.com
container_name: orderer.example.com
执行以下命令,生成公私钥、证书、创世区块等,该命令执行后,会在本地生成 channel-artifacts 和 crypto-config 目录。
读者这里需要注意一下,在执行 generateArtifacets.sh 脚本时,需要确保 channel-artifacts 目录已经存在,否则可能会报错
chmod generateArtifacts.sh
./generateArtifacts.sh mychannel
将channel-artifacts 和 crypto-config 目录文件拷贝到 47.93.249.250 机器的相同目录
scp -r crypto-config root@47.93.249.250:/opt/gopath/src/github.com/hyperledger/fabric/examples/e2e_cli
scp -r channel-artifacts root@47.93.249.250:/opt/gopath/src/github.com/hyperledger/fabric/examples/e2e_cli
启动docker 进程
docker-compose -f docker-compose-test.yaml up -d
docker 进程启动后,读者可以通过以下命令查看正在运行的进程
docker ps
- 分布式部署(2)
读者此时在 47.93.249.250 机器上切换目录到 /opt/gopath/src/github.com/hyperledger/fabric/examples/e2e_cli,同样的复制一份docker-compose 的配置文件
cp docker-compose-cli.yaml docker-compose-test.yaml
对 docker-compose-test.yaml 配置进行修改,修改后的内容如下
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
# version: '' services: peer0.org1.example.com:
container_name: peer0.org1.example.com
extends:
file: base/docker-compose-base.yaml
service: peer0.org1.example.com
extra_hosts:
- "orderer.example.com:47.94.244.156" peer1.org1.example.com:
container_name: peer1.org1.example.com
extends:
file: base/docker-compose-base.yaml
service: peer1.org1.example.com
extra_hosts:
- "orderer.example.com:47.94.244.156"
- "peer0.org1.example.com:47.93.249.250" peer0.org2.example.com:
container_name: peer0.org2.example.com
extends:
file: base/docker-compose-base.yaml
service: peer0.org2.example.com
extra_hosts:
- "orderer.example.com:47.94.244.156" peer1.org2.example.com:
container_name: peer1.org2.example.com
extends:
file: base/docker-compose-base.yaml
service: peer1.org2.example.com
extra_hosts:
- "orderer.example.com:47.94.244.156"
- "peer0.org2.example.com:47.93.249.250" cli:
container_name: cli
image: hyperledger/fabric-tools
tty: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_LOGGING_LEVEL=DEBUG
- CORE_PEER_ID=cli
- CORE_PEER_ADDRESS=peer0.org1.example.com:
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
#command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT'
volumes:
- /var/run/:/host/var/run/
- ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
depends_on:
- peer0.org1.example.com
- peer1.org1.example.com
- peer0.org2.example.com
- peer1.org2.example.com
extra_hosts:
- "orderer.example.com:47.94.244.156"
- "peer0.org1.example.com:47.93.249.250"
- "peer1.org1.example.com:47.93.249.250"
- "peer0.org2.example.com:47.93.249.250"
- "peer1.org2.example.com:47.93.249.250"
启动该台机器的docker 相关服务
docker-compose -f docker-compose-test.yaml up -d
docker 进程启动后,读者可以通过以下命令查看正在运行的进程
docker ps
此时屏幕上将输出的类似如下信息

读者可以看到docker中的服务映射的端口号的区别,然后针对不同的docker 服务,继续修改 scripts/script.sh 脚本中的 setGlobals 函数(大约是32行)中,各个docker 服务的端口号
vi scripts/script.sh
setGlobals () {
if [ $ -eq -o $ -eq ] ; then
CORE_PEER_LOCALMSPID="Org1MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
if [ $ -eq ]; then
CORE_PEER_ADDRESS=peer0.org1.example.com:
else
CORE_PEER_ADDRESS=peer1.org1.example.com:
fi
else
CORE_PEER_LOCALMSPID="Org2MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
if [ $ -eq ]; then
CORE_PEER_ADDRESS=peer0.org2.example.com:
else
CORE_PEER_ADDRESS=peer1.org2.example.com:
fi
fi
env |grep CORE
}
将最新的 scripts/script.sh 脚本上传到docker 的cli 镜像中
注意:c05d72aef89b 是作者docker 的cli 容器编号,具体使用方法可以参考:http://blog.csdn.net/u011596455/article/details/76862271,并且将script.sh 脚本上传cli 容器后,该脚本将一直保存在cli 的容器中(包括重启容器服务)
docker cp scripts/script.sh c05d72aef89b:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
不需要从宿主机器拷贝script.sh 脚本到 cli 中,因为 docker-compose-test.yaml 配置文件中,已经将宿主的script.sh 脚本挂载到cli 中了
volumes:
- /var/run/:/host/var/run/
- ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
- init fabric 集群环境
选择其中一台机器进入docker cli 镜像的shell 环境,作者选择了 47.93.249.250 进行操作
docker exec -it cli bash
再执行script.sh 脚本
./scripts/script.sh mychannel
然后集群就开始真正的初始化,等待所有的操作都结束后,将出现如下信息

到这里,fabric 的集群环境就部署好了,如果读者想部署更多机器的fabric 环境,也可以照葫芦画瓢地进行配置和部署
参考博客:
http://www.cnblogs.com/aberic/p/7541470.html
http://www.cnblogs.com/aberic/p/7542167.html
http://blog.csdn.net/u011596455/article/details/76862271
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 分布式部署 (三)
本篇博客主要是向读者介绍 fabric 在部署时的一些细节,还有作者自己学习过程中的心得. 初始化相关密钥的程序,实际上是一个shell脚本,并且结构特别简单 generateArtifacts.sh ...
- hyperledger fabric 1.0.5 分布式部署 (一)
环境是个人虚拟机ubuntu 16.04 64 位版本 前期用户需要先安装好:gcc.g++.git 软件 安装 golang 首先给环境安装一个 go 语言环境,版本最好在1.8 以上 golang ...
- hyperledger fabric 1.0.5 分布式部署 (九)
linux 使用vim.ctags 配置fabric 源码阅读环境 首先需要安装 ctags,作者使用apt-get 来安装的,安装的版本是5.9 apt-get install ctags 5.9 ...
- Hyperledger Fabric 1.0 从零开始(十二)——fabric-sdk-java应用【补充】
在 Hyperledger Fabric 1.0 从零开始(十二)--fabric-sdk-java应用 中我已经把官方sdk具体改良办法,即使用办法发出来了,所有的类及文件都是完整的,在文章的结尾也 ...
随机推荐
- 2018-11-9-匿名函数&递归函数初识
1.匿名函数(lambda) 2.递归函数初识
- 推荐一个非常好的 IntelliJ IDEA 教程
教程地址:https://github.com/judasn/IntelliJ-IDEA-Tutorial 作者博客:http://www.youmeek.com/category/software- ...
- javascript --- 声明提前(学习笔记)
声明提升 未声明变量 console.log(a); 在没有定义 a 的情况下,直接使用,会报错. 声明变量 console.log(a); var a = 2; 输出结果:undefined 并不会 ...
- NOIP考前感悟
闭关这么久,后来突然后悔自己前几天和暑假的状态很頽 不然进步也还能多一点吧 还好提前发现了,最后也还是努力了一把 也算不枉费自己的选择吧 从初中开始学习OI,到头来也没有什么成果 但还好自己高一 也还 ...
- A Windows GUI for Appium
A Windows GUI for Appium If you are new to Appium then please see the Getting started guide for more ...
- [2017-10-25]Abp系列——集成消息队列功能(基于Rebus.Rabbitmq)
本系列目录:Abp介绍和经验分享-目录 前言 由于提交给ABP作者的集成消息队列机制的PR还未Review完成,本篇以Abplus中的代码为基准来介绍ABP集成消息队列机制的方案. Why 为什么需要 ...
- 03-树1 树的同构(25 point(s)) 【Tree】
03-树1 树的同构(25 point(s)) 给定两棵树T1和T2.如果T1可以通过若干次左右孩子互换就变成T2,则我们称两棵树是"同构"的.例如图1给出的两棵树就是同构的,因为 ...
- C++模板(二)【转】
本文转自:http://www.cnblogs.com/gw811/archive/2012/10/25/2738929.html C++模板 模板是C++支持参数化多态的工具,使用模板可以使用户为类 ...
- HDU 1878(1Y) (判断欧拉回路是否存在 奇点个数为0 + 一个联通分量 *【模板】)
欧拉回路 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- POJ2389 —— 高精度乘法
直接上代码了: #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib& ...