创建自己的区块链网络 四

Posted 患孤

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了创建自己的区块链网络 四相关的知识,希望对你有一定的参考价值。

这里写目录标题

前言

上次我们修改了configtx.yaml文件,那么到这里我们也就修改的差不多了,但是还有一个文件,这个文件要修改的内容很多,如果手动去修改很容易出错。那么接下来我们就来修改docker-compose-base.yaml 文件。

系列文章直通车

名称链接
创建自己的区块链网络 一点击此处
创建自己的区块链网络 二点击此处
创建自己的区块链网络 三点击此处
创建自己的区块链网络 四点击此处

修改docker-compose-base.yaml文件

那么现在我们便需要修改此文件,这里要修改的地方很多,很容易出错,所以大家在此处要小心一点。
此文件主要指定了Orderer节点还有Peer节点的主要配置信息。

1、明确文件信息

那么我们要修改它就需要知道这个文件内容的主要作用,这个文件内容的主要作用如下:
Orderer节点

名称字段作用
environmentORDERER_GENERAL_GENESISFILE指定在Orderer容器中初始区块的所在路径,由volumes中的…/channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block指定主机到Docker的映射。
ORDERER_GENERAL_LOCALMSPID指定当前Orderer容器的唯一MSPID。
ORDERER_GENERAL_LOCALMSPDIR指定当前Orderer容器的MSP所在路径。
ORDERER_GENERAL_TLS_ENABLED是否开启TLS验证。
ORDERER_GENERAL_TLS_PRIVATEKEY指定私钥所在路径。
ORDERER_GENERAL_TLS_CERTIFICAT指定证书所在路径。
ORDERER_GENERAL_TLS_ROOTCAS指定受信任的CA根证书所在路径。
working_dir进入容器后的默认工作目录。
volumes指定系统中的初始区块配置文件、MSP、TLS目录映射到Docker容器中的指定路径下。
ports指定当前节点的监听端口。

Peer节点容器

名称字段作用
extends基本信息来源于哪个文件。
environment指定容器的ID、监听地址及端口号、本地MSPID,大体与Orderer中的environment部分相同。
volumes将系统的msp及tls目录映射到容器中的指定路径下。
ports指定当前节点的监听端口。

来源1

2、修改文件

那么接下来我们便来修改此文件。
首先先看下源文件:

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

version: '2'

services:

  orderer.example.com:
    container_name: orderer.example.com
    extends:
      file: peer-base.yaml
      service: orderer-base
    volumes:
        - ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
        - ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp
        - ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
        - orderer.example.com:/var/hyperledger/production/orderer
    ports:
      - 7050:7050

  peer0.org1.example.com:
    container_name: peer0.org1.example.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer0.org1.example.com
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:7051
      - CORE_PEER_CHAINCODEADDRESS=peer0.org1.example.com:7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.example.com:8051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
        - peer0.org1.example.com:/var/hyperledger/production
    ports:
      - 7051:7051

  peer1.org1.example.com:
    container_name: peer1.org1.example.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer1.org1.example.com
      - CORE_PEER_ADDRESS=peer1.org1.example.com:8051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:8051
      - CORE_PEER_CHAINCODEADDRESS=peer1.org1.example.com:8052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:8051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls
        - peer1.org1.example.com:/var/hyperledger/production

    ports:
      - 8051:8051

  peer0.org2.example.com:
    container_name: peer0.org2.example.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer0.org2.example.com
      - CORE_PEER_ADDRESS=peer0.org2.example.com:9051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:9051
      - CORE_PEER_CHAINCODEADDRESS=peer0.org2.example.com:9052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:9052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:9051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.example.com:10051
      - CORE_PEER_LOCALMSPID=Org2MSP
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls
        - peer0.org2.example.com:/var/hyperledger/production
    ports:
      - 9051:9051

  peer1.org2.example.com:
    container_name: peer1.org2.example.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer1.org2.example.com
      - CORE_PEER_ADDRESS=peer1.org2.example.com:10051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:10051
      - CORE_PEER_CHAINCODEADDRESS=peer1.org2.example.com:10052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:10052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.example.com:10051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.example.com:9051
      - CORE_PEER_LOCALMSPID=Org2MSP
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls:/etc/hyperledger/fabric/tls
        - peer1.org2.example.com:/var/hyperledger/production
    ports:
      - 10051:10051

其实大家跟之前的crypto-config.yaml源文件对比下,发现这里面有很多都是对应crypto-config.yaml,名称还有域名,那么我们只需要照葫芦画瓢,把这个文件修改的对应crypto-config.yaml文件不就可以了吗?那么接下来就开始修改。
当然我们不可能一个个手动去改,我们可以在Goland中选中代码然后Ctrl+R快捷键来查找修改。

那么接下来我们修改过后的文件是这样的,我都有写注释的,大家对照着来就好了。

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

version: '2'

services:

  orderer.slzce.com: #crypto-config.yaml的Orderer下面的域名对应 所有的example修改为slzce
    container_name: orderer.slzce.com
    extends:
      file: peer-base.yaml
      service: orderer-base
    volumes:
        - ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
        - ../crypto-config/ordererOrganizations/slzce.com/orderers/orderer.slzce.com/msp:/var/hyperledger/orderer/msp
#        - ../crypto-config/ordererOrganizations/slzce.com/orderers/orderer.slzce.com/tls/:/var/hyperledger/orderer/tls
#        TLS加密传输我们不需要删除即可
        - orderer.slzce.com:/var/hyperledger/production/orderer
    ports:
      - 7050:7050

  node1.organization1.slzce.com: # 这里需要把peer0改为node1 把org1改为organization1
    container_name: node1.organization1.slzce.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=node1.organization1.slzce.com
      - CORE_PEER_ADDRESS=node1.organization1.slzce.com:7051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:7051
      - CORE_PEER_CHAINCODEADDRESS=node1.organization1.slzce.com:7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
      - CORE_PEER_GOSSIP_BOOTSTRAP=node2.organization1.slzce.com:8051 #这里需要注意一点 node1就改成他前面一个及node1->node2  node2->node1 下同
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=node1.organization1.slzce.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP  #这里的Org1不需要修改,因为我们没有修改mspid 下同
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/organization1.slzce.com/peers/node1.organization1.slzce.com/msp:/etc/hyperledger/fabric/msp
#        - ../crypto-config/peerOrganizations/organization1.slzce.com/peers/node1.organization1.slzce.com/tls:/etc/hyperledger/fabric/tls
     #  TLS 删除
        - node1.organization1.slzce.com:/var/hyperledger/production
    ports:
      - 7051:7051

  node2.organization1.slzce.com: # 这里需要把peer1改为node2 把org1改为organization1
    container_name: node2.organization1.slzce.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=node2.organization1.slzce.com
      - CORE_PEER_ADDRESS=node2.organization1.slzce.com:8051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:8051
      - CORE_PEER_CHAINCODEADDRESS=node2.organization1.slzce.com:8052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=node1.organization1.slzce.com:8051 #这里需要注意一点 node1就改成他前面一个及node1->node2  node2->node1 下同
      - CORE_PEER_GOSSIP_BOOTSTRAP=node1.organization1.slzce.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP #这里的Org1不需要修改,因为我们没有修改mspid 下同
    volumes:
        - /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/organization1.slzce.com/peers/node2.organization1.slzce.com/msp:/etc/hyperledger/fabric/msp
#        - ../crypto-config/peerOrganizations/organization1.slzce.com/peers/node2.organization1.slzce.com/tls:/etc/hyperledger/fabric/tls
        # TLS 删除
        - node2.organization1.slzce.com:/var/hyperledger/production

    ports:
      - 17051:7051

# 这里直接拷贝上面两个 然后修改就可以了
  node1.organization2.slzce.com: # 这 把把organization1改为organization2
    container_name: node1.organization2.slzce.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=node1.organization2.slzce.com
      - CORE_PEER_ADDRESS=node1.organization2.slzce.com:7051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:7051
      - CORE_PEER_CHAINCODEADDRESS=node1.organization2.slzce.com:7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
      - CORE_PEER_GOSSIP_BOOTSTRAP=node2.organization2.slzce.com:8051 #这里需要注意一点 node1就改成他前面一个及node1->node2  node2->node1 下同
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=node1.organization2.slzce.com:7051
      - CORE_PEER_LOCALMSPID=Org2MSP  #这里的Org1不需要修改,因为我们没有修改mspid 下同 对应organization2
    volumes:
      - /var/run/:/host/var/run/
      - ../crypto-config/peerOrganizations/organization2.slzce.com/peers/node1.organization2.slzce.com/msp:/etc/hyperledger/fabric/msp
      #        - ../crypto-config/peerOrganizations/organization2.slzce.com/peers/node1.organization2.slzce.com/tls:/etc/hyperledger/fabric/tls
      #  TLS 删除
      - node1.organization2.slzce.com:/var/hyperledger/production
    ports:
      - 27051:7051

  node2.organization2.slzce.com: # 这里需要把peer1改为node2 把org1改为organization2
    container_name: node2.organization2.slzce.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=node2.organization2.slzce.com
      - CORE_PEER_ADDRESS=node2.organization2.slzce.com:8051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:8051
      - CORE_PEER_CHAINCODEADDRESS=node2.organization2.slzce.com:8052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=node1.organization2.slzce.com:8051 #这里需要注意一点 node1就改成他前面一个及node1->node2  node2->node1 下同
      - CORE_PEER_GOSSIP_BOOTSTRAP=node1.organization2.slzce.com:7051
      - CORE_PEER_LOCALMSPID=Org2MSP #这里的Org1不需要修改,因为我们没有修改mspid 下同  对应 organization2
    volumes:
      - /var/run/:/host/var/run/
      - ../crypto-config/peerOrganizations/organization2.slzce.com/peers/node2.organization2.slzce.com/msp:/etc/hyperledger/fabric/msp
      #        - ../crypto-config/peerOrganizations/organization2.slzce.com/peers/node2.organization2.slzce.com/tls:/etc/hyperledger/fabric/tls
      # TLS 删除
      - node2.organization2.slzce.com:/var/hyperledger/production

    ports:
      - 37051:7051

  # 这里直接拷贝上面两个 然后修改就可以了
  node1.organization3.slzce.com: # 这 把把organization1改为organization3
    container_name: node1.organization3.slzce.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=node1.organization3.slzce.com
      - CORE_PEER_ADDRESS=node1.organization3.slzce.com:7051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:7051
      - CORE_PEER_CHAINCODEADDRESS=node1.organization3.slzce.com:7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
      - CORE_PEER_GOSSIP_BOOTSTRAP=node2.organization3.slzce.com:8051 #这里需要注意一点 node1就改成他前面一个及node1->node2  node2->node1 下同
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=node1.organization3.slzce.com:7051
      - CORE_PEER_LOCALMSPID=Org3MSP  #这里的Org1不需要修改,因为我们没有修改mspid 下同 对应organization3
    volumes:
      - /var/run/:/host/var/run/
      - ../crypto-config/peerOrganizations/organization3.slzce.com/peers/node1.organization3.slzce.com/msp:/etc/hyperledger/fabric/msp
      #        - ../crypto-config/peerOrganizations/organization3.slzce.com/peers/node1.organization3.slzce.com/tls:/etc/hyperledger/fabric/tls
      #  TLS 删除
      - node1.organization3.slzce.com:/var/hyperledger/production
    ports:
      - 47051:7051

  node2.organization3.slzce.com: # 这里需要把peer1改为node2 把org1改为organization3
    container_name: node2.organization3.slzce.com
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=node2.organization3.slzce.com
      - CORE_PEER_ADDRESS=node2.organization3.slzce.com:8051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:8051
      - CORE_PEER_CHAINCODEADDRESS=node2.organization3.slzce.com:8052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=node1.organization3.slzce.com:8051 #这里需要注意一点 node1就改成他前面一个及node1->node2  node2->node1 下同
      - CORE_PEER_GOSSIP_BOOTSTRAP=node1.organization3.slzce.com:7051
      - CORE_PEER_LOCALMSPID=Org3MSP #这里的Org1不需要修改,因为我们没有修改mspid 下同
    volumes:
      - /var/run/:/host/var/run/
      - ../crypto-config/peerOrganizations/organization3.slzce.com/peers/node2.organization3.slzce.com/msp:/etc/hyperledger/fabric/msp
      #        - ../crypto-config/peerOrganizations/organization3.slzce.com/peers/node2.organization3.slzce.com/tls:/etc/hyperledger/fabric/tls
      # TLS 删除
      - node2.organization3.slzce.com:/var/hyperledger/production

    ports:
      - 57051:7051

# 看一下有没有少  排列组合
# node1 node2  organization1 organization2 organization3
#一共六种 不要少了哦
# Org1Msp Org2MSP Org3MSP 都是对应configtx.yaml文件哦 
# 最后的端口那从node1.organization1.slzce.com下面的ports为7051:7051后其他的其次递增级17051:7051->27051:7051

那么到这里我们这个配置文件就修改成功了。
那么到了这里我们的配置文件就已经修改成功了,所以后面我们就可以用命令来启动网络了哦。是不是很期待呢?

结语

又写完了一篇,写这些东西真的很累,也很浪费时间,但我希望把我所学习到的东西分享出来,记录下来。
创作不易,多多支持。


  1. 以上表格内容来源于《Hyperledger Fabric 菜鸟进阶攻略》
    那么到了这一步我们就可以开始修改此文件了。 ↩︎

以上是关于创建自己的区块链网络 四的主要内容,如果未能解决你的问题,请参考以下文章

创建自己的区块链网络 九

创建自己的区块链网络 八

创建自己的区块链网络 十二

创建自己的区块链网络 十二

创建自己的区块链网络 六

创建自己的区块链网络 七