Fabric2.0 SDK測試網絡搭建

前期準備

  操作系統:CentOS 7
  Fabric版本: 2.x(1.x版本參考Fabric SDK測試網絡搭建(v1.x))

軟件/依賴 版本
go 1.14.x
git 最新版本
curl 最新版本
docker 17.06.2-ce及以上版本
docker-compose 1.14及以上

   下載fabric-samples源碼:下載地址

git clone -b master https://github.com/hyperledger/fabric-samples.git && cd fabric-samples && git checkout v2.0.1
mkdir bin 

   將下載好的二進制工具,放置在fabric-samples/bin路徑下,請確保所下載二進制工具版本爲v2.0.1

運行

   默認fabric-samples/first-network會啓動一個兩個組織四個節點(不含CA節點)的網絡,和1.x版本的腳本不同,2.x版本腳本啓動時可選擇是否啓動CA節點(默認不啓動CA)
   byfn.sh腳本部分內容

# Generate the needed certificates, the genesis block and start the network.
function networkUp() {
  #檢查二進制文件是否可用,以及對應版本的docker鏡像是否存在
  checkPrereqs
  # generate artifacts if they don't exist,假設當前sh所在的父目錄不存在crypto-config目錄就執行生成區塊通道以及證書腳本
  if [ ! -d "crypto-config" ]; then
    generateCerts
    generateChannelArtifacts
  fi
  COMPOSE_FILES="-f ${COMPOSE_FILE} -f ${COMPOSE_FILE_RAFT2}"
  if [ "${CERTIFICATE_AUTHORITIES}" == "true" ]; then
    COMPOSE_FILES="${COMPOSE_FILES} -f ${COMPOSE_FILE_CA}"
    export BYFN_CA1_PRIVATE_KEY=$(cd crypto-config/peerOrganizations/org1.example.com/ca && ls *_sk)
    export BYFN_CA2_PRIVATE_KEY=$(cd crypto-config/peerOrganizations/org2.example.com/ca && ls *_sk)
  fi
  if [ "${IF_COUCHDB}" == "couchdb" ]; then
    COMPOSE_FILES="${COMPOSE_FILES} -f ${COMPOSE_FILE_COUCH}"
  fi
  #使用docker-compose命令啓動fabric網絡
  IMAGE_TAG=$IMAGETAG docker-compose ${COMPOSE_FILES} up -d 2>&1
  docker ps -a
  if [ $? -ne 0 ]; then
    echo "ERROR !!!! Unable to start network"
    exit 1
  fi

  echo "Sleeping 15s to allow Raft cluster to complete booting"
  sleep 15

  if [ "${NO_CHAINCODE}" != "true" ]; then
    #加載go合約依賴包
    echo Vendoring Go dependencies ...
    pushd ../chaincode/abstore/go
    GO111MODULE=on go mod vendor
    popd
    echo Finished vendoring Go dependencies
  fi

  # now run the end to end script
  # 使用cli客戶端執行腳本操作
  docker exec cli scripts/script.sh $CHANNEL_NAME $CLI_DELAY $CC_SRC_LANGUAGE $CLI_TIMEOUT $VERBOSE $NO_CHAINCODE
  if [ $? -ne 0 ]; then
    echo "ERROR !!!! Test failed"
    exit 1
  fi
}

  CERTIFICATE_AUTHORITIES爲一變量,啓動時通過-a參數傳入;進入fabric-samples/first-network/目錄,看下官方還提供了哪些命令

./byfn.sh help

輸出:

Usage: 
  byfn.sh <mode> [-c <channel name>] [-t <timeout>] [-d <delay>] [-f <docker-compose-file>] [-s <dbtype>] [-l <language>] [-o <consensus-type>] [-i <imagetag>] [-a] [-n] [-v]
    <mode> - one of 'up', 'down', 'restart', 'generate' or 'upgrade'
      - 'up' - bring up the network with docker-compose up
      - 'down' - clear the network with docker-compose down
      - 'restart' - restart the network
      - 'generate' - generate required certificates and genesis block
      - 'upgrade'  - upgrade the network from version 1.3.x to 1.4.0
    -c <channel name> - channel name to use (defaults to "mychannel")
    -t <timeout> - CLI timeout duration in seconds (defaults to 10)
    -d <delay> - delay duration in seconds (defaults to 3)
    -s <dbtype> - the database backend to use: goleveldb (default) or couchdb
    -l <language> - the programming language of the chaincode to deploy: go (default), javascript, or java
    -i <imagetag> - the tag to be used to launch the network (defaults to "latest")
    -a - launch certificate authorities (no certificate authorities are launched by default)
    -n - do not deploy chaincode (abstore chaincode is deployed by default)
    -v - verbose mode
  byfn.sh -h (print this message)

Typically, one would first generate the required certificates and 
genesis block, then bring up the network. e.g.:

	byfn.sh generate -c mychannel
	byfn.sh up -c mychannel -s couchdb
        byfn.sh up -c mychannel -s couchdb -i 1.4.0
	byfn.sh up -l javascript
	byfn.sh down -c mychannel
        byfn.sh upgrade -c mychannel

Taking all defaults:
	byfn.sh generate
	byfn.sh up
	byfn.sh down

  言歸正傳,執行以下命令

./byfn.sh up -a true

  由此etcd raft SDK測試網絡搭建完成

關於啓用/關閉 TLS

  啓用/關閉 TLS 請修改fabric-samples/first-network/base/目錄下的peer-base.yaml

  Orderer節點:

- ORDERER_GENERCORE_PEER_TLS_ENABLED=true

  Peer節點:

- CORE_PEER_TLS_ENABLED=true
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章