GithubHelp home page GithubHelp logo

fabric-network's Introduction

fabric-network

概述

这是 Hyperledger Fabric 2.x多机环境。它是由两个组织和四个peer和三个使用 Docker Swarm 作为多主机容器环境的排序服务组成的设置。我们首先介绍Docker Swarm,完成了这些步骤,在两个主机网络中建立这个结构网络。

DOCKER SWARM

Docker Swarm 是 Docker 环境中原生的容器编排工具。简而言之,它为跨多个主机的容器提供了一个覆盖网络。这个覆盖网络上的那些容器可以相互通信,就像它们在一台大型主机上一样。好的一面显然是,原始配置只需少量修改即可使用,并且配置中没有编码 IP 等静态信息。在本文中,我们使用 Docker Swarm。

先决条件

  1. docker
  2. docker-compose
  3. fabric-network(克隆 GitHub 代码)

网络拓扑结构

主机1 (组织 -1)

  1. 证书颁发机构 (CA)
  2. 2 个peer(peer0.org1.exampl.com、peer1.org1.example.com)
  3. 2 个orderer(orderer0.example.com、orderer1.example.com)
  4. cli

主机2 (组织-2)

  1. 证书颁发机构 (CA)
  2. 2 个peer(peer0.org2.exampl.com、peer1.org2.example.com)
  3. 3 个orderer (orderer2.example.com)

整体流程

  1. 启动两台包含先决条件的主机。
  2. 形成一个覆盖网络并使所有两个主机加入。
  3. 准备主机 1 上的所有内容,包括配置文件、证书、每个节点的 docker-compose 文件。然后将整个结构复制到所有其他主机。
  4. 使用 docker-compose 启动所有节点。
  5. 创建一个通道并将所有节点加入 mychannel
  6. 安装并实例化 Fabcar 链码。
  7. 调用和查询链码函数。

第 1 步:启动主机

请注意,出于演示目的,我为所有内容(所有 UDP、TCP 和 ICMP)打开了一个安全组。对于生产,请确保您只打开所需的端口。

注意:Docker-swarm 必须打开以下端口 \1. 2377 (TCP) — 集群管理 \2. 7946 (TCP and UDP) — 节点通信 \3. 4789 (TCP and UDP) — 覆盖网络流量

第 2 步:使用 DOCKER SWARM 形成一个 OVERLAY 网络

现在我们可以打开四个终端。

ssh -i <key> ubuntu@<public IP>

从主机1

docker swarm init --advertise-addr <pc-1 ip address>docker swarm join-token manager

使用最后一个输出,将其他主机作为管理器添加到这个群。

从主机2

<output from join-token manager> --advertise-addr <pc-2 ip address>

从主机1,

docker network create --attachable --driver overlay basic-network docker network ls

从主机2,

docker network ls

第3步:在主机1中准备好FABRIC文件并复制给其他人

关键部分之一是确保所有组件共享相同的加密文件。我们将使用主机1创建文件并将它们复制到其他主机。

从主机1,

./create-artifacts.sh

理论上,我们只需要确保身份(证书和签名密钥)遵循所需的方案。组织(例如 org1)的证书由同一 CA (ca.org1) 颁发和签署。为简单起见,在本演示中,我们在 PC -1 中创建所有材料,然后将整个目录 crypto-config 复制到其他主机。

第 4 步:在每个主机中启动容器

我们使用 docker-compose 来启动所有节点。

# from PC -1,
docker-compose -f pc1.yaml up -d# from PC -2,
docker-compose -f pc2.yaml up -d

第5步:创建通道,所有peer加入

由于我们在主机1上只有 CLI,所有命令都是从主机1终端发出的。

./createChannel.sh

第 6 步:安装和实例化 FABCAR 链码

从主机1终端,

将 Fabcar 链码安装到所有peer

./deployChaincode.sh

第 7 步:链码调用和查询

为了演示,根据 Fabcar 的设计,我们首先调用 initLedger 函数在账本中预加载 10 条汽车记录。

./invoke.sh./query.sh

总结

在这个演示中,我们建立了两个具有基本网络的组织。这些容器在两台独立的主机上运行。Docker Swarm 将这两台主机结合在一起,以便运行在不同主机上的容器可以进行通信。我们不再在配置文件上指定静态 IP,所有容器都像在同一台主机上一样相互通信。

fabric-network's People

Contributors

iaintdreamer avatar sxguan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fabric-network's Issues

做到运行./createChannel.sh这个脚本的时候会报以下的错误,不知道怎么解决

Error: error getting endorser client for channel: endorser client failed to connect to localhost:9051: failed to create new connection: connection error: desc = "transport: error while dialing: dial tcp 127.0.0.1:9051: connect: connection refused"
Error: error getting endorser client for channel: endorser client failed to connect to localhost:10051: failed to create new connection: connection error: desc = "transport: error while dialing: dial tcp 127.0.0.1:10051: connect: connection refused"

按文档启动ca服务报错

2021/08/06 16:23:00 [DEBUG] Closing server DBs
Error: Failed to find private key for certificate in '/etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem': Could not find matching private key for SKI: Failed getting key for SKI [[139 72 245 38 116 37 37 241 105 29 217 186 186 99 43 184 244 183 173 46 210 135 27 158 103 32 211 187 55 55 171 87]]: Key with SKI 8b48f526742525f1691dd9baba632bb8f4b7ad2ed2871b9e6720d3bb3737ab57 not found in /etc/hyperledger/fabric-ca-server/msp/keystore

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.