Hyperledger Fabric --- 三机部署实现

204 阅读12分钟

4.2 三机部署

在上一节中,我们尝试实现了在不同虚拟机上配置fabric网络,并实现了在虚拟机2上的操作和fabric网络的其他各节点中同步。在此基础上,我们尝试扩展一个虚拟机,实现在三台虚拟机上fabric网络同步。下面我们将详细介绍三机部署的配置过程

硬件环境:3台Ubuntu虚拟机

软件环境:

1.fabric v2.2.0 (2.x版本额均可)

2.go v1.15

3.dokcer 20.10.7

4.docker-compose 1.29.2

4.2.1 部署前环境准备

Hyperledger Fabric 2.x 生产环境的分布式部署,在三台虚拟机上分别安装好上述fabric环境

请参考双机部署中第1,2部分的详细介绍,在此不再赘述。

4.2.2 建立多机部署文件夹

在三台虚拟机上都需要建立

cd /home/xxxx/gopath/src/github.com/hyperledger

mkdir -p amops/multiple-deployment

4.2.3 设置Fabric服务的地址映射

三台虚拟机都需要配置

sudo vim /etc/hosts

把以下内容填充至hosts文件中,IP需要按实际情况更改

192.168.xxx.xxx host1orderer.amops.com 192.168.xxx.xxx host2orderer.amops.com 192.168.xxx.xxx host3orderer.amops.com 192.168.xxx.xxx peer0.host1.amops.com 192.168.xxx.xxx peer1.host1.amops.com 192.168.xxx.xxx peer0.host2.amops.com 192.168.xxx.xxx peer1.host2.amops.com 192.168.xxx.xxx peer0.host3.amops.com 192.168.xxx.xxx peer1.host3.amops.com

重启服务器网络

sudo service network-manager restart

4.2.4 建立链码文件夹,部署两个链码

仅需要在服务器1上操作即可

我们使用官方提供的两个链码(fabcar和sacc)

cd amops/multiple-deployment

mkdir chaincode

然后将示例提供的fabcar复制到chaincode目录下

cp -r ../../fabric-samples/chaincode/fabcar ./chaincode/

将示例提供的sacc复制到chaincode目录下

cp -r ../../fabric-samples/chaincode/sacc ./chaincode/

到链码文件夹下,下载链码的依赖文件

cd chaincode/fabcar/go/


go env -w GOPROXY=goproxy.io,direct go env -w GO111MODULE=on go mod vendor


cd ../../sacc/

go mod vendor

4.2.5 生成加密材料、证书和创世区块、通道交易配置和锚节点更新文件

在服务器1 的multiple-deployment文件夹下新建crypto-config.yaml文件和configtx.yaml文件(证书密钥和交易配置文件),用于生产证书、密钥、创世区块等文件(注:服务器2、3不用建这两个文件)

回到multiple-deployment目录下

touch crypto-config.yaml

touch configtx.yaml

将以下内容写进crypto-config.yaml文件中

OrdererOrgs:
  - Name: Orderer
    Domain: amops.com
    Specs:
      - Hostname: host1orderer
      - Hostname: host2orderer
      - Hostname: host3orderer

PeerOrgs:
  - Name: Host1
    Domain: host1.amops.com
    EnableNodeOUs: true
    Template:
      Count: 2 #生成证书的数量
    Users:
      Count: 1 #生成用户证书个数
  - Name: Host2
    Domain: host2.amops.com
    EnableNodeOUs: true
    Template:
      Count: 2
    Users:
      Count: 1
  - Name: Host3
    Domain: host3.amops.com
    EnableNodeOUs: true
    Template:
      Count: 2
    Users:
      Count: 1

将以下内容写进configtx.yaml文件中

Organizations:
    - &OrdererOrg
        Name: OrdererOrg
        ID: OrdererMSP
        MSPDir: crypto-config/ordererOrganizations/amops.com/msp
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Writers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Admins:
                Type: Signature
                Rule: "OR('OrdererMSP.admin')"

    - &Host1
        Name: Host1MSP
        ID: Host1MSP
        MSPDir: crypto-config/peerOrganizations/host1.amops.com/msp
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Host1MSP.admin', 'Host1MSP.peer', 'Host1MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Host1MSP.admin', 'Host1MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Host1MSP.admin')"
            Endorsement:
                Type: Signature
                Rule: "OR('Host1MSP.peer')"

        AnchorPeers:
            - Host: peer0.host1.amops.com
              Port: 7051

    - &Host2
        Name: Host2MSP
        ID: Host2MSP
        MSPDir: crypto-config/peerOrganizations/host2.amops.com/msp
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Host2MSP.admin', 'Host2MSP.peer', 'Host2MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Host2MSP.admin', 'Host2MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Host2MSP.admin')"
            Endorsement:
                Type: Signature
                Rule: "OR('Host2MSP.peer')"

        AnchorPeers:
            - Host: peer0.host2.amops.com
              Port: 7051

    - &Host3
        Name: Host3MSP
        ID: Host3MSP
        MSPDir: crypto-config/peerOrganizations/host3.amops.com/msp
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Host3MSP.admin', 'Host3MSP.peer', 'Host3MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Host3MSP.admin', 'Host3MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Host3MSP.admin')"
            Endorsement:
                Type: Signature
                Rule: "OR('Host3MSP.peer')"

        AnchorPeers:
            - Host: peer0.host3.amops.com
              Port: 7051

Capabilities:
    Channel: &ChannelCapabilities
        V2_0: true
    Orderer: &OrdererCapabilities
        V2_0: true
    Application: &ApplicationCapabilities
        V2_0: true

Application: &ApplicationDefaults

    Organizations:

    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
        LifecycleEndorsement:
            Type: ImplicitMeta
            Rule: "MAJORITY Endorsement"
        Endorsement:
            Type: ImplicitMeta
            Rule: "MAJORITY Endorsement"

    Capabilities:
        <<: *ApplicationCapabilities

Orderer: &OrdererDefaults

    OrdererType: etcdraft

    Addresses: # orderer 集群节点
        - host1orderer.amops.com:7050
        - host2orderer.amops.com:7050
        - host3orderer.amops.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:

        MaxMessageCount: 10

        AbsoluteMaxBytes: 99 MB

        PreferredMaxBytes: 512 KB

    Organizations:

    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"

Channel: &ChannelDefaults

    Policies:
        # Who may invoke the 'Deliver' API
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        # Who may invoke the 'Broadcast' API
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        # By default, who may modify elements at this config level
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"

    Capabilities:
        <<: *ChannelCapabilities

Profiles:

    ThreeOrgsChannel:
        Consortium: SampleConsortium
        <<: *ChannelDefaults
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Host1
                - *Host2
                - *Host3
            Capabilities:
                <<: *ApplicationCapabilities

    SampleMultiNodeEtcdRaft:
        <<: *ChannelDefaults
        Capabilities:
            <<: *ChannelCapabilities
        Orderer:
            <<: *OrdererDefaults
            OrdererType: etcdraft
            EtcdRaft:
                Consenters:
                - Host: host1orderer.amops.com
                  Port: 7050
                  ClientTLSCert: crypto-config/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/tls/server.crt
                - Host: host2orderer.amops.com
                  Port: 7050
                  ClientTLSCert: crypto-config/ordererOrganizations/amops.com/orderers/host2orderer.amops.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/amops.com/orderers/host2orderer.amops.com/tls/server.crt
                - Host: host3orderer.amops.com
                  Port: 7050
                  ClientTLSCert: crypto-config/ordererOrganizations/amops.com/orderers/host3orderer.amops.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/amops.com/orderers/host3orderer.amops.com/tls/server.crt
            Addresses:
                - host1orderer.amops.com:7050
                - host2orderer.amops.com:7050
                - host3orderer.amops.com:7050
            Organizations:
            - *OrdererOrg
            Capabilities:
                <<: *OrdererCapabilities
        Application:
            <<: *ApplicationDefaults
            Organizations:
            - <<: *OrdererOrg
        Consortiums:
            SampleConsortium:
                Organizations:
                - *Host1
                - *Host2
                - *Host3



服务器1的操作:生成证书、密钥、创世区块、各组织的交易配置文件等

生成crypto-config.yaml定义的证书文件

cryptogen generate --config=./crypto-config.yaml

生成创世区块

configtxgen -profile SampleMultiNodeEtcdRaft -channelID amopsdeploy -outputBlock ./channel-artifacts/genesis.block

生成通道交易配置

configtxgen -profile ThreeOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID amops

生成组织1锚节点更新配置

configtxgen -profile ThreeOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Host1MSPanchors.tx -channelID amops -asOrg Host1MSP

生成组织2锚节点更新配置

configtxgen -profile ThreeOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Host2MSPanchors.tx -channelID amops -asOrg Host2MSP

生成组织3锚节点更新配置

configtxgen -profile ThreeOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Host3MSPanchors.tx -channelID amops -asOrg Host3MSP

4.2.6 将host1所有生成的材料复制到另外两台主机(scp命令) 将生成的channel-artifacts、crypto-config文件夹拷贝至 服务器2、3 中的multiple-deployment文件夹下, 我们使用scp命令进行传输,因此需要先给服务器2,3的相应文件夹权限。

在服务器2,3上的操作

来到amops目录下

chmod 777 multiple-deployment

回到服务器1,执行下列操作

scp -r channel-artifacts smy@192.168.88.136:/home/smy/gopath/src/github.com/hyperledger/amops/multiple-deployment/

scp -r crypto-config smy@192.168.88.136:/home/smy/gopath/src/github.com/hyperledger/amops/multiple-deployment/

scp -r channel-artifacts smy@192.168.88.137:/home/smy/gopath/src/github.com/hyperledger/amops/multiple-deployment/

scp -r crypto-config smy@192.168.88.137:/home/smy/gopath/src/github.com/hyperledger/amops/multiple-deployment/

4.2.7 编写网络启动配置文件

同样在multiple-deployment文件夹下创建并编辑Fabric启动代码(在三台虚拟机上都需要)

touch docker-compose-up.yaml

编写Fabric启动的yaml文件,这里只展现其中一个服务器的启动代码,其他两个服务器的Fabric启动代码对照编写即可

version: '2'

services:
  ca.host1.amops.com:
    container_name: ca.host1.amops.com
    image: hyperledger/fabric-ca
    environment:
      - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
      - FABRIC_CA_SERVER_CA_NAME=ca.host1.amops.com
      - FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.host1.amops.com-cert.pem
      - FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/priv_sk
      - FABRIC_CA_SERVER_TLS_ENABLED=true
      - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-tls/tlsca.host1.amops.com-cert.pem
      - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-tls/priv_sk
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/ca
    command: sh -c 'fabric-ca-server start -b admin:adminpw -d'
    volumes:
      - ./crypto-config/peerOrganizations/host1.amops.com/ca/:/etc/hyperledger/fabric-ca-server-config
      - ./crypto-config/peerOrganizations/host1.amops.com/tlsca/:/etc/hyperledger/fabric-ca-server-tls
    ports:
      - "7054:7054"

  host1orderer.amops.com:
    container_name: host1orderer.amops.com
    image: hyperledger/fabric-orderer
    environment:
      - FABRIC_LOGGING_SPEC=DEBUG
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_BOOTSTRAPMETHOD=file
      - ORDERER_GENERAL_BOOTSTRAPFILE=/var/hyperledger/orderer/orderer.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]
      - ORDERER_OPERATIONS_LISTENADDRESS=0.0.0.0:8443
      - ORDERER_METRICS_PROVIDER=prometheus
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: orderer
    volumes:
        - ./channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
        - ./crypto-config/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp:/var/hyperledger/orderer/msp
        - ./crypto-config/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/tls/:/var/hyperledger/orderer/tls
    ports:
      - 7050:7050
    extra_hosts:
      - "host1orderer.amops.com:192.168.xxx.xxx"
      - "host2orderer.amops.com:192.168.xxx.xxx"
      - "host3orderer.amops.com:192.168.xxx.xxx"

  peer0.host1.amops.com:
    container_name: peer0.host1.amops.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_PEER_ID=peer0.host1.amops.com
      - CORE_PEER_ADDRESS=peer0.host1.amops.com:7051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:7051
      - CORE_PEER_CHAINCODEADDRESS=peer0.host1.amops.com:7052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.host1.amops.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.host1.amops.com:7051
      - CORE_PEER_LOCALMSPID=Host1MSP
      - FABRIC_LOGGING_SPEC=INFO
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
      # Allow more time for chaincode container to build on install.
      - CORE_CHAINCODE_EXECUTETIMEOUT=300s
      - CORE_OPERATIONS_LISTENADDRESS=0.0.0.0:9443
      - CORE_METRICS_PROVIDER=prometheus
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    volumes:
       - /var/run/:/host/var/run/
       - ./crypto-config/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/msp:/etc/hyperledger/fabric/msp
       - ./crypto-config/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/tls:/etc/hyperledger/fabric/tls
    ports:
      - 7051:7051
      - 7052:7052
      - 7053:7053
    extra_hosts:
      - "host1orderer.amops.com:192.168.xxx.xxx"
      - "host2orderer.amops.com:192.168.xxx.xxx"
      - "host3orderer.amops.com:192.168.xxx.xxx"

  peer1.host1.amops.com:
    container_name: peer1.host1.amops.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_PEER_ID=peer1.host1.amops.com
      - CORE_PEER_ADDRESS=peer1.host1.amops.com:8051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:8051
      - CORE_PEER_CHAINCODEADDRESS=peer1.host1.amops.com:8052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.host1.amops.com:8051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.host1.amops.com:8051
      - CORE_PEER_LOCALMSPID=Host1MSP
      - FABRIC_LOGGING_SPEC=INFO
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
      # Allow more time for chaincode container to build on install.
      - CORE_CHAINCODE_EXECUTETIMEOUT=300s
      - CORE_OPERATIONS_LISTENADDRESS=0.0.0.0:10443
      - CORE_METRICS_PROVIDER=prometheus
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    volumes:
       - /var/run/:/host/var/run/
       - ./crypto-config/peerOrganizations/host1.amops.com/peers/peer1.host1.amops.com/msp:/etc/hyperledger/fabric/msp
       - ./crypto-config/peerOrganizations/host1.amops.com/peers/peer1.host1.amops.com/tls:/etc/hyperledger/fabric/tls
    ports:
      - 8051:8051
      - 8052:8052
      - 8053:8053
    extra_hosts:
      - "host1orderer.amops.com:192.168.xxx.xxx"
      - "host2orderer.amops.com:192.168.xxx.xxx"
      - "host3orderer.amops.com:192.168.xxx.xxx"

  cli1:
    container_name: cli1
    image: hyperledger/fabric-tools
    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=INFO
      - CORE_PEER_ID=cli1
      - CORE_PEER_ADDRESS=peer0.host1.amops.com:7051
      - CORE_PEER_LOCALMSPID=Host1MSP
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/users/Admin@host1.amops.com/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
        - /var/run/:/host/var/run/
        - ./chaincode/fabcar/go/:/opt/gopath/src/github.com/hyperledger/multiple-deployment/chaincode/fabcar/go
        - ./chaincode/sacc/go/:/opt/gopath/src/github.com/hyperledger/multiple-deployment/chaincode/sacc/go
        - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
        - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    extra_hosts:
      - "host1orderer.amops.com:192.168.xxx.xxx"
      - "host2orderer.amops.com:192.168.xxx.xxx"
      - "host3orderer.amops.com:192.168.xxx.xxx"
      - "peer0.host1.amops.com:192.168.xxx.xxx"
      - "peer1.host1.amops.com:192.168.xxx.xxx"
      - "peer0.host2.amops.com:192.168.xxx.xxx"
      - "peer1.host2.amops.com:192.168.xxx.xxx"
      - "peer0.host3.amops.com:192.168.xxx.xxx"
      - "peer1.host3.amops.com:192.168.xxx.xxx"

  cli2:
    container_name: cli2
    image: hyperledger/fabric-tools
    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=INFO
      - CORE_PEER_ID=cli2
      - CORE_PEER_ADDRESS=peer1.host1.amops.com:8051
      - CORE_PEER_LOCALMSPID=Host1MSP
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer1.host1.amops.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer1.host1.amops.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer1.host1.amops.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/users/Admin@host1.amops.com/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash
    volumes:
        - /var/run/:/host/var/run/
        - ./chaincode/fabcar/go/:/opt/gopath/src/github.com/hyperledger/multiple-deployment/chaincode/fabcar/go
        - ./chaincode/sacc/go/:/opt/gopath/src/github.com/hyperledger/multiple-deployment/chaincode/sacc/go
        - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
        - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    extra_hosts:
      - "host1orderer.amops.com:192.168.xxx.xxx"
      - "host2orderer.amops.com:192.168.xxx.xxx"
      - "host3orderer.amops.com:192.168.xxx.xxx"
      - "peer0.host1.amops.com:192.168.xxx.xxx"
      - "peer1.host1.amops.com:192.168.xxx.xxx"
      - "peer0.host2.amops.com:192.168.xxx.xxx"
      - "peer1.host2.amops.com:192.168.xxx.xxx"
      - "peer0.host3.amops.com:192.168.xxx.xxx"
      - "peer1.host3.amops.com:192.168.xxx.xxx"


4.2.8 启动Fabric网络

在服务器1、2、3的操作

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

4.2.9 创建通道、加入通道与更新组织锚节点

服务器1的操作

进入cli1容器内

docker exec -it cli1 bash

创建通道(等网络启动15s后,再创建通道,Raft选举leader需要时间)

peer channel create -o host1orderer.amops.com:7050 -c amops -f ./channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem

将host1.peer0.amops.com加入通道

peer channel join -b amops.block

更新组织host1锚节点

peer channel update -o host1orderer.amops.com:7050 -c amops -f ./channel-artifacts/Host1MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem

退出cli1容器,将区块文件amops.block从容器中拷贝出来,拷贝至cli2容器中,使host1.peer1.amops.com也加入区块中

退出容器

exit

将容器1中的通道区块文件复制到本地

docker cp cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/amops.block ./

将本地文件复制到容器cli2中

docker cp amops.block cli2:/opt/gopath/src/github.com/hyperledger/fabric/peer/

进入容器cli2

docker exec -it cli2 bash

host1.peer1节点加入通道

peer channel join -b amops.block

将amops.block区块文件拷贝至服务器2、3

scp amops.block smy@192.168.88.136:/home/smy/gopath/src/github.com/hyperledger/amops/multiple-deployment/

scp amops.block smy@192.168.88.137:/home/smy/gopath/src/github.com/hyperledger/amops/multiple-deployment/

服务器2的操作:节点0、1加入通道,并更新组织2的锚节点

将amops.block复制到cli1,cli2

docker cp amops.block cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/

docker cp amops.block cli2:/opt/gopath/src/github.com/hyperledger/fabric/peer/

进入cli1容器中

docker exec -it cli1 bash

peer0.host2节点加入通道

peer channel join -b amops.block

更新组织2的锚节点

peer channel update -o host1orderer.amops.com:7050 -c amops -f ./channel-artifacts/Host2MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem

退出cli1,来到cli2容器

exit

docker exec -it cli2 bash

peer1.host2节点加入通道

peer channel join -b amops.block

服务器3的操作:节点0、1加入通道,并更新组织3的锚节点

将amops.block复制到cli1,cli2下

docker cp amops.block cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/

docker cp amops.block cli2:/opt/gopath/src/github.com/hyperledger/fabric/peer/

进入cli1

docker exec -it cli1 bash

将peer0.host3节点加入通道

peer channel join -b amops.block

更新组织3锚节点

peer channel update -o host1orderer.amops.com:7050 -c amops -f ./channel-artifacts/Host3MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem

进入容器2

docker exec -it cli2 bash

将peer1.host3节点加入通道

peer channel join -b amops.block

4.2.10 打包并安装链码

4.2.10.1 虚拟机11的操作

进入cli1中,

docker exec -it cli1 bash

打包链码sacc

peer lifecycle chaincode package sacc.tar.gz --path github.com/hyperledger/multiple-deployment/chaincode/sacc --lang golang --label sacc_1

打包链码fabcar

peer lifecycle chaincode package fabcar.tar.gz --path github.com/hyperledger/multiple-deployment/chaincode/fabcar/go --lang golang --label fabcar_1

在peer0上安装链码sacc

peer lifecycle chaincode install sacc.tar.gz

在peer0上安装链码fabcar

peer lifecycle chaincode install fabcar.tar.gz

将cli1的链码先复制到本地

docker cp cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/sacc.tar.gz ./

docker cp cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer/fabcar.tar.gz ./

将本地的链码复制到cli2容器中

docker cp sacc.tar.gz cli2:/opt/gopath/src/github.com/hyperledger/fabric/peer/

docker cp fabcar.tar.gz cli2:/opt/gopath/src/github.com/hyperledger/fabric/peer/

进入cli2容器中,并在peer1安装这两个链码

docker exec -it cli2 bash

peer lifecycle chaincode install sacc.tar.gz

peer lifecycle chaincode install fabcar.tar.gz

将链码复制到服务器2和服务器3(回到服务器1的终端)

scp fabcar.tar.gz smy@192.168.88.136:/home/smy/gopath/src/github.com/hyperledger/amops/multiple-deployment

scp fabcar.tar.gz smy@192.168.88.137:/home/smy/gopath/src/github.com/hyperledger/amops/multiple-deployment

scp sacc.tar.gz smy@192.168.88.136:/home/smy/gopath/src/github.com/hyperledger/amops/multiple-deployment

scp sacc.tar.gz smy@192.168.88.137:/home/smy/gopath/src/github.com/hyperledger/amops/multiple-deployment

4.2.10.2 在虚拟机2上的操作

将链码复制到cli1 和 cli2

docker cp sacc.tar.gz cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer

docker cp sacc.tar.gz cli2:/opt/gopath/src/github.com/hyperledger/fabric/peer

docker cp fabcar.tar.gz cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer

docker cp fabcar.tar.gz cli2:/opt/gopath/src/github.com/hyperledger/fabric/peer

进入容器cli1中

docker exec -it cli1 bash

在peer0上安装两个链码

peer lifecycle chaincode install sacc.tar.gz

peer lifecycle chaincode install fabcar.tar.gz

进入容器cli2中

docker exec -it cli2 bash

在peer1上安装两个链码

peer lifecycle chaincode install sacc.tar.gz

peer lifecycle chaincode install fabcar.tar.gz

4.2.10.3 在虚拟机3上的操作 ####

将链码复制到cli1 和 cli2

docker cp sacc.tar.gz cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer

docker cp sacc.tar.gz cli2:/opt/gopath/src/github.com/hyperledger/fabric/peer

docker cp fabcar.tar.gz cli1:/opt/gopath/src/github.com/hyperledger/fabric/peer

docker cp fabcar.tar.gz cli2:/opt/gopath/src/github.com/hyperledger/fabric/peer

进入容器cli1中

docker exec -it cli1 bash

在peer0上安装两个链码

peer lifecycle chaincode install sacc.tar.gz

peer lifecycle chaincode install fabcar.tar.gz

进入容器cli2中

docker exec -it cli2 bash

在peer1上安装两个链码

peer lifecycle chaincode install sacc.tar.gz

peer lifecycle chaincode install fabcar.tar.gz

4.2.11 各组织锚节点同意提交链码

组织1同意提交链码(在虚拟机1上操作)

进入cli1容器中

docker exec -it cli1 bash

锚节点同意提交链码sacc

peer lifecycle chaincode approveformyorg --channelID amops --name sacc --version 1.0 --init-required --package-id sacc_1:98760e3e42eefc4869823bfc52b18e9f9cfe9a6dca5525972a6dba16ea900ba6 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem

锚节点同意提交链码fabcar

peer lifecycle chaincode approveformyorg --channelID amops --name fabcar --version 1.0 --init-required --package-id fabcar_1:f90f0b3e2f303104d58d239a2904eec9f3cf4f164897f5b35ebde847a342c5d4 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem

组织2同意提交链码(在虚拟机2上操作)

进入cli1容器中

docker exec -it cli1 bash

锚节点同意提交链码sacc

peer lifecycle chaincode approveformyorg --channelID amops --name sacc --version 1.0 --init-required --package-id sacc_1:98760e3e42eefc4869823bfc52b18e9f9cfe9a6dca5525972a6dba16ea900ba6 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem

锚节点同意提交链码fabcar

peer lifecycle chaincode approveformyorg --channelID amops --name fabcar --version 1.0 --init-required --package-id fabcar_1:f90f0b3e2f303104d58d239a2904eec9f3cf4f164897f5b35ebde847a342c5d4 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem

组织3同意提交链码(在虚拟机3上操作)

进入cli1容器中

docker exec -it cli1 bash

锚节点同意提交链码sacc

peer lifecycle chaincode approveformyorg --channelID amops --name sacc --version 1.0 --init-required --package-id sacc_1:98760e3e42eefc4869823bfc52b18e9f9cfe9a6dca5525972a6dba16ea900ba6 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem

锚节点同意提交链码fabcar

peer lifecycle chaincode approveformyorg --channelID amops --name fabcar --version 1.0 --init-required --package-id fabcar_1:f90f0b3e2f303104d58d239a2904eec9f3cf4f164897f5b35ebde847a342c5d4 --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem

4.2.12 查看链码状态是否就绪

使用任一服务器操作都可

查询sacc链码状态是否就绪

peer lifecycle chaincode checkcommitreadiness --channelID amops --name sacc --version 1.0 --init-required --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem --output json

查询fabcar链码状态是否就绪

peer lifecycle chaincode checkcommitreadiness --channelID amops --name fabcar --version 1.0 --init-required --sequence 1 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem --output json

4.2.13 提交链码

使用任一服务器操作都可

在通道上提交链码sacc

peer lifecycle chaincode commit -o host1orderer.amops.com:7050 --channelID amops --name sacc --version 1.0 --sequence 1 --init-required --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem --peerAddresses peer0.host1.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/tls/ca.crt --peerAddresses peer0.host2.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host2.amops.com/peers/peer0.host2.amops.com/tls/ca.crt --peerAddresses peer0.host3.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host3.amops.com/peers/peer0.host3.amops.com/tls/ca.crt

在通道上提交链码fabcar

peer lifecycle chaincode commit -o host1orderer.amops.com:7050 --channelID amops --name fabcar --version 1.0 --sequence 1 --init-required --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem --peerAddresses peer0.host1.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/tls/ca.crt --peerAddresses peer0.host2.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host2.amops.com/peers/peer0.host2.amops.com/tls/ca.crt --peerAddresses peer0.host3.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host3.amops.com/peers/peer0.host3.amops.com/tls/ca.crt

4.2.14 初始化链码 ###

初始化链码sacc

peer chaincode invoke -o host1orderer.amops.com:7050 --isInit --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem -C amops -n sacc --peerAddresses peer0.host1.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/tls/ca.crt --peerAddresses peer0.host2.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host2.amops.com/peers/peer0.host2.amops.com/tls/ca.crt --peerAddresses peer0.host3.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host3.amops.com/peers/peer0.host3.amops.com/tls/ca.crt -c '{"Args":["a","bb"]}' –waitForEvent

初始化链码fabcar

peer chaincode invoke -o host1orderer.amops.com:7050 --isInit --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem -C amops -n fabcar --peerAddresses peer0.host1.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/tls/ca.crt --peerAddresses peer0.host2.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host2.amops.com/peers/peer0.host2.amops.com/tls/ca.crt --peerAddresses peer0.host3.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host3.amops.com/peers/peer0.host3.amops.com/tls/ca.crt -c '{"Args":["InitLedger","Prius","blue","Tomoko"]}' –waitForEvent

4.2.15 与链码进行交互

4.2.15.1 与链码sacc交互

查询键为a的值

peer chaincode query -C amops -n sacc -c '{"Args":["get","a"]}'

更改键a的值

peer chaincode invoke -o host1orderer.amops.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem -C amops -n sacc --peerAddresses peer0.host1.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/tls/ca.crt --peerAddresses peer0.host2.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host2.amops.com/peers/peer0.host2.amops.com/tls/ca.crt --peerAddresses peer0.host3.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host3.amops.com/peers/peer0.host3.amops.com/tls/ca.crt -c '{"Args":["set","a","cccccc"]}'

查询更改后的键a的值

增加新的键值记录

peer chaincode invoke -o host1orderer.amops.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem -C amops -n sacc --peerAddresses peer0.host1.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/tls/ca.crt --peerAddresses peer0.host2.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host2.amops.com/peers/peer0.host2.amops.com/tls/ca.crt --peerAddresses peer0.host3.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host3.amops.com/peers/peer0.host3.amops.com/tls/ca.crt -c '{"Args":["set","c","bbbb"]}'

peer chaincode invoke -o host1orderer.amops.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem -C amops -n sacc --peerAddresses peer0.host1.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/tls/ca.crt --peerAddresses peer0.host2.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host2.amops.com/peers/peer0.host2.amops.com/tls/ca.crt --peerAddresses peer0.host3.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host3.amops.com/peers/peer0.host3.amops.com/tls/ca.crt -c '{"Args":["set","d","bbbb"]}'

查询两个新增的键值记录

peer chaincode query -C amops -n sacc -c '{"Args":["get","c"]}'

peer chaincode query -C amops -n sacc -c '{"Args":["get","d"]}'

4.2.15.2 与链码fabcar交互

查询所有的车辆信息(fabcar)

peer chaincode query -C amops -n fabcar -c '{"Args":["QueryAllCars"]}'

可以看到一共有CAR0->CAR9十条车辆信息

增加新的车辆信息

peer chaincode invoke -o host1orderer.amops.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem -C amops -n fabcar --peerAddresses peer0.host1.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/tls/ca.crt --peerAddresses peer0.host2.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host2.amops.com/peers/peer0.host2.amops.com/tls/ca.crt --peerAddresses peer0.host3.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host3.amops.com/peers/peer0.host3.amops.com/tls/ca.crt -c '{"Args":["CreateCar","CAR10","dazhong","dazhong","blue","smy"]}'

peer chaincode invoke -o host1orderer.amops.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem -C amops -n fabcar --peerAddresses peer0.host1.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/tls/ca.crt --peerAddresses peer0.host2.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host2.amops.com/peers/peer0.host2.amops.com/tls/ca.crt --peerAddresses peer0.host3.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host3.amops.com/peers/peer0.host3.amops.com/tls/ca.crt -c '{"Args":["CreateCar","CAR11","Hongqi","Hongqi","red","china"]}'

peer chaincode invoke -o host1orderer.amops.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem -C amops -n fabcar --peerAddresses peer0.host1.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/tls/ca.crt --peerAddresses peer0.host2.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host2.amops.com/peers/peer0.host2.amops.com/tls/ca.crt --peerAddresses peer0.host3.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host3.amops.com/peers/peer0.host3.amops.com/tls/ca.crt -c '{"Args":["CreateCar","CAR12","BYD","BYD","black","china"]}'

再次查询所有车辆信息,观察新的信息是否已经成功添加

peer chaincode query -C amops -n fabcar -c '{"Args":["QueryAllCars"]}'

可以看到CAR10,CAR11,CAR12信息已经成功添加

更改某个车辆的车主信息

peer chaincode invoke -o host1orderer.amops.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/amops.com/orderers/host1orderer.amops.com/msp/tlscacerts/tlsca.amops.com-cert.pem -C amops -n fabcar --peerAddresses peer0.host1.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host1.amops.com/peers/peer0.host1.amops.com/tls/ca.crt --peerAddresses peer0.host2.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host2.amops.com/peers/peer0.host2.amops.com/tls/ca.crt --peerAddresses peer0.host3.amops.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/host3.amops.com/peers/peer0.host3.amops.com/tls/ca.crt -c '{"Args":["ChangeCarOwner","CAR10","newSMY"]}'

有之前查询的所有车辆信息可知CAR10原有的车主为smy,先将车主信息改为newSMY

特定查询(查看信息是否已经成功更改)

peer chaincode query -C amops -n fabcar -c '{"Args":["QueryCar","CAR10"]}'