network_setup.sh分析

network_setup.sh分析

1. 具体流程

这里写图片描述

fabric/examples/e2e_cli目录下存有文件network_setup.sh用于一键部署环境并测试chaincode示例代码。其中包括两个部分,一个是利用generateArtifacts.sh脚本文件配置组织关系和颁发证书,另一个是docker-compose-cli.yaml用于根据配置启动集群并测试chaincode的示例代码。

2. generateArtifacts.sh脚本文件

包含三个函数:

  • generateCerts:使用cryptogen工具根据crypto-config.yaml来生成证书。
  • replacePrivateKey:将docker-compose-e2e-template.yaml文档中的ca私钥替换成具体的私钥。(本例中未使用)
  • generateChannelArtifacts:使用configtxgen工具根据configtx.yaml文件来生成orderer genesis blockchannel configuration transactionanchor peer update

crypto-config.yaml的具体内容如下:

# ---------------------------------------------------------------------------
# "OrdererOrgs" - Definition of organizations managing orderer nodes
# ---------------------------------------------------------------------------
OrdererOrgs:
  # ---------------------------------------------------------------------------
  # Orderer
  # ---------------------------------------------------------------------------
  - Name: Orderer
    Domain: example.com
    # ---------------------------------------------------------------------------
    # "Specs" - See PeerOrgs below for complete description
    # ---------------------------------------------------------------------------
    Specs:
      - Hostname: orderer
# ---------------------------------------------------------------------------
# "PeerOrgs" - Definition of organizations managing peer nodes
# ---------------------------------------------------------------------------
PeerOrgs:
  # ---------------------------------------------------------------------------
  # Org1
  # ---------------------------------------------------------------------------
  - Name: Org1
    Domain: org1.example.com
    # ---------------------------------------------------------------------------
    # "Specs"
    # ---------------------------------------------------------------------------
    # Uncomment this section to enable the explicit definition of hosts in your
    # configuration.  Most users will want to use Template, below
    #
    # Specs is an array of Spec entries.  Each Spec entry consists of two fields:
    #   - Hostname:   (Required) The desired hostname, sans the domain.
    #   - CommonName: (Optional) Specifies the template or explicit override for
    #                 the CN.  By default, this is the template:
    #
    #                              "{{.Hostname}}.{{.Domain}}"
    #
    #                 which obtains its values from the Spec.Hostname and
    #                 Org.Domain, respectively.
    # ---------------------------------------------------------------------------
    # Specs:
    #   - Hostname: foo # implicitly "foo.org1.example.com"
    #     CommonName: foo27.org5.example.com # overrides Hostname-based FQDN set above
    #   - Hostname: bar
    #   - Hostname: baz
    # ---------------------------------------------------------------------------
    # "Template"
    # ---------------------------------------------------------------------------
    # Allows for the definition of 1 or more hosts that are created sequentially
    # from a template. By default, this looks like "peer%d" from 0 to Count-1.
    # You may override the number of nodes (Count), the starting index (Start)
    # or the template used to construct the name (Hostname).
    #
    # Note: Template and Specs are not mutually exclusive.  You may define both
    # sections and the aggregate nodes will be created for you.  Take care with
    # name collisions
    # ---------------------------------------------------------------------------
    Template:
      Count: 2
      # Start: 5
      # Hostname: {{.Prefix}}{{.Index}} # default
    # ---------------------------------------------------------------------------
    # "Users"
    # ---------------------------------------------------------------------------
    # Count: The number of user accounts _in addition_ to Admin
    # ---------------------------------------------------------------------------
    Users:
      Count: 1
  # ---------------------------------------------------------------------------
  # Org2: See "Org1" for full specification
  # ---------------------------------------------------------------------------
  - Name: Org2
    Domain: org2.example.com
    Template:
      Count: 2
    Users:
      Count: 1

configtx.yaml的具体内容如下:

################################################################################
#
#   Profile
#
#   - Different configuration profiles may be encoded here to be specified
#   as parameters to the configtxgen tool
#
################################################################################
Profiles:

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

################################################################################
#
#   Section: Organizations
#
#   - This section defines the different organizational identities which will
#   be referenced later in the configuration.
#
################################################################################
Organizations:

    # SampleOrg defines an MSP using the sampleconfig.  It should never be used
    # in production but may be used as a template for other definitions
    - &OrdererOrg
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: OrdererOrg

        # ID to load the MSP definition as
        ID: OrdererMSP

        # MSPDir is the filesystem path which contains the MSP configuration
        MSPDir: crypto-config/ordererOrganizations/example.com/msp

    - &Org1
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: Org1MSP

        # ID to load the MSP definition as
        ID: Org1MSP

        MSPDir: crypto-config/peerOrganizations/org1.example.com/msp

        AnchorPeers:
            # AnchorPeers defines the location of peers which can be used
            # for cross org gossip communication.  Note, this value is only
            # encoded in the genesis block in the Application section context
            - Host: peer0.org1.example.com
              Port: 7051

    - &Org2
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: Org2MSP

        # ID to load the MSP definition as
        ID: Org2MSP

        MSPDir: crypto-config/peerOrganizations/org2.example.com/msp

        AnchorPeers:
            # AnchorPeers defines the location of peers which can be used
            # for cross org gossip communication.  Note, this value is only
            # encoded in the genesis block in the Application section context
            - Host: peer0.org2.example.com
              Port: 7051

################################################################################
#
#   SECTION: Orderer
#
#   - This section defines the values to encode into a config transaction or
#   genesis block for orderer related parameters
#
################################################################################
Orderer: &OrdererDefaults

    # Orderer Type: The orderer implementation to start
    # Available types are "solo" and "kafka"
    OrdererType: solo

    Addresses:
        - orderer.example.com:7050

    # Batch Timeout: The amount of time to wait before creating a batch
    BatchTimeout: 2s

    # Batch Size: Controls the number of messages batched into a block
    BatchSize:

        # Max Message Count: The maximum number of messages to permit in a batch
        MaxMessageCount: 10

        # Absolute Max Bytes: The absolute maximum number of bytes allowed for
        # the serialized messages in a batch.
        AbsoluteMaxBytes: 98 MB

        # Preferred Max Bytes: The preferred maximum number of bytes allowed for
        # the serialized messages in a batch. A message larger than the preferred
        # max bytes will result in a batch larger than preferred max bytes.
        PreferredMaxBytes: 512 KB

    Kafka:
        # Brokers: A list of Kafka brokers to which the orderer connects
        # NOTE: Use IP:port notation
        Brokers:
            - 127.0.0.1:9092

    # Organizations is the list of orgs which are defined as participants on
    # the orderer side of the network
    Organizations:

################################################################################
#
#   SECTION: Application
#
#   - This section defines the values to encode into a config transaction or
#   genesis block for application related parameters
#
################################################################################
Application: &ApplicationDefaults

    # Organizations is the list of orgs which are defined as participants on
    # the application side of the network
    Organizations:

3. docker-compose-cli.yaml文件

根据组织关系启动docker集群,并在cli容器中执行command命令运行./scripts/script.sh脚本文件。

./scripts/script.sh脚本包含以下函数:

  • createChannel:创建channel。
  • joinChannel:将每个peer节点加入channel。
  • updateAnchorPeers
  • installChaincode:部署chaincode。
  • instantiateChaincode:初始化chaincode,并设置背书策略。
  • chaincodeQuery
  • chaincodeInvoke
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个示例Shell脚本,用于修改网卡的联网配置信息和防火墙规则,并展示联通结果和验证防火墙规则的正确性。 ```shell #!/bin/bash # 网卡配置信息 IP_ADDRESS="192.168.63.128" SUBNET_MASK="255.255.255.0" GATEWAY="192.168.63.1" DNS_SERVER="8.8.8.8" # 防火墙规则IP黑名单 BLACKLIST=("192.168.1.100" "192.168.1.200") # 修改网卡配置信息 sudo ifconfig eth0 $IP_ADDRESS netmask $SUBNET_MASK sudo route add default gw $GATEWAY echo "nameserver $DNS_SERVER" | sudo tee /etc/resolv.conf > /dev/null # 验证网络通畅性 ping -c 4 www.google.com if [ $? -eq 0 ]; then echo "网络已联通" else echo "网络未联通" fi # 配置防火墙规则IP黑名单 for ip in "${BLACKLIST[@]}"; do sudo iptables -A INPUT -s $ip -j DROP done # 手动验证防火墙规则的正确与否 echo "请输入一个在黑名单中的IP地址进行验证:" read test_ip ping -c 4 $test_ip if [ $? -eq 0 ]; then echo "该IP可以访问,防火墙规则不生效" else echo "该IP无法访问,防火墙规则生效" fi ``` 请注意,上述脚本中的网卡名称为`eth0`,你可能需要根据你的实际情况修改网卡名称。另外,脚本中的操作需要以root权限运行,所以使用了`sudo`命令。 你可以将上述脚本保存到一个文件中(例如`network_setup.sh`),然后通过在终端中运行`bash network_setup.sh`来执行脚本。脚本将按照设定的配置信息进行网卡配置和防火墙规则设置,并展示联通结果和验证防火墙规则的正确性。 请谨慎使用防火墙规则,确保你了解如何正确设置和管理规则,以避免阻止了正常的网络通信。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值