创建自己的区块链网络 三

Posted 患孤

tags:

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

目录

前言

上次我们修改了peer-base.yaml文件,接下来我们还需要修改configx.yaml文件。这个配置文件是用来创建创世区块以及通道的配置文件。

系列文章直通车

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

修改configtx.yaml文件

明确文件信息

我们首先需要知道他文件内容的作用才能去修改它,那么文件信息如下:

  1. Organizations部分指定OrdererOrg与PeerOrg的组织信息,其核心目的是指定各组织的名称、唯一ID及MSP的目录所在路径。
  2. Capabilities部分指定通道的权限信息。
  3. Application部分指定初始加入通道的组织。
  4. Orderer部分指定Orderer节点的信息。
    1. OrdererType指定共识排序服务的实现方式,目前有两种选择(solo及Kafka)。
    2. Addresses指定Orderer节点的服务地址与端口号。
    3. BatchSize指定与消息相关的批处理大小,如最大交易数量、最大字节数及建议字节数。
  5. Profiles部分指定了两个模板:TwoOrgsOrdererGenesis与TwoOrgsChannel。
    1. TwoOrgsOrdererGenesis模板用来生成Orderer服务的初始区块文件,该模板由3部分组成。
      1. Capabilities:指定通道的权限信息。
      2. Orderer:指定Orderer服务的信息(OrdererOrg)及权限信息。
      3. Consortiums:定义联盟组成成员(Org1、Org2)。
    2. TwoOrgsChannel模板用来生成应用通道交易配置文件,由两部分组成。
      1. Consortium:指定联盟信息。
      2. Application:指定组织及权限信息。

来源1

那么到这里我们已经明确了此配置文件的作用,还有文件内容的详细信息,那么我们现在就可以取修改还文件了。

修改文件

1、删除不必要内容

那么我们先来看看官方文件。


---

Organizations:
    - &OrdererOrg
        Name: OrdererOrg
        ID: OrdererMSP
        MSPDir: crypto-config/ordererOrganizations/example.com/msp
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Writers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Admins:
                Type: Signature
                Rule: "OR('OrdererMSP.admin')"
    - &Org1
        Name: Org1MSP
        ID: Org1MSP
        MSPDir: crypto-config/peerOrganizations/org1.example.com/msp
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Org1MSP.admin', 'Org1MSP.peer', 'Org1MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Org1MSP.admin', 'Org1MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Org1MSP.admin')"
        AnchorPeers:
            - Host: peer0.org1.example.com
              Port: 7051
    - &Org2
        Name: Org2MSP
        ID: Org2MSP
        MSPDir: crypto-config/peerOrganizations/org2.example.com/msp
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Org2MSP.admin', 'Org2MSP.peer', 'Org2MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Org2MSP.admin', 'Org2MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Org2MSP.admin')"
        AnchorPeers:
            - Host: peer0.org2.example.com
              Port: 9051
Capabilities:
    Channel: &ChannelCapabilities
        V1_4_3: true
        V1_3: false
        V1_1: false

   
    Orderer: &OrdererCapabilities
        V1_4_2: true
        V1_1: false

    Application: &ApplicationCapabilities
        V1_4_2: true
        V1_3: false
        V1_2: false
        V1_1: false
Application: &ApplicationDefaults
    Organizations:
    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"

    Capabilities:
        <<: *ApplicationCapabilities
Orderer: &OrdererDefaults
    OrdererType: solo

    Addresses:
        - orderer.example.com:7050
    BatchTimeout: 2s
    BatchSize:
        MaxMessageCount: 10
        AbsoluteMaxBytes: 99 MB
        PreferredMaxBytes: 512 KB

    Kafka:
        Brokers:
            - 127.0.0.1:9092
    EtcdRaft:
        Consenters:
            - Host: orderer.example.com
              Port: 7050
              ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
              ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
            - Host: orderer2.example.com
              Port: 7050
              ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
              ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
            - Host: orderer3.example.com
              Port: 7050
              ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt
              ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt
            - Host: orderer4.example.com
              Port: 7050
              ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt
              ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt
            - Host: orderer5.example.com
              Port: 7050
              ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt
              ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt
    Organizations:
    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
        BlockValidation:
            Type: ImplicitMeta
            Rule: "ANY Writers"
Channel: &ChannelDefaults
    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
    Capabilities:
        <<: *ChannelCapabilities
Profiles:

    TwoOrgsOrdererGenesis:
        <<: *ChannelDefaults
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
            Capabilities:
                <<: *OrdererCapabilities
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *Org1
                    - *Org2
    TwoOrgsChannel:
        Consortium: SampleConsortium
        <<: *ChannelDefaults
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org1
                - *Org2
            Capabilities:
                <<: *ApplicationCapabilities

    SampleDevModeKafka:
        <<: *ChannelDefaults
        Capabilities:
            <<: *ChannelCapabilities
        Orderer:
            <<: *OrdererDefaults
            OrdererType: kafka
            Kafka:
                Brokers:
                - kafka.example.com:9092

            Organizations:
            - *OrdererOrg
            Capabilities:
                <<: *OrdererCapabilities
        Application:
            <<: *ApplicationDefaults
            Organizations:
            - <<: *OrdererOrg
        Consortiums:
            SampleConsortium:
                Organizations:
                - *Org1
                - *Org2

    SampleMultiNodeEtcdRaft:
        <<: *ChannelDefaults
        Capabilities:
            <<: *ChannelCapabilities
        Orderer:
            <<: *OrdererDefaults
            OrdererType: etcdraft
            EtcdRaft:
                Consenters:
                - Host: orderer.example.com
                  Port: 7050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
                - Host: orderer2.example.com
                  Port: 7050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
                - Host: orderer3.example.com
                  Port: 7050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt
                - Host: orderer4.example.com
                  Port: 7050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt
                - Host: orderer5.example.com
                  Port: 7050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt
            Addresses:
                - orderer.example.com:7050
                - orderer2.example.com:7050
                - orderer3.example.com:7050
                - orderer4.example.com:7050
                - orderer5.example.com:7050

            Organizations:
            - *OrdererOrg
            Capabilities:
                <<: *OrdererCapabilities
        Application:
            <<: *ApplicationDefaults
            Organizations:
            - <<: *OrdererOrg
        Consortiums:
            SampleConsortium:
                Organizations:
                - *Org1
                - *Org2

是不是很长,我还把注释给删除了,还有这么多,但是我们不需要这么多。
相必大家都看到了TLS加密传输我们都不需要,全部删了,我们只需要如下内容

  1. Organizations (里面的Policies全部不需要)
  2. Application/Organizations
  3. Orderer/OrdererType
  4. Orderer/Addresses
  5. Orderer/BatchTimeout
  6. Orderer/BatchSize
  7. Profiles/TwoOrgsOrdererGenesis
  8. Profiles/TwoOrgsChannel

我们只需要这么多内容其它的全部删除掉
然后删除完后会有爆红的,我们把他删除就行了


这样就不会爆红了,那么删除完成了我们现在就应该真正的修改它了

2、真正的修改配置文件

那么接下来我们就来真正的修改配置文件,修改完成后是这个样子的


---
# 1--Ctrl+R 查找example 替换为slzce 
# 2--Ctrl+R 查找 org1 替换为 organization1 org2 替换为 organization1 (Organizations内的)
# 3--Ctrl+R 查找peer0 替换为node2 指定的背书节点
# 4-- 我们有三个组织所以需要复制一个 不要忘记修改
# 5-- 修改三个组织的监听端口为7051 

Organizations:
    - &OrdererOrg
        Name: OrdererOrg
        ID: OrdererMSP
        MSPDir: crypto-config/ordererOrganizations/slzce.com/msp
    - &Org1
        Name: Org1MSP
        ID: Org1MSP
        MSPDir: crypto-config/peerOrganizations/organization1.slzce.com/msp
        AnchorPeers:
            - Host: node2.organization1.slzce.com
              Port: 7051
    - &Org2
        Name: Org2MSP
        ID: Org2MSP
        MSPDir: crypto-config/peerOrganizations/organization2.slzce.com/msp
        AnchorPeers:
            - Host: node2.organization2.slzce.com
              Port: 7051
    - &Org3
        Name: Org3MSP
        ID: Org3MSP
        MSPDir: crypto-config/peerOrganizations/organization3.slzce.com/msp
        AnchorPeers:
            - Host: node2.organization3.slzce.com
              Port: 7051
Application: &ApplicationDefaults
    Organizations:
Orderer: &OrdererDefaults
    OrdererType: solo

    Addresses:
        - orderer.slzce.com:7050
    BatchTimeout: 2s
    BatchSize:
        MaxMessageCount: 10
        AbsoluteMaxBytes: 99 MB
        PreferredMaxBytes: 512 KB
        
Profiles:
    TwoOrgsOrdererGenesis:
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *Org1
                    - *Org2
                    - *Org3
#                   注意这里要加上Org3
    TwoOrgsChannel:
        Consortium: SampleConsortium
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org1
                - *Org2
                - *Org3
#                   注意这里要加上Org3

那么到这里我们这个文件就修改完成了,那么下次我们就可以修改docker-compose-base.yaml文件了。

结语

到这一步距离网络搭建还有一段路程,我们只需要再修改一个yaml文件就可以编写命令来跑通网络了,
创作不易,多多支持,谢谢。


  1. 以上表格内容来源于《Hyperledger Fabric 菜鸟进阶攻略》 ↩︎

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

创建自己的区块链网络 八

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

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

创建自己的区块链网络 六

创建自己的区块链网络 七

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