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

猜你喜欢

转载自blog.csdn.net/weixin_43839871/article/details/106001194