fabric2.0多机多节点部署

服务介绍
服务器ip orderer节点 组织 组织地址 peer节点
192.168.1.101 orderer1.test.com Org1 org1.test.com peer0.org1.test.com
192.168.1.102 orderer2.test.com Org2 org2.test.com peer0.org2.test.com
192.168.1.103 orderer3.test.com Org3 org3.test.com peer0.org3.test.com

工程结构:

fabric2.0多机多节点部署_第1张图片

一、定义配置文件

1、服务器配置如上“环境介绍”,拷贝”fabric-samples/first-network/crypto-config.yaml“文件,该文件主要用于定义orderer节点、组织下的peer节点生成证书用的,我们本次定义3个orderer,3个组织,3个peer,具体的crypto-config.yaml配置如下:

# 修改orderer组织(OrdererOrgs)配置信息,Domain为基础域名,Specs是命名空间,如orderer1.test.com 
OrdererOrgs:
  # ---------------------------------------------------------------------------
  # Orderer
  # ---------------------------------------------------------------------------
  - Name: Orderer
    Domain: test.com
    # ---------------------------------------------------------------------------
    # "Specs" - See PeerOrgs below for complete description
    # ---------------------------------------------------------------------------
    Specs:
      - Hostname: orderer1
      - Hostname: orderer2
      - Hostname: orderer3

# 修改组织中peer节点配置,name是组织名称,domain为基础域名,Template定义节点数量,users定义普通用户数量
PeerOrgs:
  # ---------------------------------------------------------------------------
  # Org1
  # ---------------------------------------------------------------------------
  - Name: Org1
    Domain: org1.test.com
    EnableNodeOUs: true
    # ---------------------------------------------------------------------------
    # "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: 1
      # Start: 5
      # Hostname: {{.Prefix}}{{.Index}} # default
    # ---------------------------------------------------------------------------
    # "Users"
    # ---------------------------------------------------------------------------
    # Count: The number of user accounts _in addition_ to Admin
    # ---------------------------------------------------------------------------
    Users:
      Count: 2
  # ---------------------------------------------------------------------------
  # Org2: See "Org1" for full specification
  # ---------------------------------------------------------------------------
  - Name: Org2
    Domain: org2.test.com
    EnableNodeOUs: true
    Template:
      Count: 1
    Users:
      Count: 2
  - Name: Org3
    Domain: org3.test.com
    EnableNodeOUs: true
    Template:
      Count: 1
    Users:
      Count: 2

2、拷贝“fabric-samples/first-network/configtx.yaml”文件,此文件主要定义创世块配置信息,其中包括:共识规则、组织通信协议等,根据实际情况修改组织的证书地址、发布服务地址配置,主要修改部分为rganizations、Orderer、Profiles配置项:

# OrdererOrg为排序组织,name是组织名称,id是组织唯一标识,mspdir为组织证书位置,Policies是策略

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
        # id和name不改,将example.com改为test.com
        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/test.com/msp

        # Policies defines the set of policies at this level of the config tree
        # For organization policies, their canonical path is usually
        #   /Channel///
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Writers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Admins:
                Type: Signature
                Rule: "OR('OrdererMSP.admin')"
        # OrdererEndpoints中配置的是默认排序节点,我们提供的排序节点为orderer1、orderer2、orderer3,所以需要改为orderer1.test.com
        OrdererEndpoints:
            - orderer1.test.com:7050

    - &Org1
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        # 定义组织信息,name和id为组织的名称,mspdir为组织证书根地址
        Name: Org1MSP

        # ID to load the MSP definition as
        ID: Org1MSP

        MSPDir: crypto-config/peerOrganizations/orgxy.test.com/msp

        # Policies defines the set of policies at this level of the config tree
        # For organization policies, their canonical path is usually
        #   /Channel///
        # Policies为用户权限策略
        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')"
            Endorsement:
                Type: Signature
                Rule: "OR('Org1MSP.peer')"

        # AnchorPeers为各组织选举的锚节点地址
        AnchorPeers:
            # Org1组织下锚节点访问地址,其中端口是指区块链网络中能访问的,而不是节点容器内部的,一般指容器映射到宿主机的端口
            - Host: peer0.org1.test.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.test.com/msp

        # Policies defines the set of policies at this level of the config tree
        # For organization policies, their canonical path is usually
        #   /Channel///
        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')"
            Endorsement:
                Type: Signature
                Rule: "OR('Org2MSP.peer')"

        AnchorPeers:
            # Org2组织下锚节点访问地址,其中端口是指区块链网络中能访问的,而不是节点容器内部的,一般指容器映射到宿主机的端口
            - Host: peer0.org2.test.com
              Port: 7051

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

        # ID to load the MSP definition as
        ID: Org3MSP

        MSPDir: crypto-config/peerOrganizations/org3.test.com/msp

        # Policies defines the set of policies at this level of the config tree
        # For organization policies, their canonical path is usually
        #   /Channel///
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Org3MSP.admin', 'Org3MSP.peer', 'Org3MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Org3MSP.admin', 'Org3MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Org3MSP.admin')"
            Endorsement:
                Type: Signature
                Rule: "OR('Org3MSP.peer')"

        AnchorPeers:
            # Org3组织下锚节点访问地址,其中端口是指区块链网络中能访问的,而不是节点容器内部的,一般指容器映射到宿主机的端口
            - Host: peer0.org3.test.com
              Port: 7051

# 修改orderer节点配置,采用ETCdraft模式,并配置三个节点信息
Orderer: &OrdererDefaults

    # Orderer Type: The orderer implementation to start
    OrdererType: etcdraft
    
    Addresses:
        - orderer1.test.com:7050
        - orderer2.test.com:7050
        - orderer3.test.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: 100

        # Absolute Max Bytes: The absolute maximum number of bytes allowed for
        # the serialized messages in a batch.
        AbsoluteMaxBytes: 64 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
    # 定义etcdraft模式的节点信息,如果采用了tls,那么需要配置tlscert证书
    EtcdRaft:
        Consenters:
        - Host: orderer1.test.com
          Port: 7050
          ClientTLSCert: crypto-config/ordererOrganizations/test.com/orderers/orderer1.test.com/tls/server.crt
          ServerTLSCert: crypto-config/ordererOrganizations/test.com/orderers/orderer1.test.com/tls/server.crt
        - Host: orderer2.test.com
          Port: 7050
          ClientTLSCert: crypto-config/ordererOrganizations/test.com/orderers/orderer2.test.com/tls/server.crt
          ServerTLSCert: crypto-config/ordererOrganizations/test.com/orderers/orderer2.test.com/tls/server.crt
        - Host: orderer3.test.com
          Port: 7050
          ClientTLSCert: crypto-config/ordererOrganizations/test.com/orderers/orderer3.test.com/tls/server.crt
          ServerTLSCert: crypto-config/ordererOrganizations/test.com/orderers/orderer3.test.com/tls/server.crt

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

    # Policies defines the set of policies at this level of the config tree
    # For Orderer policies, their canonical path is
    #   /Channel/Orderer/
    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
        # BlockValidation specifies what signatures must be included in the block
        # from the orderer for the peer to validate it.
        BlockValidation:
            Type: ImplicitMeta
            Rule: "ANY Writers"

# 修改生成创世区块配置的配置信息,主要修改组织结构信息
Profiles:
    # 配置通道信息,需要指明该通道有哪些组织
    ThreeOrgsChannel:
        Consortium: SampleConsortium
        <<: *ChannelDefaults
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org1
                - *Org2
                - *Org3
            Capabilities:
                <<: *ApplicationCapabilities
    # 创世块配置信息,需要指明有哪些组织,orderer节点有哪些,peer节点有哪些
    ThreeOrgsOrdererGenesis:
        <<: *ChannelDefaults
        Capabilities:
            <<: *ChannelCapabilities
        Orderer:
            <<: *OrdererDefaults
            Organizations:
            - *OrdererOrg
            Capabilities:
                <<: *OrdererCapabilities
        Application:
            <<: *ApplicationDefaults
            Organizations:
            - <<: *OrdererOrg
        Consortiums:
            SampleConsortium:
                Organizations:
                - *Org1
                - *Org2
                - *Org3

二、生成配置文件

1、生成证书文件(只需要在一台服务器中执行即可)

# 创建工作目录
$ mkdir -p /home/fabricblock
# 进入到工作目录
$ cd /home/fabricblock
# 给执行文件授权
$ chmod +x ./bin/*
# 生成各个组织相关证书,成功后会生成一个crypto-config目录,里面存有orderer和peer节点证书文件
# 这些证书包括:ca证书、tls证书、签名证书、私钥文件以及管理用户的相关证书
$ ./bin/cryptogen generate --config=./crypto-config.yaml

2、生成创世区块文件,并指定创世块通道id

$ ./bin/configtxgen -profile ThreeOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block

3、生成通道配置

$ ./bin/configtxgen -profile ThreeOrgsChannel -outputCreateChannelTx ./channel-artifacts/testchannel.tx -channelID testchannel

4、拷贝证书和通道文件到其他服务器(先压缩,再通过scp或者sftp方式上传到其他服务器,然后解压)

$ tar czvf all.tar.gz channel-artifacts/* crypto-config/*
$ scp ./all.tar.gz [email protected]:/home/fabricblock
$ scp ./all.tar.gz [email protected]:/home/fabricblock

三、启动网络(此处只展示一台服务器的相关配置,其他服务相似,只需要修改相关组织及访问路径信息)

1、配置docker-compose-orderer.yaml文件,用于docker-compose启动orderer节点服务

version: '2'

services:
  orderer.test.com:
    container_name: orderer.test.com
    image: hyperledger/fabric-orderer:2.0.0
    restart: always
    environment:
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fabricblock_default
      - FABRIC_LOGGING_SPEC=DEBUG
      - GODEBUG=netdns=go
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/etc/hyperledger/configtx/genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
      # enabled TLS
      - ORDERER_GENERAL_TLS_ENABLED=true
      - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: orderer
    volumes:
      # 注意同步时间
      - /etc/localtime:/etc/localtime
      - ./channel-artifacts:/etc/hyperledger/configtx
      - ./crypto-config/ordererOrganizations/test.com/orderers/orderer1.test.com/:/var/hyperledger/orderer
      - ./fabric-data/orderer1.test.com:/var/hyperledger/production/orderer
    ports:
      - 7050:7050
    networks:
      default:
        aliases:
          - fabricblock_default

2、配置docker-compose-cli.yaml文件,用于配置组织中各个peer节点及对应的客户端服务,不同组织更换相关组织名、域名

version: '2'

services:
  peer0.org1.test.com:
    container_name: peer0.org1.test.com
    hostname: peer0.org1.test.com
    image: hyperledger/fabric-peer:2.0.0
    restart: always
    environment:
      - CORE_PEER_ID=peer0.org1.test.com
      - GODEBUG=netdns=go
      - CORE_PEER_ADDRESS=peer0.org1.test.com:7051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:7051
      - CORE_PEER_CHAINCODEADDRESS=peer0.org1.test.com:7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.test.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.test.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_TLS_CLIENTROOTCAS_FILES=/etc/hyperledger/fabric/peer/msp/tlscacerts/tlsca.org1.test.com-cert.pem
      # ---
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fabricblock_default
      - FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_ENDORSER_ENABLED=true
      - CORE_PEER_CHANNELSERVICE_ENABLED=true
      - CORE_CHAINCODE_STARTUPTIMEOUT=10m
      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/peer/msp
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/peer/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/peer/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/peer/tls/ca.crt
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    volumes:
      # 注意同步时间
      - /etc/localtime:/etc/localtime
      - /var/run/:/host/var/run/
      - ./crypto-config/peerOrganizations/org1.test.com/peers/peer0.org1.test.com:/etc/hyperledger/fabric/peer
      - ./fabric-data/peer0.org1.test.com:/var/hyperledger/production
    ports:
      - 7051:7051
      - 7052:7052
    networks:
      default:
        aliases:
          - fabricblock_default
    extra_hosts:
      - "orderer1.test.com:192.168.1.101"
      - "peer0.org1.test.com:192.168.1.101"
  cli:
    container_name: cli
    image: hyperledger/fabric-tools:2.0.0
    tty: true
    stdin_open: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      #- FABRIC_LOGGING_SPEC=DEBUG
      - FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_ID=cli
      - CORE_PEER_ADDRESS=peer0.org1.test.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.test.com/peers/peer0.org1.test.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.test.com/peers/peer0.org1.test.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.test.com/peers/peer0.org1.test.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.test.com/users/[email protected]/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
        - /var/run/:/host/var/run/
        - ./chaincode/:/opt/gopath/src/github.com/chaincode
        - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
        - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    networks:
      default:
        aliases:
          - fabricblock_default
    depends_on:
      - peer0.org1.test.com

5、101/102/103服务器启动orderer节点

$ docker-compose -f ./docker-compose-orderer101.yaml up -d
$ docker-compose -f ./docker-compose-orderer102.yaml up -d
$ docker-compose -f ./docker-compose-orderer103.yaml up -d

6、进入101服务器,启动peer节点以及cli客户端,并且进入cli中操作网络

$ docker-compose -f ./docker-compose-cli.yaml up -d
# 进入org1客户端
$ docker exec -it cli bash

# 创建通道,执行成功会生成一个 testchannel.block 文件,其他组织节点需要加入这个通道,则需要将这个block文件拷贝到相应组织的节点下
$ peer channel create -o orderer1.test.com:7050 -c testchannel -f ./channel-artifacts/testchannel.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/test.com/orderers/orderer1.test.com/msp/tlscacerts/tlsca.test.com-cert.pem

# 组织1中的节点1加入通道
$ peer channel join -b testchannel.block

# 检查当前节点是否加入通道
$ peer channel list

# 再将101中org1客户端创建的testchannel.block拷贝到102/103服务器的cli中,因为节点加入通道是通过该文件操作的
$ docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/testchannel.block ./
$ scp testchannel.block [email protected]:/home/fabricblock/channel-artifacts
$ scp testchannel.block [email protected]:/home/fabricblock/channel-artifacts

 7、进入102服务器,启动peer节点以及cli客户端,并且进入cli中操作网络

$ docker-compose -f ./docker-compose-cli.yaml up -d
# 进入org2客户端
$ docker exec -it cli bash

# 组织2中的节点1加入通道(注意testchannel.block文件路径)
$ peer channel join -b ./channel-artifacts/testchannel.block

# 检查当前节点是否加入通道
$ peer channel list

 8、进入103服务器,启动peer节点以及cli客户端,并且进入cli中操作网络

$ docker-compose -f ./docker-compose-cli.yaml up -d
# 进入org3客户端
$ docker exec -it cli bash

# 组织3中的节点1加入通道(注意testchannel.block文件路径)
$ peer channel join -b ./channel-artifacts/testchannel.block

# 检查当前节点是否加入通道
$ peer channel list

四、安装链码

 1、打包链码

1、首先进入到101服务器中的cli
$ docker exec -it cli bash
2、打包链码
$ peer lifecycle chaincode package mycc.tar.gz --path github.com/chaincode --lang golang --label mycc_1 >&log.txt

2、安装链码,命令执行成功会响应一个PACKAGE_ID,用于后续审批链码,且每个组织每个节点都需要安装

$ peer lifecycle chaincode install mycc.tar.gz >&log.txt

3、审批链码(每个组织都需要审批,但不是每个节点)

1、进入101服务器中组织1审批链码
$ peer lifecycle chaincode approveformyorg --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/test.com/orderers/orderer1.test.com/msp/tlscacerts/tlsca.test.com-cert.pem --channelID testchannel --name mycc --version 1 --init-required --package-id mycc_1:83e15b4e70915a1582ec1373696ed5a8e4a544e8ded33acea007beced52ef6c9 --sequence 1 --waitForEvent >&log.txt

2、进入102服务器中的组织2审批链码
$ peer lifecycle chaincode approveformyorg --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/test.com/orderers/orderer1.test.com/msp/tlscacerts/tlsca.test.com-cert.pem --channelID testchannel --name mycc --version 1 --init-required --package-id mycc_1:1730997ffaaa5b8fcc7a9bd82f42580634a0f978bff124725be5ba4d3f788a12 --sequence 1 --waitForEvent >&log.txt

3、进入103服务器中的组织3审批链码
$ peer lifecycle chaincode approveformyorg --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/test.com/orderers/orderer1.test.com/msp/tlscacerts/tlsca.test.com-cert.pem --channelID testchannel --name mycc --version 1 --init-required --package-id mycc_1:cf48a30df19efec9cf107990d5b9141874fcd409512f1a70870322ff3712a0b6 --sequence 1 --waitForEvent >&log.txt

4、检查整个网络中的审批状态:{"Org1MSP": true,"Org2MSP": true,"Org3MSP": true} 则为全部审批成功

$ peer lifecycle chaincode checkcommitreadiness --channelID testchannel --name mycc --version 1 --init-required --sequence 1 -o -orderer1.test.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/test.com/orderers/orderer1.test.com/msp/tlscacerts/tlsca.test.com-cert.pem --signature-policy "AND ('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')"

5、提交链码,在任一组织中都可以执行,且执行一次(注意相关服务器之间的服务能正常访问,且相关证书路径正确)

$ peer lifecycle chaincode commit -o orderer1.test.com:7050 --channelID testchannel --name mycc --version 1 --sequence 1 --init-required --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/test.com/orderers/orderer1.test.com/msp/tlscacerts/tlsca.test.com-cert.pem --peerAddresses peer0.org1.test.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.test.com/peers/peer0.org1.test.com/tls/ca.crt --peerAddresses peer0.org2.test.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.test.com/peers/peer0.org2.test.com/tls/ca.crt --peerAddresses peer0.org3.test.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.test.com/peers/peer0.org3.test.com/tls/ca.crt --signature-policy "AND ('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')"

6、链码初始化,在任一组织都可执行,且执行一次

$ peer chaincode invoke -o orderer1.test.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/test.com/orderers/orderer1.test.com/msp/tlscacerts/tlsca.test.com-cert.pem -C testchannel -n mycc --peerAddresses peer0.org1.test.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.test.com/peers/peer0.org1.test.com/tls/ca.crt --peerAddresses peer0.org2.test.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.test.com/peers/peer0.org2.test.com/tls/ca.crt --peerAddresses peer0.org3.test.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.test.com/peers/peer0.org3.test.com/tls/ca.crt --isInit -c '{"Args":["Init","a","100","b","100"]}'

7、查询数据

$ peer chaincode query -C testchannel -n mycc -c '{"Args":["query","a"]}' >&log.txt

 

你可能感兴趣的:(区块链,区块链,fabric)