栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

如何基于Docker Swarm多机部署Hyperledger Fabric?

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何基于Docker Swarm多机部署Hyperledger Fabric?

前言
最近在研究如何用Docker Swarm多机部署,也找了很多博客和教程,发现很多说的其实不是很清楚,所有,在踩了很多坑之后,我做一个搭建过程的记录,尽量写的详细一点。

1 概述

本文准备部署一个6个组织,每个组织2个peer节点,其中5个组织维护5个排序节点的Hyperledger Fabric 区块链网络。
Docker Swarm来连通各个主机的节点

本项目开源地址 https://gitee.com/ccccczy77/fabric_docker_swarm

2 前期准备 2.1 服务器准备

准备6台阿里云的服务器,推荐购买按量付费的实例就可以,不用了及时释放掉!(樂樂阿里云打钱!!!本来想用腾讯云的,结果我在腾讯云没有找到按量付费的服务器)

2.2 服务器环境准备
docker
docker-compose
hyperledger fabric的镜像

这一步直接参考fabric的官方文档就可以了。如果能搜到这篇博客的话,这一步肯定已经安装完毕了,就不赘述了。
到这里前期准备就完事了。

3 网络配置

初始化docker swarm

docker swarm init --advertise-addr 

生成一个其他host加入同一个网络的命令

docker swarm join-token manager

把上一步生成的命令放到这一条命令的开头,加上本机的ip
对其余的5台主机都操作一下这一步

 --advertise-addr 

在各个主机都查看一下有没有成功,
(路‍♂️话说这里其实我有点不太明白?为什么各个主机都以manager身份加入?docker swarm中的worker和这个有什么关系!有懂的大佬在教教我!)

docker node ls

接下来生成一个docker network,输入如下命令(这里的basic-network是网络名字,可以自定义哈~ ,不过要和后面指定的名字对应起来!)

docker network create --attachable --driver overlay basic-network
配置节点启动文件

在这里我们配置节点启动文件,然后用docker-compose启动起来。
启动文件仓库里面有!仅供测试用哈。改配置文件实在太头疼了!

下面简答拿一个文件举个例子!

version: '2.4'

volumes:
  peer0.org1.supervisor.com:
  peer1.org1.supervisor.com:

networks:
  basic-network:
    external: true
    name: basic-network

services:

  peer0.org1.supervisor.com:
    container_name: peer0.org1.supervisor.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      #Generic peer variables
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=basic-network
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
      # Peer specific variabes
      - CORE_PEER_ID=peer0.org1.supervisor.com
      - CORE_PEER_ADDRESS=peer0.org1.supervisor.com:7051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:7051
      - CORE_PEER_CHAINCODEADDRESS=peer0.org1.supervisor.com:7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.supervisor.com:8051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.supervisor.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:
      - /var/run/docker.sock:/host/var/run/docker.sock
      - ./crypto-config/peerOrganizations/org1.supervisor.com/peers/peer0.org1.supervisor.com/msp:/etc/hyperledger/fabric/msp
      - ./crypto-config/peerOrganizations/org1.supervisor.com/peers/peer0.org1.supervisor.com/tls:/etc/hyperledger/fabric/tls
      - /var/run/:/host/var/run/
      - ./:/etc/hyperledger/channel/
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 7051:7051
    networks:
      - basic-network

  peer1.org1.supervisor.com:
    container_name: peer1.org1.supervisor.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      #Generic peer variables
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=basic-network
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
      # Peer specific variabes
      - CORE_PEER_ID=peer1.org1.supervisor.com
      - CORE_PEER_ADDRESS=peer1.org1.supervisor.com:8051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:8051
      - CORE_PEER_CHAINCODEADDRESS=peer1.org1.supervisor.com:8052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.supervisor.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.supervisor.com:8051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:
      - /var/run/docker.sock:/host/var/run/docker.sock
      - ./crypto-config/peerOrganizations/org1.supervisor.com/peers/peer1.org1.supervisor.com/msp:/etc/hyperledger/fabric/msp
      - ./crypto-config/peerOrganizations/org1.supervisor.com/peers/peer1.org1.supervisor.com/tls:/etc/hyperledger/fabric/tls
      - /var/run/:/host/var/run/
      - ./:/etc/hyperledger/channel/
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 8051:8051
    networks:
      - basic-network

  cli11:
    container_name: cli11
    image: hyperledger/fabric-tools:latest
    tty: true
    stdin_open: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - FABRIC_LOGGING_SPEC=INFO
      - CORE_PEER_ID=cli11
      - CORE_PEER_ADDRESS=peer0.org1.supervisor.com:7051
      - 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.supervisor.com/peers/peer0.org1.supervisor.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.supervisor.com/peers/peer0.org1.supervisor.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.supervisor.com/peers/peer0.org1.supervisor.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.supervisor.com/users/Admin@org1.supervisor.com/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
      - /var/run/:/host/var/run/
      - ./chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go
      - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
      - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    networks:
      - basic-network

  cli12:
    container_name: cli12
    image: hyperledger/fabric-tools:latest
    tty: true
    stdin_open: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - FABRIC_LOGGING_SPEC=INFO
      - CORE_PEER_ID=cli12
      - CORE_PEER_ADDRESS=peer1.org1.supervisor.com:8051
      - 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.supervisor.com/peers/peer1.org1.supervisor.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.supervisor.com/peers/peer1.org1.supervisor.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.supervisor.com/peers/peer1.org1.supervisor.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.supervisor.com/users/Admin@org1.supervisor.com/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
      - /var/run/:/host/var/run/
      - ./chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go
      - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
      - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    networks:
      - basic-network

下面说明几个网络需要注意的地方

这一块声明用外部网络,basic-network是我的网络的名字。

networks:
  basic-network:
    external: true
    name: basic-network

这里也要是basic-network,和上面对应

    networks:
      - basic-network

这一块的参数也是basic-network

      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=basic-network

OK,到现在为止,好像所有的配置有关的东西都准备好了。接下来就把项目跑起来吧!

4 运行项目

输入启动节点,在6个服务器都启动一下就行了,记得改文件名!

docker-compose -f  -f [] up -d
5 运行

多机部署完毕啦,接下来可以进行一些通道链码的操作啦!
放一张查询成功的截图哈哈✌️✌️

有关多机搭建如何用sdk来进行操作,之后有时间我再尝试吧!
理论上好像只需要更新一下节点的ip就可以!后面再说!

okk,到此为止,就记录完毕啦!

参考链接
https://github.com/sxguan/fabric-network
https://blog.csdn.net/tank_ft/article/details/111233898

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/826102.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号