Hyperledger Fabric 部署for Mac

環境準備

docker安裝

Docker最低版本要求是version 17.06.2-ce
推薦在Docker官網下載Mac版本git

go安裝

Go最低版本要求是 1.10.x
可在使用brew或者Go官網下載Mac版本github

下載示例,二進制和docker鏡像

在home目錄新建立一個目錄,好比golang

makedir ~/fabric_learning
cd ~/fabric_learning

下載腳本文件https://raw.githubusercontent... 到當前目錄下
執行腳本docker

./bootstrap.sh -s version_number

e.g.bootstrap

./bootstrap.sh -s 1.2.0

而後你將獲得一個 fabric-samples 文件夾
在fabric-samples/bin目錄下有以下平臺相關的二進制文件bash

  • configtxgen
  • cryptogen
  • fabric-ca-client
  • idemixgen
  • peer
  • configtxlator
  • discover
  • orderer

並下載了一系列所需的image文件網絡

手動搭建byfn網絡

如無特別說明如下的操做都在fabric-samples/first-network目錄下ide

修改docker-compose-cli.yaml文件log級別爲DEBUG

cli:
  container_name: cli
  image: hyperledger/fabric-tools:$IMAGE_TAG
  tty: true
  stdin_open: true
  environment:
    - GOPATH=/opt/gopath
    - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    #- CORE_LOGGING_LEVEL=INFO

生成加密材料 (x509證書和簽名密鑰)

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

命令執行完成後會看到以下輸出加密

org1.example.com
org2.example.com

並在first-network目錄下生成crypto-config文件夾,證書和密鑰都在此文件夾下unix

證書是身份的表明,當咱們的網絡實體交互和交易的時候,用來簽名和驗證權限
cryptogen 須要配置一個文件- crypto-config.yaml, 此文件包含了網絡的拓撲定義,有三個成員,分別是一個Orderer Org和兩個Peer Orgs (Org1 & Org2), 每一個Peer組織維護兩個peer結點爲組織和其中的組件生成一系列的證書和密鑰。

生成orderer 創世區塊 genesis block

export FABRIC_CFG_PATH=$PWD
../bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block

生成channel配置交易

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

定義錨節點

爲Org1定義錨節點

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

爲Org2定義錨節點

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

啓動網絡

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

建立和加入channel

Docker exec -it cli bash

命令成功後bash顯示以下

root@e1fac8b5ec98:/opt/gopath/src/github.com/hyperledger/fabric/peer#

建立channel

export CHANNEL_NAME=mychannel
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

將peer0.org1.example.com加入建立的channel

peer channel join -b mychannel.block

將peer0.org2.example.com加入建立的channel

CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_ADDRESS=peer0.org2.example.com:7051 CORE_PEER_LOCALMSPID="Org2MSP" 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 peer channel join -b mychannel.block

更新錨節點

peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_ADDRESS=peer0.org2.example.com:7051 CORE_PEER_LOCALMSPID="Org2MSP" 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 peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org2MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

安裝 & 實例化chaincode

peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"

查詢

peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'

Invoke

peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'
相關文章
相關標籤/搜索