怎样部署Hyperledger Fabric多节点(二)

在各众多学弟和作者的一通瞎捣鼓下,我们又做了一点微小的工作。现在记录下多节点部署的一些事情。

本文主要参考http://www.cnblogs.com/studyzy/p/7237287.html

这次瞎捣鼓一共用了5台服务器,具体参数如下,具体ip地址以ip0,ip1……代替:

ip节点标志hostnameorganization
ip0ordererorderer.example.cnorderer
ip1sp0peer0.org1.example.cnorg1
ip2sp1peer1.org1.example.cnorg1
ip3sp2peer0.org2.example.cnorg2
ip4sp3peer1.org2.example.cnorg2

首先选定一台服务器作为orderer节点,假设其ip为ip0,以下操作都在orderer上完成

  • 生成公私钥,创世区块,证书等
cd /opt/gopath/src/github.com/hyperledger/fabric/examples/e2e_cli/
generateArtifacts.sh mychannel

设置docker-compose-peer.yaml和docker-compose-order.yaml文件。还是在e2e_cli下。

cp docker-compose-cli.yaml docker-compose-peer.yaml
cp docker-compose-cli.yaml docker-compose-orderer.yaml

分别对两个文件修改

docker-compose-peer.yaml修改如下:

把peer1.org1,peer0.org2,peer2.org2的配置删除,

peer0.org1加上orderer的影射,

cli下的command删掉,

cli的depends_on:只保留peer0.org1

加上extra_hosts

最后如下

# Copyright IBM Corp. All Rights Reserved.
#
  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:ip0"

  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: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.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
    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

    extra_hosts:
       - "orderer.example.com:ip0"
       - "peer0.org1.example.com:ip1"
       - "peer1.org1.example.com:ip2"
       - "peer0.org2.example.com:ip3"
       - "peer1.org2.example.com:ip4"
                                               

docker-compose-orderer.yaml如下修改:

只保留orderer的配置

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

version: '2'

services:

  orderer.example.com:
    extends:
      file:   base/docker-compose-base.yaml
      service: orderer.example.com
    container_name: orderer.example.com

修改base/docker-compose-base.yaml文件,将所有peer的端口映射都改为相同的

这是原来的:

   ports:
      - 7051:7051
      - 7052:7052
      - 7053:7053
……
   ports:
      - 8051:7051
      - 8052:7052
      - 8053:7053
……
   ports:
      - 9051:7051
      - 9052:7052
      - 9053:7053
……
   ports:
      - 10051:7051
      - 10052:7052
      - 10053:7053

改成

   ports:
      - 7051:7051
      - 7052:7052
      - 7053:7053
……
   ports:
      - 7051:7051
      - 7052:7052
      - 7053:7053
……
   ports:
      - 7051:7051
      - 7052:7052
      - 7053:7053
……
   ports:
      - 7051:7051
      - 7052:7052
      - 7053:7053

最后把e2e_cli复制到四个peer上。

在peer上对docker-compose-peer.yaml做一点微小的改动

以peer1.org1.example.com为例,改成:(主要是peer0换成peer1,加上peer0的映射)

version: '2'

services:

  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:ip0" 
     - "peer0.org1.example.com:ip1"

  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=peer1.org1.example.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.example.com/peers/peer1.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/peer1.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/peer1.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 
    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: 
      - peer1.org1.example.com 
    extra_hosts: 
       - "orderer.example.com:ip0"
       - "peer0.org1.example.com:ip1"
       - "peer1.org1.example.com:ip2"
       - "peer0.org2.example.com:ip3"
       - "peer1.org2.example.com:ip4"

 

现在回到orderer下,先启动orderer

docker-compose -f docker-compose-orderer.yaml up -d

可以看到启动了两个镜像

来到peer下,启动peer

docker-compose -f docker-compose-peer.yaml up -d

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值