mac中Hyperledger fabric多通道多节点增删改查的示例分析

发布时间:2021-12-06 14:20:27 作者:小新
来源:亿速云 阅读:171

小编给大家分享一下mac中Hyperledger fabric多通道多节点增删改查的示例分析,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

cd /opt/gopath/src/github.com/hyperledger/fabric/aberic

$ docker images

$ docker rmi f0fe49196c40 (IMAGE ID)

$ docker ps -a

$ docker stop $(docker ps -a -q)

$ docker rm $(docker ps -a -q)

=============================================

cd /opt/gopath/src/github.com/hyperledger/fabric/scripts

./bootstrap.sh

首次需要创建(有问题)

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

新建channel-artifacts文件夹

export FABRIC_CFG_PATH=$PWD

./bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block

chmod +x /opt/gopath/src/github.com/hyperledger/fabric/aberic/bin/configtxgen

chmod -R 777 /opt/gopath/src/github.com/hyperledger/fabric/aberic/bin

$ ./bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel.tx -channelID mychannel

新增通道:$ /opt/gopath/src/github.com/hyperledger/fabric/aberic/bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel2.tx -channelID mychannel2

export CHANNEL_NAME=mychannel

新增通道:export CHANNEL_NAME=mychannel2

$ ./bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP

$ ./bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP

修改docker-peer.yaml文件,修改成为红色部分,/Users/shijun/Desktop/fabricWorkspace/membersheepFabric/crypto-config/peerOrganizations/org1.example.com/ca/4855be3f47ea89f3e86425d6b2bf3fbc5343d187d61887188396405c844077ca_sk

channel-artifacts和crypto-config文件夹打包发给子节点

==============================

主节点执行(子节点不用):$ docker-compose -f docker-orderer.yaml up -d

主节点执行命令:$ docker-compose -f docker-peer.yaml up -d

子节点执行命令:docker-compose -f docker-peer0-org2.yaml up -d

$ docker exec -it cli bash

主节点执行:# peer channel create -o orderer.example.com:7050 -c mychannel  -f ./channel-artifacts/mychannel.tx 

主节点创建新通道:# peer channel create -o orderer.example.com:7050 -c mychannel2  -f ./channel-artifacts/mychannel2.tx 

子节点不用执行上面命令,直接执行:peer channel fetch 0 mychannel.block -o orderer.example.com:7050 -c mychannel

(新通道)子节点不用执行上面命令,直接执行:peer channel fetch 0 mychannel2.block -o orderer.example.com:7050 -c mychannel2

# peer channel join -b mychannel.block

新通道:# peer channel join -b mychannel2.block

新通道不用执行这句话:# peer chaincode install -n traceGoods -p github.com/hyperledger/fabric/aberic/chaincode/go/trace_goods -v 1.0
子节点不执行这句 # peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n traceGoods -c '{"Args":["init","admin","admin"]}' -P "OR ('Org1MSP.member')" -v 1.0

(新通道)子节点不执行这句 # peer chaincode instantiate -o orderer.example.com:7050 -C mychannel2 -n traceGoods -c '{"Args":["init","admin","admin"]}' -P "OR ('Org1MSP.member')" -v 1.0

# peer chaincode query -C mychannel -n traceGoods -c '{"Args":["queryAllGoods","admin","1","10"]}'

新通道:# peer chaincode query -C mychannel2 -n traceGoods -c '{"Args":["queryAllGoods","admin","1","10"]}'

#peer chaincode invoke -C mychannel -n traceGoods -c '{"Args":["addGoods","94cdaa8576314e6bb4277c11bc3f0492","PS4","2000","2018/12/12","admin"]}'

重启电脑后启动fabric,执行以下三条命令

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

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

$ docker exec -it cli bash

===============================================

docker-peer0-org2.yaml

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

services:

  couchdb:
    container_name: couchdb
    image: hyperledger/fabric-couchdb
    environment:
      - GODEBUG=netdns=go
    # Comment/Uncomment the port mapping if you want to hide/expose the CouchDB service,
    # for example map it to utilize Fauxton User Interface in dev environments.
    ports:
      - "5984:5984"

  ca:
    container_name: ca
    image: hyperledger/fabric-ca
    restart: always
    environment:
      - GODEBUG=netdns=go
      - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
      - FABRIC_CA_SERVER_CA_NAME=ca
      - FABRIC_CA_SERVER_TLS_ENABLED=false
      - FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org2.example.com-cert.pem
      - FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/373d2325b9a13a35b2eebefe5acc0529702f2194e3058bdad0d99b16d092e8ee_sk
    ports:
      - "7054:7054"
    command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.org2.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/373d2325b9a13a35b2eebefe5acc0529702f2194e3058bdad0d99b16d092e8ee_sk -b admin:adminpw -d'
    volumes:
      - ./crypto-config/peerOrganizations/org2.example.com/ca/:/etc/hyperledger/fabric-ca-server-config

  peer0.org2.example.com:
    container_name: peer0.org2.example.com
    image: hyperledger/fabric-peer
    restart: always
    environment:
      - GODEBUG=netdns=go
      - CORE_LEDGER_STATE_STATEDATABASE=couchdb
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984

      - CORE_PEER_ID=peer0.org2.example.com
      - CORE_PEER_NETWORKID=aberic
      - CORE_PEER_ADDRESS=peer0.org2.example.com:7051
      - CORE_PEER_CHAINCODELISTENADDRESS=peer0.org2.example.com:7052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:7051
      - CORE_PEER_LOCALMSPID=Org2MSP

      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      # the following setting starts chaincode containers on the same
      # bridge network as the peers
      # https://docs.docker.com/compose/networking/
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=aberic
      # - CORE_LOGGING_LEVEL=ERROR
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=aberic_default
      - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=false
      - CORE_PEER_TLS_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
    volumes:
        - /var/run/:/host/var/run/
        - ./crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp
        - ./crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
    ports:
      - 7051:7051
      - 7052:7052
      - 7053:7053
    depends_on:
      - couchdb
    networks:
      default:
        aliases:
          - aberic
    extra_hosts:
     - "orderer.example.com:10.85.106.142"
    networks:
      default:
        aliases:
          - aberic

  cli:
    container_name: cli
    image: hyperledger/fabric-tools
    tty: true
    environment:
      - GODEBUG=netdns=go
      - GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_ID=cli
      - CORE_PEER_ADDRESS=peer0.org2.example.com:7051
      - CORE_PEER_LOCALMSPID=Org2MSP
      - CORE_PEER_TLS_ENABLED=false
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    volumes:
        - /var/run/:/host/var/run/
        - ./chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/aberic/chaincode/go
        - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
        - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    depends_on:
      - peer0.org2.example.com
    extra_hosts:
     - "orderer.example.com:10.85.106.142"
     - "peer0.org1.example.com:10.85.106.142"
     - "peer1.org1.example.com:10.85.106.227"
===============================================

docker-orderer.yaml

version: '2'

services:

  orderer.example.com:
    container_name: orderer.example.com
    image: hyperledger/fabric-orderer
    environment:
      - GODEBUG=netdns=go
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=aberic_default
      # - ORDERER_GENERAL_LOGLEVEL=error
      - ORDERER_GENERAL_LOGLEVEL=debug
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_LISTENPORT=7050
      #- ORDERER_GENERAL_GENESISPROFILE=AntiMothOrdererGenesis
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
      #- ORDERER_GENERAL_LEDGERTYPE=ram
      #- ORDERER_GENERAL_LEDGERTYPE=file
      # enabled TLS
      - ORDERER_GENERAL_TLS_ENABLED=false
      - 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]
    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/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp
    - ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
    networks:
      default:
        aliases:
          - aberic
    ports:
      - 7050:7050
 

看完了这篇文章,相信你对“mac中Hyperledger fabric多通道多节点增删改查的示例分析”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

推荐阅读:
  1. mac系统中如何搭建Hyperledger composer环境
  2. Hyperledger Fabric网络构架的示例分析

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

hyperledger mac fabric

上一篇:ASP.NET的EF Core迁移怎么实现

下一篇:分布式ID生成器的解决方案是怎么样的

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》