Hyperledger Fabric 1.0 版本整体 重新设计了架构,新的设计可以实现更好的扩展性和安全性。
$ git clone https://github.com/yeasy/docker-compose-files
进入 hyperledger/1.0 目录,查看包括若干模板文件,功能如下。
hyperledger/1.0
channel
chaincode
docker 及 docker-compose 可以自行手动安装。也可以通过 hyperledger/1.0/scripts 提供的 setup_Docker.sh 脚本自动安装。
setup_Docker.sh
$ bash scripts/setup_Docker.sh
Docker 镜像可以自行从源码编译(make docker),或从 DockerHub 仓库下载。
make docker
直接执行 hyperledger/1.0/scripts 提供的 download_images.sh 脚本获取。
download_images.sh
$ bash scripts/download_images.sh
从社区 DockerHub 仓库下载。
# pull fabric images ARCH=x86_64 BASEIMAGE_RELEASE=0.3.1 BASE_VERSION=1.0.0 PROJECT_VERSION=1.0.0 IMG_TAG=1.0.0 echo "Downloading fabric images from DockerHub...with tag = ${IMG_TAG}... need a while" # TODO: we may need some checking on pulling result? docker pull hyperledger/fabric-peer:$ARCH-$IMG_TAG docker pull hyperledger/fabric-orderer:$ARCH-$IMG_TAG docker pull hyperledger/fabric-ca:$ARCH-$IMG_TAG docker pull hyperledger/fabric-tools:$ARCH-$IMG_TAG docker pull hyperledger/fabric-ccenv:$ARCH-$PROJECT_VERSION docker pull hyperledger/fabric-baseimage:$ARCH-$BASEIMAGE_RELEASE docker pull hyperledger/fabric-baseos:$ARCH-$BASEIMAGE_RELEASE # Only useful for debugging # docker pull yeasy/hyperledger-fabric echo "===Re-tagging images to *latest* tag" docker tag hyperledger/fabric-peer:$ARCH-$IMG_TAG hyperledger/fabric-peer docker tag hyperledger/fabric-orderer:$ARCH-$IMG_TAG hyperledger/fabric-orderer docker tag hyperledger/fabric-ca:$ARCH-$IMG_TAG hyperledger/fabric-ca docker tag hyperledger/fabric-tools:$ARCH-$IMG_TAG hyperledger/fabric-tools
这里也提供了调整(基于 golang:1.8 基础镜像制作)后的第三方镜像,与社区版本功能是一致的。
通过如下命令拉取相关镜像,并更新镜像别名。
$ ARCH=x86_64 $ BASEIMAGE_RELEASE=0.3.1 $ BASE_VERSION=1.0.0 $ PROJECT_VERSION=1.0.0 $ IMG_TAG=1.0.0 $ docker pull yeasy/hyperledger-fabric-base:$IMG_VERSION \ && docker pull yeasy/hyperledger-fabric-peer:$IMG_VERSION \ && docker pull yeasy/hyperledger-fabric-orderer:$IMG_VERSION \ && docker pull yeasy/hyperledger-fabric-ca:$IMG_VERSION \ && docker pull hyperledger/fabric-couchdb:$ARCH-$IMG_VERSION \ && docker pull hyperledger/fabric-kafka:$ARCH-$IMG_VERSION \ && docker pull hyperledger/fabric-zookeeper:$ARCH-$IMG_VERSION $ docker tag yeasy/hyperledger-fabric-peer:$IMG_VERSION hyperledger/fabric-peer \ && docker tag yeasy/hyperledger-fabric-orderer:$IMG_VERSION hyperledger/fabric-orderer \ && docker tag yeasy/hyperledger-fabric-ca:$IMG_VERSION hyperledger/fabric-ca \ && docker tag yeasy/hyperledger-fabric-peer:$IMG_VERSION hyperledger/fabric-tools \ && docker tag yeasy/hyperledger-fabric-base:$IMG_VERSION hyperledger/fabric-ccenv:$ARCH-$PROJECT_VERSION \ && docker tag yeasy/hyperledger-fabric-base:$IMG_VERSION hyperledger/fabric-baseos:$ARCH-$BASEIMAGE_RELEASE \ && docker tag yeasy/hyperledger-fabric-base:$IMG_VERSION hyperledger/fabric-baseimage:$ARCH-$BASEIMAGE_RELEASE \ && docker tag hyperledger/fabric-couchdb:$ARCH-$IMG_VERSION hyperledger/fabric-couchdb \ && docker tag hyperledger/fabric-zookeeper:$ARCH-$IMG_VERSION hyperledger/fabric-zookeeper \ && docker tag hyperledger/fabric-kafka:$ARCH-$IMG_VERSION hyperledger/fabric-kafka
通过如下命令快速启动。
$ bash scripts/start_fabric.sh
或者
$ docker-compose -f docker-compose-2orgs-4peers.yaml up
注意输出日志中无错误信息。
此时,系统中包括 7 个容器。
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8683435422ca hyperledger/fabric-peer "bash -c 'while true;" 19 seconds ago Up 18 seconds 7050-7059/tcp fabric-cli f284c4dd26a0 hyperledger/fabric-peer "peer node start --pe" 22 seconds ago Up 19 seconds 7050/tcp, 0.0.0.0:7051->7051/tcp, 7052/tcp, 7054-7059/tcp, 0.0.0.0:7053->7053/tcp peer0.org1.example.com 95fa3614f82c hyperledger/fabric-ca "fabric-ca-server sta" 22 seconds ago Up 19 seconds 0.0.0.0:7054->7054/tcp fabric-ca 833ca0d8cf41 hyperledger/fabric-orderer "orderer" 22 seconds ago Up 19 seconds 0.0.0.0:7050->7050/tcp orderer.example.com cd21cfff8298 hyperledger/fabric-peer "peer node start --pe" 22 seconds ago Up 20 seconds 7050/tcp, 7052/tcp, 7054-7059/tcp, 0.0.0.0:9051->7051/tcp, 0.0.0.0:9053->7053/tcp peer0.org2.example.com 372b583b3059 hyperledger/fabric-peer "peer node start --pe" 22 seconds ago Up 20 seconds 7050/tcp, 7052/tcp, 7054-7059/tcp, 0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp peer1.org2.example.com 47ce30077276 hyperledger/fabric-peer "peer node start --pe" 22 seconds ago Up 20 seconds 7050/tcp, 7052/tcp, 7054-7059/tcp, 0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp peer1.org1.example.com
启动 fabric 网络后,可以进行 chaincode 操作,验证网络是否启动正常。
进入到 cli 容器里面,执行 initialize.sh 和 test_4peers.sh 脚本。
initialize.sh
test_4peers.sh
通过如下命令进入容器 cli 并执行测试脚本。
$ docker exec -it fabric-cli bash $ bash ./scripts/initialize.sh
注意输出日志无错误提示,最终返回结果应该为:
UTC [main] main -> INFO 00c Exiting..... ===================== Chaincode Instantiation on PEER2 on channel 'businesschannel' is successful ===================== ===================== All GOOD, initialization completed ===================== _____ _ _ ____ | ____| | \ | | | _ \ | _| | \| | | | | | | |___ | |\ | | |_| | |_____| |_| \_| |____/
之后同样是在 cli 容器里执行 test_4peers.sh 脚本
cli
$ bash ./scripts/test_4peers.sh
输出日志无错误提示,最终返回结果应该为:
Query Result: 80 UTC [main] main -> INFO 008 Exiting..... ===================== Query on PEER3 on channel 'businesschannel' is successful ===================== ===================== All GOOD, End-2-End execution completed ===================== _____ _ _ ____ | ____| | \ | | | _ \ | _| | \| | | | | | | |___ | |\ | | |_| | |_____| |_| \_| |____/
至此,整个网络启动并验证成功。
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8