您好,登錄后才能下訂單哦!
小編給大家分享一下mac中Hyperledger fabric多通道多節(jié)點(diǎn)增刪改查的示例分析,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
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
首次需要?jiǎng)?chuàng)建(有問(wèn)題)
./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文件夾打包發(fā)給子節(jié)點(diǎn)
==============================
主節(jié)點(diǎn)執(zhí)行(子節(jié)點(diǎn)不用):$ docker-compose -f docker-orderer.yaml up -d
主節(jié)點(diǎn)執(zhí)行命令:$ docker-compose -f docker-peer.yaml up -d
子節(jié)點(diǎn)執(zhí)行命令:docker-compose -f docker-peer0-org2.yaml up -d
$ docker exec -it cli bash
主節(jié)點(diǎn)執(zhí)行:# peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/mychannel.tx
主節(jié)點(diǎn)創(chuàng)建新通道:# peer channel create -o orderer.example.com:7050 -c mychannel2 -f ./channel-artifacts/mychannel2.tx
子節(jié)點(diǎn)不用執(zhí)行上面命令,直接執(zhí)行:peer channel fetch 0 mychannel.block -o orderer.example.com:7050 -c mychannel
(新通道)子節(jié)點(diǎn)不用執(zhí)行上面命令,直接執(zhí)行: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
新通道不用執(zhí)行這句話:# peer chaincode install -n traceGoods -p github.com/hyperledger/fabric/aberic/chaincode/go/trace_goods -v 1.0
子節(jié)點(diǎn)不執(zhí)行這句 # peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n traceGoods -c '{"Args":["init","admin","admin"]}' -P "OR ('Org1MSP.member')" -v 1.0
(新通道)子節(jié)點(diǎn)不執(zhí)行這句 # 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"]}'
重啟電腦后啟動(dòng)fabric,執(zhí)行以下三條命令
$ 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
看完了這篇文章,相信你對(duì)“mac中Hyperledger fabric多通道多節(jié)點(diǎn)增刪改查的示例分析”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。