HyperLedger Fabric 2.4.6 安装配置终结版【自定义配置Peer、Orderer,部署链码】

326 阅读6分钟

Docker安装,HyperLedger Fabric 2.4.6镜像获取

这些与之前版本没有什么太多变化,略。

证书配置文件准备

crypto-config-orderer.yaml

OrdererOrgs:
  # ---------------------------------------------------------------------------
  # Orderer
  # ---------------------------------------------------------------------------
  - Name: Orderer
    Domain: example.com
    EnableNodeOUs: true
    # ---------------------------------------------------------------------------
    # "Specs" - See PeerOrgs for complete description
    # ---------------------------------------------------------------------------
    Specs:
      - Hostname: orderer
        SANS:
          - "172.31.33.227"

crypto-config-org1.yaml

PeerOrgs:
  # ---------------------------------------------------------------------------
  # Org1
  # ---------------------------------------------------------------------------
  - Name: Org1
    Domain: org1.example.com
    EnableNodeOUs: true
    Template:
      Count: 1
      SANS:
        - "172.31.33.227"
      # Start: 5
      # Hostname: {{.Prefix}}{{.Index}} # default
    # ---------------------------------------------------------------------------
    # "Users"
    # ---------------------------------------------------------------------------
    # Count: The number of user accounts _in addition_ to Admin
    # ---------------------------------------------------------------------------
    Users:
      Count: 1

crypto-config-org2.yaml

PeerOrgs:
  # ---------------------------------------------------------------------------
  # Org2
  # ---------------------------------------------------------------------------
  - Name: Org2
    Domain: org2.example.com
    EnableNodeOUs: true
    Template:
      Count: 1
      SANS:
        - "172.31.33.227"
      # Start: 5
      # Hostname: {{.Prefix}}{{.Index}} # default
    # ---------------------------------------------------------------------------
    # "Users"
    # ---------------------------------------------------------------------------
    # Count: The number of user accounts _in addition_ to Admin
    # ---------------------------------------------------------------------------
    Users:
      Count: 1

使用docker镜像命令生成证书:

docker run --rm -v /home/ec2-user/hlf_v2/organizations:/organizations hyperledger/fabric-tools:2.4.6 /usr/local/bin/cryptogen generate --config=/organizations/cryptogen/crypto-config-org1.yaml --output="/organizations"
docker run --rm -v /home/ec2-user/hlf_v2/organizations:/organizations hyperledger/fabric-tools:2.4.6 /usr/local/bin/cryptogen generate --config=/organizations/cryptogen/crypto-config-org2.yaml --output="/organizations"
docker run --rm -v /home/ec2-user/hlf_v2/organizations:/organizations hyperledger/fabric-tools:2.4.6 /usr/local/bin/cryptogen generate --config=/organizations/cryptogen/crypto-config-orderer.yaml --output="/organizations"

opeer配置文件

core.yaml 注意修改网络模式

NetworkMode: docker_default

configtx.yaml 没有修改,略。

compose-test-net.yaml 配置文件

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

version: '3.7'

volumes:
  orderer.example.com:
  peer0.org1.example.com:
  peer0.org2.example.com:


services:

  orderer.example.com:
    container_name: orderer.example.com
    image: hyperledger/fabric-orderer:latest
    labels:
      service: hyperledger-fabric
    environment:
      - FABRIC_LOGGING_SPEC=INFO
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_LISTENPORT=7050
      - 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_GENERAL_BOOTSTRAPMETHOD=none
      - ORDERER_CHANNELPARTICIPATION_ENABLED=true
      - ORDERER_ADMIN_TLS_ENABLED=true
      - ORDERER_ADMIN_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_ADMIN_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_ADMIN_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_ADMIN_TLS_CLIENTROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
      - ORDERER_ADMIN_LISTENADDRESS=0.0.0.0:7053
      - ORDERER_OPERATIONS_LISTENADDRESS=orderer.example.com:9443
      - ORDERER_METRICS_PROVIDER=prometheus
    working_dir: /root
    command: orderer
    volumes:
        - ../organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp
        - ../organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
        - orderer.example.com:/var/hyperledger/production/orderer
    ports:
      - "172.31.33.227:7050:7050"
      - "172.31.33.227:7053:7053"
      - "172.31.33.227:9443:9443"

  peer0.org1.example.com:
    container_name: peer0.org1.example.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      - FABRIC_CFG_PATH=/etc/hyperledger/peercfg
      - CORE_VM_DOCKER_ATTACHSTDOUT=true
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_PROFILE_ENABLED=false
      - 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
      # Peer specific variables
      - 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=peer0.org1.example.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp
      - CORE_OPERATIONS_LISTENADDRESS=peer0.org1.example.com:9444
      - CORE_METRICS_PROVIDER=prometheus
      - CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG={"peername":"peer0org1"}
      - CORE_CHAINCODE_EXECUTETIMEOUT=300s
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=docker_default
    volumes:
        - ../organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com:/etc/hyperledger/fabric
        - peer0.org1.example.com:/var/hyperledger/production
        - ../config/peercfg:/etc/hyperledger/peercfg
        - /var/run/docker.sock:/var/run/docker.sock
    working_dir: /root
    command: peer node start
    ports:
      - "172.31.33.227:7051:7051"
      - "172.31.33.227:9444:9444"

  peer0.org2.example.com:
    container_name: peer0.org2.example.com
    image: hyperledger/fabric-peer:latest
    labels:
      service: hyperledger-fabric
    environment:
      - FABRIC_CFG_PATH=/etc/hyperledger/peercfg
      - CORE_VM_DOCKER_ATTACHSTDOUT=true
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_PROFILE_ENABLED=false
      - 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
      # Peer specific variables
      - 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=peer0.org2.example.com:9051
      - CORE_PEER_LOCALMSPID=Org2MSP
      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp      
      - CORE_OPERATIONS_LISTENADDRESS=peer0.org2.example.com:9445
      - CORE_METRICS_PROVIDER=prometheus
      - CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG={"peername":"peer0org2"}
      - CORE_CHAINCODE_EXECUTETIMEOUT=300s
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=docker_default
    volumes:
        - ../organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com:/etc/hyperledger/fabric
        - peer0.org2.example.com:/var/hyperledger/production
        - ../config/peercfg:/etc/hyperledger/peercfg
        - /var/run/docker.sock:/var/run/docker.sock
    working_dir: /root
    command: peer node start
    ports:
      - "172.31.33.227:9051:9051"
      - "172.31.33.227:9445:9445"

需要特别注意的是:

  • 一定要把本地core.yaml所在目录挂载到Docker容器的环境变量所指示的路径上。

    这里,

    本地core.yaml所在目录:../config/peercfg

    容器环境变量指示的目录:/etc/hyperledger/peercfg

    启动的时候,通过环境变量FABRIC_CFG_PATH注入。

  • peer配置部分,增加:

- CORE_VM_ENDPOINT=unix:///var/run/docker.sock
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=docker_default

接下来,docker-compose -f docker/compose-test-net.yaml up 就可以顺利的启动了

使用docker镜像中的命令创建创世区块

docker run --rm -e FABRIC_CFG_PATH="/hlf2/config" -v /home/ec2-user/hlf_v2:/hlf2  hyperledger/fabric-tools:2.4.6 /usr/local/bin/configtxgen -profile TwoOrgsApplicationGenesis -outputBlock /hlf2/channel-artifacts/genesis.block -channelID arya01channel

注意:FABRIC_CFG_PATH即为容器中core.yaml所在目录位置。通过主机挂载目录 /hlf2 映射为 /home/ec2-user/hlf_v2 可以找到。

order节点收到 osnadmin channel join 命令,激活通道

docker run --rm -e FABRIC_CFG_PATH="/hlf2/config" -v /home/ec2-user/hlf_v2:/hlf2  hyperledger/fabric-tools:2.4.6 /usr/local/bin/osnadmin channel join --channelID arya01channel --config-block /hlf2/channel-artifacts/genesis.block -o 172.31.33.227:7053 --ca-file "/hlf2/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --client-cert "/hlf2/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt" --client-key "/hlf2/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.key"

注: Because the connection between the osnadmin CLI and the orderer requires mutual TLS, you need to pass the --client-cert and --client-key parameters on each osadmin command. The --client-cert parameter points to the admin client certificate and --client-key refers to the admin client private key, both issued by the admin client TLS CA.

peer加入通道

docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org1MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:7051" -v /home/ec2-user/hlf_v2:/hlf2  hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer channel join -b /hlf2/channel-artifacts/genesis.block
docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org2MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:9051" -v /home/ec2-user/hlf_v2:/hlf2  hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer channel join -b /hlf2/channel-artifacts/genesis.block

设置Anchor Peer

After an organization has joined their peers to the channel, they should select at least one of their peers to become an anchor peer. Anchor peers are required in order to take advantage of features such as private data and service discovery. Each organization should set multiple anchor peers on a channel for redundancy.

对于第一个peer

docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org1MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:7051" -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer channel fetch config /hlf2/channel-artifacts/genesis.block -o 172.31.33.227:7050 --ordererTLSHostnameOverride orderer.example.com -c arya01channel --tls --cafile "/hlf2/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"

docker run --rm -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/configtxlator proto_decode --input /hlf2/channel-artifacts/genesis.block --type common.Block --output /hlf2/channel-artifacts/config_block.json

jq .data.data[0].payload.data.config ./channel-artifacts/config_block.json > ./channel-artifacts/config.json

cp ./channel-artifacts/config.json ./channel-artifacts/config_copy.json

jq '.channel_group.groups.Application.groups.Org1MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.org1.example.com","port": 7051}]},"version": "0"}}' ./channel-artifacts/config_copy.json > ./channel-artifacts/modified_config.json

docker run --rm -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/configtxlator proto_encode --input /hlf2/channel-artifacts/config.json --type common.Config --output /hlf2/channel-artifacts/config.pb

docker run --rm -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/configtxlator proto_encode --input /hlf2/channel-artifacts/modified_config.json --type common.Config --output /hlf2/channel-artifacts/modified_config.pb

docker run --rm -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/configtxlator compute_update --channel_id arya01channel --original /hlf2/channel-artifacts/config.pb --updated /hlf2/channel-artifacts/modified_config.pb --output /hlf2/channel-artifacts/config_update.pb

docker run --rm -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/configtxlator proto_decode --input /hlf2/channel-artifacts/config_update.pb --type common.ConfigUpdate --output /hlf2/channel-artifacts/config_update.json

echo '{"payload":{"header":{"channel_header":{"channel_id":"arya01channel", "type":2}},"data":{"config_update":'$(cat ./channel-artifacts/config_update.json)'}}}' | jq . > ./channel-artifacts/config_update_in_envelope.json

docker run --rm -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/configtxlator proto_encode --input /hlf2/channel-artifacts/config_update_in_envelope.json --type common.Envelope --output /hlf2/channel-artifacts/config_update_in_envelope.pb

docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org1MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:7051" -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer channel update -f /hlf2/channel-artifacts/config_update_in_envelope.pb -c arya01channel -o 172.31.33.227:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "/hlf2/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"


对于第二个peer
docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org2MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:9051" -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer channel fetch config /hlf2/channel-artifacts/genesis.block -o 172.31.33.227:7050 --ordererTLSHostnameOverride orderer.example.com -c arya01channel --tls --cafile "/hlf2/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"


docker run --rm -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/configtxlator proto_decode --input /hlf2/channel-artifacts/genesis.block --type common.Block --output /hlf2/channel-artifacts/config_block.json

jq .data.data[0].payload.data.config ./channel-artifacts/config_block.json > ./channel-artifacts/config.json

*下面的命令,可能有提示,需要人工确认
cp ./channel-artifacts/config.json ./channel-artifacts/config_copy.json

jq '.channel_group.groups.Application.groups.Org2MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.org2.example.com","port": 9051}]},"version": "0"}}' ./channel-artifacts/config_copy.json > ./channel-artifacts/modified_config.json

docker run --rm -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/configtxlator proto_encode --input /hlf2/channel-artifacts/config.json --type common.Config --output /hlf2/channel-artifacts/config.pb

docker run --rm -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/configtxlator proto_encode --input /hlf2/channel-artifacts/modified_config.json --type common.Config --output /hlf2/channel-artifacts/modified_config.pb

docker run --rm -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/configtxlator compute_update --channel_id arya01channel --original /hlf2/channel-artifacts/config.pb --updated /hlf2/channel-artifacts/modified_config.pb --output /hlf2/channel-artifacts/config_update.pb

docker run --rm -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/configtxlator proto_decode --input /hlf2/channel-artifacts/config_update.pb --type common.ConfigUpdate --output /hlf2/channel-artifacts/config_update.json

echo '{"payload":{"header":{"channel_header":{"channel_id":"arya01channel", "type":2}},"data":{"config_update":'$(cat ./channel-artifacts/config_update.json)'}}}' | jq . > ./channel-artifacts/config_update_in_envelope.json

docker run --rm -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/configtxlator proto_encode --input /hlf2/channel-artifacts/config_update_in_envelope.json --type common.Envelope --output /hlf2/channel-artifacts/config_update_in_envelope.pb

docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org2MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:9051" -v /home/ec2-user/hlf_v2:/hlf2 hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer channel update -f /hlf2/channel-artifacts/config_update_in_envelope.pb -c arya01channel -o 172.31.33.227:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "/hlf2/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"

现在通道更新了,新的配置块加到了通道创世区块上,通道高度将会增长,hash将会被更新。

链码部署

打包

docker run --rm -v /home/ec2-user/hlf_v2:/hlf2  hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer lifecycle chaincode package /hlf2/Arya2ChainCode.tar.gz --path /hlf2/arya-java-demo01/ --lang java --label Arya2ChainCode

安装

docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org1MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:7051" -v /home/ec2-user/hlf_v2:/hlf2  hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer lifecycle chaincode install /hlf2/Arya2ChainCode.tar.gz
docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org2MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:9051" -v /home/ec2-user/hlf_v2:/hlf2  hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer lifecycle chaincode install /hlf2/Arya2ChainCode.tar.gz

Approve

docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org1MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:7051" -v /home/ec2-user/hlf_v2:/hlf2  hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer lifecycle chaincode approveformyorg -o 172.31.33.227:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "/hlf2/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --channelID arya01channel --name "Arya2ChainCode" --version "1.0" --package-id "Arya2ChainCode:97d4aaf8615838430f342d0e2128f384439415eee825d4f1f9b13b20082f4a42" --sequence 1 --init-required --signature-policy "AND ('Org1MSP.peer','Org2MSP.peer')"
docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org2MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:9051" -v /home/ec2-user/hlf_v2:/hlf2  hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer lifecycle chaincode approveformyorg -o 172.31.33.227:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "/hlf2/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --channelID arya01channel --name "Arya2ChainCode" --version "1.0" --package-id "Arya2ChainCode:97d4aaf8615838430f342d0e2128f384439415eee825d4f1f9b13b20082f4a42" --sequence 1 --init-required --signature-policy "AND ('Org1MSP.peer','Org2MSP.peer')"

查看一下

docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org1MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:7051" -v /home/ec2-user/hlf_v2:/hlf2  hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer lifecycle chaincode checkcommitreadiness --channelID arya01channel --name "Arya2ChainCode" --version 1.0 --sequence 1 --init-required --signature-policy "AND ('Org1MSP.peer','Org2MSP.peer')" --output json
docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org2MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:9051" -v /home/ec2-user/hlf_v2:/hlf2  hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer lifecycle chaincode checkcommitreadiness --channelID arya01channel --name "Arya2ChainCode" --version 1.0 --sequence 1 --init-required --signature-policy "AND ('Org1MSP.peer','Org2MSP.peer')" --output json

最后commit

docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org1MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:7051" -v /home/ec2-user/hlf_v2:/hlf2  hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer lifecycle chaincode commit -o 172.31.33.227:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "/hlf2/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --channelID arya01channel --name "Arya2ChainCode" --version "1.0" --peerAddresses 172.31.33.227:7051 --tlsRootCertFiles "/hlf2/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses 172.31.33.227:9051 --tlsRootCertFiles "/hlf2/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" --sequence 1 --init-required --signature-policy "AND ('Org1MSP.peer','Org2MSP.peer')"

执行chaincode

docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org1MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:7051" -v /home/ec2-user/hlf_v2:/hlf2  hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer chaincode invoke -o 172.31.33.227:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "/hlf2/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C arya01channel -n "Arya2ChainCode" --peerAddresses 172.31.33.227:7051 --tlsRootCertFiles "/hlf2/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses 172.31.33.227:9051 --tlsRootCertFiles "/hlf2/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" --isInit -c '{"function":"init","Args":[]}'
docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org2MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:9051" -v /home/ec2-user/hlf_v2:/hlf2  hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer chaincode invoke -o 172.31.33.227:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "/hlf2/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C arya01channel -n "Arya2ChainCode" --peerAddresses 172.31.33.227:7051 --tlsRootCertFiles "/hlf2/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses 172.31.33.227:9051 --tlsRootCertFiles "/hlf2/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"addUser","Args":["4","Bob","123"]}'
docker run --rm -e FABRIC_CFG_PATH="/hlf2/config/peercfg" -e CORE_PEER_TLS_ENABLED=true -e CORE_PEER_LOCALMSPID="Org2MSP" -e CORE_PEER_TLS_ROOTCERT_FILE="/hlf2/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -e CORE_PEER_MSPCONFIGPATH="/hlf2/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" -e CORE_PEER_ADDRESS="172.31.33.227:9051" -v /home/ec2-user/hlf_v2:/hlf2  hyperledger/fabric-tools:2.4.6 /usr/local/bin/peer chaincode invoke -o 172.31.33.227:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "/hlf2/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C arya01channel -n "Arya2ChainCode" --peerAddresses 172.31.33.227:7051 --tlsRootCertFiles "/hlf2/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses 172.31.33.227:9051 --tlsRootCertFiles "/hlf2/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"queryAll","Args":[]}'