Fabric2.X中,
fabric-samples
将作为Fabric1.X中的first-network
的替代。也就是说,在2.X版本及以后,使用fabric-samples
作为fabric的测试网络了。
在配置好基本环境之后,来看一下它为我们提供了哪些内容。
目录结构
root@lizonglin-virtual-machine:/home/lizonglin/GoWork/src/github.com/fabric/scripts/fabric-samples# ll
total 100
drwxr-xr-x 15 lizonglin lizonglin 4096 1月 21 10:55 ./
drwxr-xr-x 3 lizonglin lizonglin 4096 1月 21 10:17 ../
drwxr-xr-x 2 lizonglin lizonglin 4096 10月 1 03:52 bin/
drwxr-xr-x 8 lizonglin lizonglin 4096 1月 21 10:55 chaincode/
drwxr-xr-x 3 lizonglin lizonglin 4096 1月 21 10:55 chaincode-docker-devmode/
drwxr-xr-x 4 lizonglin lizonglin 4096 1月 21 10:55 ci/
-rw-r--r-- 1 lizonglin lizonglin 597 1月 17 18:50 CODE_OF_CONDUCT.md
-rw-r--r-- 1 lizonglin lizonglin 109 1月 17 18:50 CODEOWNERS
drwxr-xr-x 3 lizonglin lizonglin 4096 1月 21 10:55 commercial-paper/
drwxr-xr-x 2 lizonglin lizonglin 4096 10月 1 02:41 config/
-rw-r--r-- 1 lizonglin lizonglin 935 1月 17 18:50 CONTRIBUTING.md
drwxr-xr-x 5 lizonglin lizonglin 4096 1月 21 10:55 fabcar/
drwxr-xr-x 6 lizonglin lizonglin 4096 1月 21 11:24 first-network/
drwxr-xr-x 8 lizonglin lizonglin 4096 1月 21 10:55 .git/
-rw-r--r-- 1 lizonglin lizonglin 189 1月 21 10:55 .gitignore
drwxr-xr-x 4 lizonglin lizonglin 4096 1月 21 10:55 high-throughput/
drwxr-xr-x 4 lizonglin lizonglin 4096 1月 21 10:55 interest_rate_swaps/
-rw-r--r-- 1 lizonglin lizonglin 11358 1月 17 18:50 LICENSE
-rw-r--r-- 1 lizonglin lizonglin 1644 1月 21 10:55 MAINTAINERS.md
drwxr-xr-x 2 lizonglin lizonglin 4096 1月 21 10:55 off_chain_data/
-rw-r--r-- 1 lizonglin lizonglin 1694 1月 21 10:55 README.md
-rw-r--r-- 1 lizonglin lizonglin 1035 1月 17 18:50 SECURITY.md
drwxr-xr-x 8 lizonglin lizonglin 4096 1月 21 18:52 test-network/
fabric-samples的目录结构如下,可以看到还是暂时为我们保留了first-network,但是新版的启动网络脚本则是在test-network中。
root@lizonglin-virtual-machine:/home/lizonglin/GoWork/src/github.com/fabric/scripts/fabric-samples/test-network# ll
total 68
drwxr-xr-x 8 lizonglin lizonglin 4096 1月 21 18:52 ./
drwxr-xr-x 15 lizonglin lizonglin 4096 1月 21 10:55 ../
drwxr-xr-x 4 lizonglin lizonglin 4096 1月 21 10:55 addOrg3/
drwxr-xr-x 2 lizonglin lizonglin 4096 1月 21 10:55 configtx/
drwxr-xr-x 2 lizonglin lizonglin 4096 1月 21 10:55 docker/
-rw-r--r-- 1 lizonglin lizonglin 69 1月 17 18:50 .env
-rw-r--r-- 1 lizonglin lizonglin 349 1月 21 10:55 .gitignore
-rwxr-xr-x 1 lizonglin lizonglin 20570 1月 21 10:55 network.sh*
drwxr-xr-x 4 lizonglin lizonglin 4096 1月 21 20:05 organizations/
-rw-r--r-- 1 lizonglin lizonglin 788 1月 21 10:55 README.md
drwxr-xr-x 3 lizonglin lizonglin 4096 1月 21 10:55 scripts/
drwxr-xr-x 2 lizonglin lizonglin 4096 1月 21 20:05 system-genesis-block/
network.sh
其中,network.sh*即启动脚本,在新的脚本中,为我们进行了大量的配置工作,使得新版本的脚本很长,省略一些不必要的内容:
#!/bin/bash
# 首先是一些说明:
# 两个组织,每个组织一个peer节点
# 一个使用Raft单节点的排序服务
# This script brings up a Hyperledger Fabric network for testing smart contracts
# and applications. The test network consists of two organizations with one
# peer each, and a single node Raft ordering service. Users can also use this
# script to create a channel deploy a chaincode on the channel
#
# prepending $PWD/../bin to PATH to ensure we are picking up the correct binaries
# this may be commented out to resolve installed version of tools if desired
export PATH=${PWD}/../bin:${PWD}:$PATH
export FABRIC_CFG_PATH=${PWD}/configtx
export VERBOSE=false
# Print the usage message
function printHelp() {
echo "Usage: "
echo " network.sh <Mode> [Flags]"
echo " <Mode>"
echo " - 'up' - bring up fabric orderer and peer nodes. No channel is created"
echo " - 'up createChannel' - bring up fabric network with one channel"
echo " - 'createChannel' - create and join a channel after the network is created"
echo " - 'deployCC' - deploy the fabcar chaincode on the channel"
echo " - 'down' - clear the network with docker-compose down"
echo " - 'restart' - restart the network"
echo
echo " Flags:"
echo " -ca <use CAs> - create Certificate Authorities to generate the crypto material"
echo " -c <channel name> - channel name to use (defaults to \"mychannel\")"
echo " -s <dbtype> - the database backend to use: goleveldb (default) or couchdb"
echo " -r <max retry> - CLI times out after certain number of attempts (defaults to 5)"
echo " -d <delay> - delay duration in seconds (defaults to 3)"
echo " -l <language> - the programming language of the chaincode to deploy: go (default), java, javascript, typescript"
echo " -v <version> - chaincode version. Must be a round number, 1, 2, 3, etc"
echo " -i <imagetag> - the tag to be used to launch the network (defaults to \"latest\")"
echo " -verbose - verbose mode"
echo " network.sh -h (print this message)"
echo
echo " Possible Mode and flags"
echo " network.sh up -ca -c -r -d -s -i -verbose"
echo " network.sh up createChannel -ca -c -r -d -s -i -verbose"
echo " network.sh createChannel -c -r -d -verbose"
echo " network.sh deployCC -l -v -r -d -verbose"
echo
echo " Taking all defaults:"
echo " network.sh up"
echo
echo " Examples:"
echo " network.sh up createChannel -ca -c mychannel -s couchdb -i 2.0.0"
echo " network.sh createChannel -c channelName"
echo " network.sh deployCC -l javascript"
}
# 清理docker容器
# Obtain CONTAINER_IDS and remove them
# TODO Might want to make this optional - could clear other containers
# This function is called when you bring a network down
function clearContainers() {
CONTAINER_IDS=$(docker ps -a | awk '($2 ~ /dev-peer.*/) {print $1}')
if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" == " " ]; then
echo "---- No containers available for deletion ----"
else
docker rm -f $CONTAINER_IDS
fi
}
# 删除docker镜像
# Delete any images that were generated as a part of this setup
# specifically the following images are often left behind:
# This function is called when you bring the network down
function removeUnwantedImages() {
DOCKER_IMAGE_IDS=$(docker images | awk '($1 ~ /dev-peer.*/) {print $3}')
if [ -z "$DOCKER_IMAGE_IDS" -o "$DOCKER_IMAGE_IDS" == " " ]; then
echo "---- No images available for deletion ----"
else
docker rmi -f $DOCKER_IMAGE_IDS
fi
}
# Versions of fabric known not to work with the test network
BLACKLISTED_VERSIONS="^1\.0\. ^1\.1\. ^1\.2\. ^1\.3\. ^1\.4\."
# 这里检查一下现有的二进制文件以及镜像是否可用,免得后续出现问题
# Do some basic sanity checking to make sure that the appropriate versions of fabric
# binaries/images are available. In the future, additional checking for the presence
# of go or other items could be added.
function checkPrereqs() {
## Check if your have cloned the peer binaries and configuration files.
peer version > /dev/null 2>&1
if [[ $? -ne 0 || ! -d "../config" ]]; then
echo "ERROR! Peer binary and configuration files not found.."
echo
echo "Follow the instructions in the Fabric docs to install the Fabric Binaries:"
echo "https://hyperledger-fabric.readthedocs.io/en/latest/install.html"
exit 1
fi
# 检查docker镜像以及二进制文件是否匹配
# use the fabric tools container to see if the samples and binaries match your
# docker images
LOCAL_VERSION=$(peer version | sed -ne 's/ Version: //p')
DOCKER_IMAGE_VERSION=$(docker run --rm hyperledger/fabric-tools:$IMAGETAG peer version | sed -ne 's/ Version: //p' | head -1)
echo "LOCAL_VERSION=$LOCAL_VERSION"
echo "DOCKER_IMAGE_VERSION=$DOCKER_IMAGE_VERSION"
if [ "$LOCAL_VERSION" != "$DOCKER_IMAGE_VERSION" ]; then
echo "=================== WARNING ==================="
echo " Local fabric binaries and docker images are "
echo " out of sync. This may cause problems. "
echo "==============================================="
fi
for UNSUPPORTED_VERSION in $BLACKLISTED_VERSIONS; do
echo "$LOCAL_VERSION" | grep -q $UNSUPPORTED_VERSION
if [ $? -eq 0 ]; then
echo "ERROR! Local Fabric binary version of $LOCAL_VERSION does not match the versions supported by the test network."
exit 1
fi
echo "$DOCKER_IMAGE_VERSION" | grep -q $UNSUPPORTED_VERSION
if [ $? -eq 0 ]; then
echo "ERROR! Fabric Docker image version of $DOCKER_IMAGE_VERSION does not match the versions supported by the test network."
exit 1
fi
done
}
# 下面简单介绍了cryptogen这个工具以及CA
# Before you can bring up a network, each organization needs to generate the crypto
# material that will define that organization on the network. Because Hyperledger
# Fabric is a permissioned blockchain, each node and user on the network needs to
# use certificates and keys to sign and verify its actions. In addition, each user
# needs to belong to an organization that is recognized as a member of the network.
# You can use the Cryptogen tool or Fabric CAs to generate the organization crypto
# material.
# By default, the sample network uses cryptogen. Cryptogen is a tool that is
# meant for development and testing that can quicky create the certificates and keys
# that can be consumed by a Fabric network. The cryptogen tool consumes a series
# of configuration files for each organization in the "organizations/cryptogen"
# directory. Cryptogen uses the files to generate the crypto material for each
# org in the "organizations" directory.
# You can also Fabric CAs to generate the crypto material. CAs sign the certificates
# and keys that they generate to create a valid root of trust for each organization.
# The script uses Docker Compose to bring up three CAs, one for each peer organization
# and the ordering organization. The configuration file for creating the Fabric CA
# servers are in the "organizations/fabric-ca" directory. Within the same diectory,
# the "registerEnroll.sh" script uses the Fabric CA client to create the identites,
# certificates, and MSP folders that are needed to create the test network in the
# "organizations/ordererOrganizations" directory.
# Create Organziation crypto material using cryptogen or CAs
function createOrgs() {
if [ -d "organizations/peerOrganizations" ]; then
rm -Rf organizations/peerOrganizations && rm -Rf organizations/ordererOrganizations
fi
# Create crypto material using cryptogen
if [ "$CRYPTO" == "cryptogen" ]; then
which cryptogen
if [ "$?" -ne 0 ]; then
echo "cryptogen tool not found. exiting"
exit 1
fi
echo
echo "##########################################################"
echo "##### Generate certificates using cryptogen tool #########"
echo "##########################################################"
echo
echo "##########################################################"
echo "############ Create Org1 Identities ######################"
echo "##########################################################"
set -x
cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output="organizations"
res=$?
set +x
if [ $res -ne 0 ]; then
echo "Failed to generate certificates..."
exit 1
fi
echo "##########################################################"
echo "############ Create Org2 Identities ######################"
echo "##########################################################"
set -x
cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output="organizations"
res=$?
set +x
if [ $res -ne 0 ]; then
echo "Failed to generate certificates..."
exit 1
fi
echo "##########################################################"
echo "############ Create Orderer Org Identities ###############"
echo "##########################################################"
set -x
cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output="organizations"
res=$?
set +x
if [ $res -ne 0 ]; then
echo "Failed to generate certificates..."
exit 1
fi
fi
# Create crypto material using Fabric CAs
if [ "$CRYPTO" == "Certificate Authorities" ]; then
fabric-ca-client version > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Fabric CA client not found locally, downloading..."
cd ..
curl -s -L "https://github.com/hyperledger/fabric-ca/releases/download/v1.4.4/hyperledger-fabric-ca-${OS_ARCH}-1.4.4.tar.gz" | tar xz || rc=$?
if [ -n "$rc" ]; then
echo "==> There was an error downloading the binary file."
echo "fabric-ca-client binary is not available to download"
else
echo "==> Done."
cd test-network
fi
fi
echo
echo "##########################################################"
echo "##### Generate certificates using Fabric CA's ############"
echo "##########################################################"
IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE_CA up -d 2>&1
. organizations/fabric-ca/registerEnroll.sh
sleep 10
echo "##########################################################"
echo "############ Create Org1 Identities ######################"
echo "##########################################################"
createOrg1
echo "##########################################################"
echo "############ Create Org2 Identities ######################"
echo "##########################################################"
createOrg2
echo "##########################################################"
echo "############ Create Orderer Org Identities ###############"
echo "##########################################################"
createOrderer
fi
echo
echo "Generate CCP files for Org1 and Org2"
./organizations/ccp-generate.sh
}
# 使用cryptogen(cryptogen用于配置网络中的证书、组织等)配置完网络组织后
# 这里使用configtxgen配置创世区块、channel以及锚节点
# 有一个"configtx.yaml"文件帮助配置网络中的组织创世区块,组织成员等内容
# 创建每个channel的MSP
# Once you create the organization crypto material, you need to create the
# genesis block of the orderer system channel. This block is required to bring
# up any orderer nodes and create any application channels.
# The configtxgen tool is used to create the genesis block. Configtxgen consumes a
# "configtx.yaml" file that contains the definitions for the sample network. The
# genesis block is defiend using the "TwoOrgsOrdererGenesis" profile at the bottom
# of the file. This profile defines a sample consortium, "SampleConsortium",
# consisting of our two Peer Orgs. This consortium defines which organizations are
# recognized as members of the network. The peer and ordering organizations are defined
# in the "Profiles" section at the top of the file. As part of each organization
# profile, the file points to a the location of the MSP directory for each member.
# This MSP is used to create the channel MSP that defines the root of trust for
# each organization. In essense, the channel MSP allows the nodes and users to be
# recognized as network members. The file also specifies the anchor peers for each
# peer org. In future steps, this same file is used to create the channel creation
# transaction and the anchor peer updates.
#
#
# If you receive the following warning, it can be safely ignored:
#
# [bccsp] GetDefault -> WARN 001 Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
#
# You can ignore the logs regarding intermediate certs, we are not using them in
# this crypto implementation.
# Generate orderer system channel genesis block.
function createConsortium() {
which configtxgen
if [ "$?" -ne 0 ]; then
echo "configtxgen tool not found. exiting"
exit 1
fi
echo "######### Generating Orderer Genesis block ##############"
# Note: For some unknown reason (at least for now) the block file can't be
# named orderer.genesis.block or the orderer will fail to launch!
set -x
configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
res=$?
set +x
if [ $res -ne 0 ]; then
echo "Failed to generate orderer genesis block..."
exit 1
fi
}
# 之后,启动peer节点和排序服务,创建相应的docker实体
# After we create the org crypto material and the system channel genesis block,
# we can now bring up the peers and orderering service. By default, the base
# file for creating the network is "docker-compose-test-net.yaml" in the ``docker``
# folder. This file defines the environment variables and file mounts that
# point the crypto material and genesis block that were created in earlier.
# Bring up the peer and orderer nodes using docker compose.
function networkUp() {
checkPrereqs
# generate artifacts if they don't exist
if [ ! -d "organizations/peerOrganizations" ]; then
createOrgs
createConsortium
fi
COMPOSE_FILES="-f ${COMPOSE_FILE_BASE}"
if [ "${DATABASE}" == "couchdb" ]; then
COMPOSE_FILES="${COMPOSE_FILES} -f ${COMPOSE_FILE_COUCH}"
fi
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
}
# 将peer加入通道
## call the script to join create the channel and join the peers of org1 and org2
function createChannel() {
## Bring up the network if it is not arleady up.
if [ ! -d "organizations/peerOrganizations" ]; then
echo "Bringing up network"
networkUp
fi
# now run the script that creates a channel. This script uses configtxgen once
# more to create the channel creation transaction and the anchor peer updates.
# configtx.yaml is mounted in the cli container, which allows us to use it to
# create the channel artifacts
scripts/createChannel.sh $CHANNEL_NAME $CLI_DELAY $MAX_RETRY $VERBOSE
if [ $? -ne 0 ]; then
echo "Error !!! Create channel failed"
exit 1
fi
}
# 实例化链码
## Call the script to isntall and instantiate a chaincode on the channel
function deployCC() {
scripts/deployCC.sh $CHANNEL_NAME $CC_SRC_LANGUAGE $VERSION $CLI_DELAY $MAX_RETRY $VERBOSE
if [ $? -ne 0 ]; then
echo "ERROR !!! Deploying chaincode failed"
exit 1
fi
exit 0
}
# 关闭网络
# Tear down running network
function networkDown() {
# stop org3 containers also in addition to org1 and org2, in case we were running sample to add org3
docker-compose -f $COMPOSE_FILE_BASE -f $COMPOSE_FILE_COUCH -f $COMPOSE_FILE_CA down --volumes --remove-orphans
docker-compose -f $COMPOSE_FILE_COUCH_ORG3 -f $COMPOSE_FILE_ORG3 down --volumes --remove-orphans
# Don't remove the generated artifacts -- note, the ledgers are always removed
if [ "$MODE" != "restart" ]; then
# Bring down the network, deleting the volumes
#Cleanup the chaincode containers
clearContainers
#Cleanup images
removeUnwantedImages
# remove orderer block and other channel configuration transactions and certs
rm -rf system-genesis-block/*.block organizations/peerOrganizations organizations/ordererOrganizations
## remove fabric ca artifacts
rm -rf organizations/fabric-ca/org1/msp organizations/fabric-ca/org1/tls-cert.pem organizations/fabric-ca/org1/ca-cert.pem organizations/fabric-ca/org1/IssuerPublicKey organizations/fabric-ca/org1/IssuerRevocationPublicKey organizations/fabric-ca/org1/fabric-ca-server.db
rm -rf organizations/fabric-ca/org2/msp organizations/fabric-ca/org2/tls-cert.pem organizations/fabric-ca/org2/ca-cert.pem organizations/fabric-ca/org2/IssuerPublicKey organizations/fabric-ca/org2/IssuerRevocationPublicKey organizations/fabric-ca/org2/fabric-ca-server.db
rm -rf organizations/fabric-ca/ordererOrg/msp organizations/fabric-ca/ordererOrg/tls-cert.pem organizations/fabric-ca/ordererOrg/ca-cert.pem organizations/fabric-ca/ordererOrg/IssuerPublicKey organizations/fabric-ca/ordererOrg/IssuerRevocationPublicKey organizations/fabric-ca/ordererOrg/fabric-ca-server.db
rm -rf addOrg3/fabric-ca/org3/msp addOrg3/fabric-ca/org3/tls-cert.pem addOrg3/fabric-ca/org3/ca-cert.pem addOrg3/fabric-ca/org3/IssuerPublicKey addOrg3/fabric-ca/org3/IssuerRevocationPublicKey addOrg3/fabric-ca/org3/fabric-ca-server.db
# remove channel and script artifacts
rm -rf channel-artifacts log.txt fabcar.tar.gz fabcar
fi
}
# Obtain the OS and Architecture string that will be used to select the correct
# native binaries for your platform, e.g., darwin-amd64 or linux-amd64
OS_ARCH=$(echo "$(uname -s | tr '[:upper:]' '[:lower:]' | sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')
# Using crpto vs CA. default is cryptogen
CRYPTO="cryptogen"
# timeout duration - the duration the CLI should wait for a response from
# another container before giving up
MAX_RETRY=5
# default for delay between commands
CLI_DELAY=3
# channel name defaults to "mychannel"
CHANNEL_NAME="mychannel"
# use this as the default docker-compose yaml definition
COMPOSE_FILE_BASE=docker/docker-compose-test-net.yaml
# docker-compose.yaml file if you are using couchdb
COMPOSE_FILE_COUCH=docker/docker-compose-couch.yaml
# certificate authorities compose file
COMPOSE_FILE_CA=docker/docker-compose-ca.yaml
# use this as the docker compose couch file for org3
COMPOSE_FILE_COUCH_ORG3=addOrg3/docker/docker-compose-couch-org3.yaml
# use this as the default docker-compose yaml definition for org3
COMPOSE_FILE_ORG3=addOrg3/docker/docker-compose-org3.yaml
#
# use golang as the default language for chaincode
CC_SRC_LANGUAGE=golang
# Chaincode version
VERSION=1
# default image tag
IMAGETAG="latest"
# default database
DATABASE="leveldb"
# Parse commandline args
## Parse mode
if [[ $# -lt 1 ]] ; then
printHelp
exit 0
else
MODE=$1
shift
fi
# parse a createChannel subcommand if used
if [[ $# -ge 1 ]] ; then
key="$1"
if [[ "$key" == "createChannel" ]]; then
export MODE="createChannel"
shift
fi
fi
# parse flags
while [[ $# -ge 1 ]] ; do
key="$1"
case $key in
-h )
printHelp
exit 0
;;
-c )
CHANNEL_NAME="$2"
shift
;;
-ca )
CRYPTO="Certificate Authorities"
;;
-r )
MAX_RETRY="$2"
shift
;;
-d )
CLI_DELAY="$2"
shift
;;
-s )
DATABASE="$2"
shift
;;
-l )
CC_SRC_LANGUAGE="$2"
shift
;;
-v )
VERSION="$2"
shift
;;
-i )
IMAGETAG="$2"
shift
;;
-verbose )
VERBOSE=true
shift
;;
* )
echo
echo "Unknown flag: $key"
echo
printHelp
exit 1
;;
esac
shift
done
# Are we generating crypto material with this command?
if [ ! -d "organizations/peerOrganizations" ]; then
CRYPTO_MODE="with crypto from '${CRYPTO}'"
else
CRYPTO_MODE=""
fi
# Determine mode of operation and printing out what we asked for
if [ "$MODE" == "up" ]; then
echo "Starting nodes with CLI timeout of '${MAX_RETRY}' tries and CLI delay of '${CLI_DELAY}' seconds and using database '${DATABASE}' ${CRYPTO_MODE}"
echo
elif [ "$MODE" == "createChannel" ]; then
echo "Creating channel '${CHANNEL_NAME}'."
echo
echo "If network is not up, starting nodes with CLI timeout of '${MAX_RETRY}' tries and CLI delay of '${CLI_DELAY}' seconds and using database '${DATABASE} ${CRYPTO_MODE}"
echo
elif [ "$MODE" == "down" ]; then
echo "Stopping network"
echo
elif [ "$MODE" == "restart" ]; then
echo "Restarting network"
echo
elif [ "$MODE" == "deployCC" ]; then
echo "deploying chaincode on channel '${CHANNEL_NAME}'"
echo
else
printHelp
exit 1
fi
if [ "${MODE}" == "up" ]; then
networkUp
elif [ "${MODE}" == "createChannel" ]; then
createChannel
elif [ "${MODE}" == "deployCC" ]; then
deployCC
elif [ "${MODE}" == "down" ]; then
networkDown
elif [ "${MODE}" == "restart" ]; then
networkDown
networkUp
else
printHelp
exit 1
fi
启动test-network
root@lizonglin-virtual-machine:/home/lizonglin/GoWork/src/github.com/fabric/scripts/fabric-samples/test-network# ./network.sh up
# 可以看到,默认使用leveldb
Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' with crypto from 'cryptogen'
LOCAL_VERSION=2.2.1
DOCKER_IMAGE_VERSION=2.2.1
/home/lizonglin/GoWork/src/github.com/fabric/scripts/fabric-samples/test-network/../bin/cryptogen
# 首先使用cryptogen创建证书
##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
# 组织1
##########################################################
############ Create Org1 Identities ######################
##########################################################
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations
org1.example.com
+ res=0
+ set +x
# 组织2
##########################################################
############ Create Org2 Identities ######################
##########################################################
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations
org2.example.com
+ res=0
+ set +x
# 排序服务
##########################################################
############ Create Orderer Org Identities ###############
##########################################################
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations
+ res=0
+ set +x
Generate CCP files for Org1 and Org2
/home/lizonglin/GoWork/src/github.com/fabric/scripts/fabric-samples/test-network/../bin/configtxgen
# 排序节点的创世区块
######### Generating Orderer Genesis block ##############
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
2021-01-21 18:53:34.963 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2021-01-21 18:53:35.017 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft
2021-01-21 18:53:35.017 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216
2021-01-21 18:53:35.017 CST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /home/lizonglin/GoWork/src/github.com/fabric/scripts/fabric-samples/test-network/configtx/configtx.yaml
2021-01-21 18:53:35.019 CST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block
2021-01-21 18:53:35.020 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Writing genesis block
+ res=0
+ set +x
Creating network "net_test" with the default driver
Creating volume "net_orderer.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating peer0.org2.example.com ... done
Creating orderer.example.com ... done
Creating peer0.org1.example.com ... done
# 现在的docker中包含的容器,test-network到这里就是初步启动成功了
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ae8899485a40 hyperledger/fabric-peer:latest "peer node start" 18 seconds ago Up Less than a second 0.0.0.0:7051->7051/tcp peer0.org1.example.com
e8e4acee2cdd hyperledger/fabric-orderer:latest "orderer" 18 seconds ago Up Less than a second 0.0.0.0:7050->7050/tcp orderer.example.com
c0c720b03c4a hyperledger/fabric-peer:latest "peer node start" 18 seconds ago Up 1 second 7051/tcp, 0.0.0.0:9051->9051/tcp peer0.org2.example.com