macbook&hyperfabric 单机多节点部署

qi

整体参考如下文档: 

https://github.com/LHYi/tutorial/wiki/09.-Creating-a-multi-org-network-in-a-single-machine

单机6节点配置

个人记录配置过程:

Bring up components

After the cryptography materials are generated, now we can bring up the components by docker.

docker-compose -f compose/compose-org3.yaml -f docker/docker-compose-org3-6.yaml up -d

 docker/docker-compose-org3-6.yaml内容

# Copyright IBM Corp. All Rights Reserved.

#

# SPDX-License-Identifier: Apache-2.0

#

version: '3.7'

networks:

  test:

    name: fabric_test

# add the volumes according to the number of organizations you want

volumes:

  peer0.org3.example.com:

  peer0.org4.example.com:

  peer0.org5.example.com:

  peer0.org6.example.com:

# I need to change the settings for each organization to the following to make it work. There might exist other alternatives.

services:

  peer0.org3.example.com:

    container_name: peer0.org3.example.com

    image: hyperledger/fabric-peer:latest

    labels:

      service: hyperledger-fabric

    environment:

      #- FABRIC_CFG_PATH=/etc/hyperledger/peercfg

      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock

      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fabric_test

      - FABRIC_LOGGING_SPEC=INFO

      #- FABRIC_LOGGING_SPEC=DEBUG

      - CORE_PEER_TLS_ENABLED=true

      - 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

      # Peer specific variables

      - CORE_PEER_ID=peer0.org3.example.com

      - CORE_PEER_ADDRESS=peer0.org3.example.com:11051

      - CORE_PEER_LISTENADDRESS=0.0.0.0:11051

      - CORE_PEER_CHAINCODEADDRESS=peer0.org3.example.com:11052

      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:11052

      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org3.example.com:11051

      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org3.example.com:11051

      - CORE_PEER_LOCALMSPID=Org3MSP

      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp

      - CORE_OPERATIONS_LISTENADDRESS=peer0.org3.example.com:9446

      - CORE_METRICS_PROVIDER=prometheus

      - CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG={"peername":"peer0org3"}

      - CORE_CHAINCODE_EXECUTETIMEOUT=300s

    volumes:

        - /var/run/docker.sock:/host/var/run/docker.sock

        - ../../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/msp:/etc/hyperledger/fabric/msp

        - ../../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls:/etc/hyperledger/fabric/tls

        - peer0.org3.example.com:/var/hyperledger/production

    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer

    command: peer node start

    ports:

      - 11051:11051

      - 9446:9446

    networks:

      - test

  peer0.org4.example.com:

    container_name: peer0.org4.example.com

    image: hyperledger/fabric-peer:latest

    labels:

      service: hyperledger-fabric

    environment:

      #- FABRIC_CFG_PATH=/etc/hyperledger/peercfg

      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock

      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fabric_test

      - FABRIC_LOGGING_SPEC=INFO

      #- FABRIC_LOGGING_SPEC=DEBUG

      - CORE_PEER_TLS_ENABLED=true

      - 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

      # Peer specific variables

      - CORE_PEER_ID=peer0.org4.example.com

      - CORE_PEER_ADDRESS=peer0.org4.example.com:12051

      - CORE_PEER_LISTENADDRESS=0.0.0.0:12051

      - CORE_PEER_CHAINCODEADDRESS=peer0.org4.example.com:12052

      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:12052

      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org4.example.com:12051

      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org4.example.com:12051

      - CORE_PEER_LOCALMSPID=Org4MSP

      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp

      - CORE_OPERATIONS_LISTENADDRESS=peer0.org4.example.com:9546

      - CORE_METRICS_PROVIDER=prometheus

      - CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG={"peername":"peer0org4"}

      - CORE_CHAINCODE_EXECUTETIMEOUT=300s

    volumes:

        - /var/run/docker.sock:/host/var/run/docker.sock

        - ../../organizations/peerOrganizations/org4.example.com/peers/peer0.org4.example.com/msp:/etc/hyperledger/fabric/msp

        - ../../organizations/peerOrganizations/org4.example.com/peers/peer0.org4.example.com/tls:/etc/hyperledger/fabric/tls

        - peer0.org4.example.com:/var/hyperledger/production

    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer

    command: peer node start

    ports:

      - 12051:12051

      - 9546:9546

    networks:

      - test

  

  peer0.org5.example.com:

    container_name: peer0.org5.example.com

    image: hyperledger/fabric-peer:latest

    labels:

      service: hyperledger-fabric

    environment:

      #- FABRIC_CFG_PATH=/etc/hyperledger/peercfg

      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock

      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fabric_test

      - FABRIC_LOGGING_SPEC=INFO

      #- FABRIC_LOGGING_SPEC=DEBUG

      - CORE_PEER_TLS_ENABLED=true

      - 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

      # Peer specific variables

      - CORE_PEER_ID=peer0.org5.example.com

      - CORE_PEER_ADDRESS=peer0.org5.example.com:13051

      - CORE_PEER_LISTENADDRESS=0.0.0.0:13051

      - CORE_PEER_CHAINCODEADDRESS=peer0.org5.example.com:13052

      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:13052

      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org5.example.com:13051

      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org5.example.com:13051

      - CORE_PEER_LOCALMSPID=Org5MSP

      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp

      - CORE_OPERATIONS_LISTENADDRESS=peer0.org5.example.com:9646

      - CORE_METRICS_PROVIDER=prometheus

      - CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG={"peername":"peer0org5"}

      - CORE_CHAINCODE_EXECUTETIMEOUT=300s

    volumes:

        - /var/run/docker.sock:/host/var/run/docker.sock

        - ../../organizations/peerOrganizations/org5.example.com/peers/peer0.org5.example.com/msp:/etc/hyperledger/fabric/msp

        - ../../organizations/peerOrganizations/org5.example.com/peers/peer0.org5.example.com/tls:/etc/hyperledger/fabric/tls

        - peer0.org5.example.com:/var/hyperledger/production

    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer

    command: peer node start

    ports:

      - 13051:13051

      - 9646:9646

    networks:

      - test

  peer0.org6.example.com:

    container_name: peer0.org6.example.com

    image: hyperledger/fabric-peer:latest

    labels:

      service: hyperledger-fabric

    environment:

      #- FABRIC_CFG_PATH=/etc/hyperledger/peercfg

      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock

      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fabric_test

      - FABRIC_LOGGING_SPEC=INFO

      #- FABRIC_LOGGING_SPEC=DEBUG

      - CORE_PEER_TLS_ENABLED=true

      - 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

      # Peer specific variables

      - CORE_PEER_ID=peer0.org6.example.com

      - CORE_PEER_ADDRESS=peer0.org6.example.com:14051

      - CORE_PEER_LISTENADDRESS=0.0.0.0:14051

      - CORE_PEER_CHAINCODEADDRESS=peer0.org6.example.com:14052

      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:14052

      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org6.example.com:14051

      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org6.example.com:14051

      - CORE_PEER_LOCALMSPID=Org6MSP

      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp

      - CORE_OPERATIONS_LISTENADDRESS=peer0.org6.example.com:9746

      - CORE_METRICS_PROVIDER=prometheus

      - CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG={"peername":"peer0org6"}

      - CORE_CHAINCODE_EXECUTETIMEOUT=300s

    volumes:

        - /var/run/docker.sock:/host/var/run/docker.sock

        - ../../organizations/peerOrganizations/org6.example.com/peers/peer0.org6.example.com/msp:/etc/hyperledger/fabric/msp

        - ../../organizations/peerOrganizations/org6.example.com/peers/peer0.org6.example.com/tls:/etc/hyperledger/fabric/tls

        - peer0.org6.example.com:/var/hyperledger/production

    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer

    command: peer node start

    ports:

      - 14051:14051

      - 9746:9746

    networks:

      - test

本人文件架构

结合官方教程

docker-compose -f compose/compose-org3.yaml -f docker/docker-compose-org3-6.yaml up -d

运行结果

终端输入:

export PATH=${PWD}/../bin:$PATH
export FABRIC_CFG_PATH=${PWD}/../config/
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051

终端输入:

peer channel fetch config channel-artifacts/config_block.pb -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com -c channel1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

终端输入:

configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json

注意jq输入语法:

jq  .data.data\[0\].payload.data.config config_block.json > config.json
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ../organizations/peerOrganizations/org3.example.com/org3.json > modified3_config.json
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org4MSP":.[1]}}}}}' modified3_config.json ../organizations/peerOrganizations/org4.example.com/org4.json > modified4_config.json
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org5MSP":.[1]}}}}}' modified4_config.json ../organizations/peerOrganizations/org5.example.com/org5.json > modified5_config.json
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org6MSP":.[1]}}}}}' modified5_config.json ../organizations/peerOrganizations/org6.example.com/org6.json >  modified_config.json

步骤如下:

之后都是按照官方教程:

将Org3MSP、4、5、6都如下配置:

1、其中,获取配置块:终端输入

peer channel fetch 0 channel-artifacts/channel1.block -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com -c channel1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

2、部署链码

参考代码

peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go/ --lang golang --label basic_1
peer lifecycle chaincode install basic.tar.gz
peer lifecycle chaincode queryinstalled

You should see output similar to the following:

Installed chaincodes on peer:
Package ID: basic_1:ef2394600055b69053a488d0ea2ac66bd544e93bb1b272a68d8860df5ac82c8c, Label: basic_1

we can use the following steps to use invoke Basic chaincode as Org3.

切换到org3: 

export PATH=${PWD}/../bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/                 
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org3MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
export CORE_PEER_ADDRESS=localhost:11051
export CC_PACKAGE_ID=basic_1:ef2394600055b69053a488d0ea2ac66bd544e93bb1b272a68d8860df5ac82c8c

Use the following command to approve a definition of the basic chaincode for Org3:

peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID channel1 --name basic --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1

You can use the peer lifecycle chaincode querycommitted command to check if the chaincode definition you have approved has already been committed to the channel. 

peer lifecycle chaincode querycommitted --channelID channel1 --name basic --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

Populate the ledger with some sample assets. We’ll get endorsements from the Org2 peer and the new Org3 peer so that the endorsement policy is satisfied.

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C channel1 -n basic --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --peerAddresses localhost:11051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt -c '{"function":"InitLedger","Args":[]}'

You can query the chaincode to ensure that the Org3 peer committed the data.

 peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C channel1 -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"CreateAsset","Args":["asset8","blue","16","Kelley","750"]}'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值