2019年12月12日13:05:16
声明:从网络中学习整理实践而来。
1.介绍fabric
Fabric 是一个面向企业应用的区块链框架,基于 Fabric 的开发可以粗略分为几个层面:
1. 参与 Fabric 的底层开发,这主要是 fabric,fabric-ca 和 sdk 等核心组件。
2. 参与 Fabric 周边生态的开发,如支持如支持 fabric 的工具 explorer, composer 等。
3. 利用 fabric 平台开发应用,这就是利用 fabirc 提供的各种 sdk 来为应用服务(应用开发)
大部分企业会参与 2-3 的内容,以 3 为主来服务应用场景,以 2 为辅。因为现在除了区块链核心功能尚未完善外,对区块链的管理,运维,监控,测试,优化,调试等工具非常匮乏。企业将不得不面对自己开发一些工作。
#### Fabric 环境依赖
Fabric 官方推荐的开发环境是基于 docker 搭建的,使用 docker 搭建需要一下前置条件:
- docker 一一 Docker version 17.06.2-ce 或以上版本
- Docker Compose 一一 1.14 或以上版本
- Go 一一 1.10 或以上版本, Node.js 一一 8.9.x 或以上版本
- Python 一一主要是 python-pip
2.配置基本环境
与第三部分同步安装一致,比较难配置的是go环境,对于新手不太友好,尤其是项目要建在goroot下。
3.部署fabric V1.4版本
参照这篇教程
https://learnblockchain.cn/2018/11/21/fabric_introduction/
部署V1.4参照下面文章
https://learnblockchain.cn/2019/04/21/fabric-v1.4-install-demo/
3.1 介绍
主要环境是在Centos中部署(用的阿里服务器,下载github与docker快一点,本地下载速度太慢)
3.2 工具
3.2.1 git
下载源码仓库与运行脚本文件下载远程仓库使用
3.2.2 curl
利用url规则来进行文件传输的工具
3.2.3 epel-release
与yum
工具类似作用,下载仓库源
3.2.4 python-pip
python
的安装库的工具
3.2.5 golang
3.2.5.1 下载源码压缩包
下载压缩包。要下载Go二进制文件,请使用wget
或curl
:
wget https://dl.google.com/go/go1.13.linux-amd64.tar.gz
提取压缩包,使用tar
命令将压缩包提取到/usr/local
目录中:
sudo tar -C /usr/local -xzf go1.13.linux-amd64.tar.gz
3.2.5.2 配置环境变量
修改frofile
vim /etc/profile
修改如下:
export GOROOT=/usr/local/go
export GOPATH=/usr/local/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
3.2.5.3 测试go环境成功配置
要测试Go是否正确安装,我们将设置一个工作区并构建一个简单的“ Hello world”程序。
创建工作区目录,默认情况下,将工作区目录设置为$HOME/go
,要创建它,请输入:
mkdir ~/go
在工作区中,创建一个新目录src/hello
,创建一个简单的“ Hello World” Go文件。
mkdir -p ~/go/src/hello
然后在该目录中创建一个名为hello.go
〜/go/src/hello/hello.go
package main
import "fmt"
func main() {
fmt.Printf("Hello, World\n")
}
构建hello.go文件,切换到~/go/src/hello
目录并运行go build
:
cd ~/go/src/hello
go build
将生成名为hello
的可执行文件。
运行可执行文件,通过键入以下内容运行可执行文件:
./hello
Hello, World
如果看到上面的输出,则说明您已成功安装Go。
3.2.6 docker-ce
3.2.7 docker-compose
Compose 是 Docker 容器进行编排的工具,定义和运行多容器的应用,可以一条命令启动多个容器。HyperLedger Fabric需要用到docker-compose。
3.2.8 nodejs
yum安装
下载源码编译时间太长,等待不了
3.2.9 npm
3.2.10 gcc
GNU编译器家族,适合交差编译
验证是否成功
sudo docker-compose --version
3.3 下载Fabric及运行脚本下载docker
首先下载 Fabric 源码,我们在 go/src 目录下新建文件夹。
mkdir -p github.com/hyperledger
进入该文件夹执行:
git clone https://github.com/hyperledger/fabric.git (耐心等待)
完成后进入 fabric/scripts 文件夹,可以看到 bootstrap.sh 脚本,cat 该脚本可以看到 fabric 版本为 1.4.0:
执行 bootstrap.sh 脚本,自动进行 fabric 相关镜像的下载,耐心等待
./bootstrap.sh
执行完所有会用到的 Fabric docker 镜像都会下载下来了。
运行以下命令检查下载的镜像列表:
docker images
===> List out hyperledger docker images
hyperledger/fabric-tools latest 0403fd1c72c7 2 years ago 1.32GB
hyperledger/fabric-tools x86_64-1.0.0 0403fd1c72c7 2 years ago 1.32GB
hyperledger/fabric-couchdb latest 2fbdbf3ab945 2 years ago 1.48GB
hyperledger/fabric-couchdb x86_64-1.0.0 2fbdbf3ab945 2 years ago 1.48GB
hyperledger/fabric-kafka latest dbd3f94de4b5 2 years ago 1.3GB
hyperledger/fabric-kafka x86_64-1.0.0 dbd3f94de4b5 2 years ago 1.3GB
hyperledger/fabric-zookeeper latest e545dbf1c6af 2 years ago 1.31GB
hyperledger/fabric-zookeeper x86_64-1.0.0 e545dbf1c6af 2 years ago 1.31GB
hyperledger/fabric-orderer latest e317ca5638ba 2 years ago 179MB
hyperledger/fabric-orderer x86_64-1.0.0 e317ca5638ba 2 years ago 179MB
hyperledger/fabric-peer latest 6830dcd7b9b5 2 years ago 182MB
hyperledger/fabric-peer x86_64-1.0.0 6830dcd7b9b5 2 years ago 182MB
hyperledger/fabric-javaenv latest 8948126f0935 2 years ago 1.42GB
hyperledger/fabric-javaenv x86_64-1.0.0 8948126f0935 2 years ago 1.42GB
hyperledger/fabric-ccenv latest 7182c260a5ca 2 years ago 1.29GB
hyperledger/fabric-ccenv x86_64-1.0.0 7182c260a5ca 2 years ago 1.29GB
hyperledger/fabric-ca latest a15c59ecda5b 2 years ago 238MB
hyperledger/fabric-ca x86_64-1.0.0 a15c59ecda5b 2 years ago 238MB
cat boostrap.sh
cat boostrap.sh
#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# if version not passed in, default to latest released version
VERSION=1.4.4
# if ca version not passed in, default to latest released version
CA_VERSION=1.4.4
# current version of thirdparty images (couchdb, kafka and zookeeper) released
THIRDPARTY_IMAGE_VERSION=0.4.18
ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')")
MARCH=$(uname -m)
printHelp() {
echo "Usage: bootstrap.sh [version [ca_version [thirdparty_version]]] [options]"
echo
echo "options:"
echo "-h : this help"
echo "-d : bypass docker image download"
echo "-s : bypass fabric-samples repo clone"
echo "-b : bypass download of platform-specific binaries"
echo
echo "e.g. bootstrap.sh 1.4.4 -s"
echo "would download docker images and binaries for version 1.4.4"
}
# dockerPull() pulls docker images from fabric and chaincode repositories
# note, if a docker image doesn't exist for a requested release, it will simply
# be skipped, since this script doesn't terminate upon errors.
dockerPull() {
image_tag=$1
shift
while [[ $# -gt 0 ]]
do
image_name="$1"
echo "====> hyperledger/fabric-$image_name:$image_tag"
docker pull "hyperledger/fabric-$image_name:$image_tag"
docker tag "hyperledger/fabric-$image_name:$image_tag" "hyperledger/fabric-$image_name"
shift
done
}
cloneSamplesRepo() {
# clone (if needed) hyperledger/fabric-samples and checkout corresponding
# version to the binaries and docker images to be downloaded
if [ -d first-network ]; then
# if we are in the fabric-samples repo, checkout corresponding version
echo "===> Checking out v${VERSION} of hyperledger/fabric-samples"
git checkout v${VERSION}
elif [ -d fabric-samples ]; then
# if fabric-samples repo already cloned and in current directory,
# cd fabric-samples and checkout corresponding version
echo "===> Checking out v${VERSION} of hyperledger/fabric-samples"
cd fabric-samples && git checkout v${VERSION}
else
echo "===> Cloning hyperledger/fabric-samples repo and checkout v${VERSION}"
git clone -b master https://github.com/hyperledger/fabric-samples.git && cd fabric-samples && git checkout v${VERSION}
fi
}
# This will download the .tar.gz
download() {
local BINARY_FILE=$1
local URL=$2
echo "===> Downloading: " "${URL}"
curl -s -L "${URL}" | tar xz || rc=$?
if [ -n "$rc" ]; then
echo "==> There was an error downloading the binary file."
return 22
else
echo "==> Done."
fi
}
pullBinaries() {
echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries"
download "${BINARY_FILE}" "https://github.com/hyperledger/fabric/releases/download/v${VERSION}/${BINARY_FILE}"
if [ $? -eq 22 ]; then
echo
echo "------> ${FABRIC_TAG} platform specific fabric binary is not available to download <----"
echo
exit
fi
echo "===> Downloading version ${CA_TAG} platform specific fabric-ca-client binary"
download "${CA_BINARY_FILE}" "https://github.com/hyperledger/fabric-ca/releases/download/v${VERSION}/${CA_BINARY_FILE}"
if [ $? -eq 22 ]; then
echo
echo "------> ${CA_TAG} fabric-ca-client binary is not available to download (Available from 1.1.0-rc1) <----"
echo
exit
fi
}
pullDockerImages() {
command -v docker >& /dev/null
NODOCKER=$?
if [ "${NODOCKER}" == 0 ]; then
FABRIC_IMAGES=(peer orderer ccenv tools)
case "$VERSION" in
1.*)
FABRIC_IMAGES+=(javaenv)
shift
;;
2.*)
FABRIC_IMAGES+=(nodeenv baseos javaenv)
shift
;;
esac
echo "FABRIC_IMAGES:" "${FABRIC_IMAGES[@]}"
echo "===> Pulling fabric Images"
dockerPull "${FABRIC_TAG}" "${FABRIC_IMAGES[@]}"
echo "===> Pulling fabric ca Image"
CA_IMAGE=(ca)
dockerPull "${CA_TAG}" "${CA_IMAGE[@]}"
echo "===> Pulling thirdparty docker images"
THIRDPARTY_IMAGES=(zookeeper kafka couchdb)
dockerPull "${THIRDPARTY_TAG}" "${THIRDPARTY_IMAGES[@]}"
echo
echo "===> List out hyperledger docker images"
docker images | grep hyperledger
else
echo "========================================================="
echo "Docker not installed, bypassing download of Fabric images"
echo "========================================================="
fi
}
DOCKER=true
SAMPLES=true
BINARIES=true
# Parse commandline args pull out
# version and/or ca-version strings first
if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then
VERSION=$1;shift
if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then
CA_VERSION=$1;shift
if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then
THIRDPARTY_IMAGE_VERSION=$1;shift
fi
fi
fi
# prior to 1.2.0 architecture was determined by uname -m
if [[ $VERSION =~ ^1\.[0-1]\.* ]]; then
export FABRIC_TAG=${MARCH}-${VERSION}
export CA_TAG=${MARCH}-${CA_VERSION}
export THIRDPARTY_TAG=${MARCH}-${THIRDPARTY_IMAGE_VERSION}
else
# starting with 1.2.0, multi-arch images will be default
: "${CA_TAG:="$CA_VERSION"}"
: "${FABRIC_TAG:="$VERSION"}"
: "${THIRDPARTY_TAG:="$THIRDPARTY_IMAGE_VERSION"}"
fi
BINARY_FILE=hyperledger-fabric-${ARCH}-${VERSION}.tar.gz
CA_BINARY_FILE=hyperledger-fabric-ca-${ARCH}-${CA_VERSION}.tar.gz
# then parse opts
while getopts "h?dsb" opt; do
case "$opt" in
h|\?)
printHelp
exit 0
;;
d) DOCKER=false
;;
s) SAMPLES=false
;;
b) BINARIES=false
;;
esac
done
if [ "$SAMPLES" == "true" ]; then
echo
echo "Clone hyperledger/fabric-samples repo"
echo
cloneSamplesRepo
fi
if [ "$BINARIES" == "true" ]; then
echo
echo "Pull Hyperledger Fabric binaries"
echo
pullBinaries
fi
if [ "$DOCKER" == "true" ]; then
echo
echo "Pull Hyperledger Fabric docker images"
echo
pullDockerImages
fi
3.4 运行实例代码
通过 Fabric-samples 提供的 BYFN (build your first network) 构建网络。
./byfn.sh -m generate -c jackychannel(自定义名字)
其中byfn.sh为启动这个网络的启动脚本,启动脚本中除建立一个包含4个节点和1个Order service的网络外,还会启动一个容器用来执行脚本在channel中加入节点,部署和初始化chaincode,以及在部署的chaincode上执行交易。
默认channel名称为mychannel,脚本程序会给网络实例生成数字证书和密钥;生成genesis block用来启动ordering service;一些用来配置channel的配置交易
-o <consensus-type> - the consensus-type of the ordering service: solo (default), kafka, or etcdraft
+ res=0
+ set +x
#################################################################
####### Generating anchor peer update for Org1MSP ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID jackychannel -asOrg Org1MSP
2019-12-05 09:46:26.602 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-12-05 09:46:26.735 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-12-05 09:46:26.869 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-12-05 09:46:26.869 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-12-05 09:46:26.869 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2019-12-05 09:46:26.870 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
+ res=0
+ set +x
#################################################################
####### Generating anchor peer update for Org2MSP ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID jackychannel -asOrg Org2MSP
2019-12-05 09:46:26.906 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-12-05 09:46:27.037 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-12-05 09:46:27.171 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-12-05 09:46:27.171 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-12-05 09:46:27.171 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2019-12-05 09:46:27.172 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
+ res=0
+ set +x
启动网络:
./byfn.sh -m up -c jackychannel
启动后如下:
+ res=0
+ set +x
2019-12-03 01:10:53.955 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'jackychannel' =====================
Installing chaincode on peer1.org2...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
2019-12-03 01:10:54.025 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2019-12-03 01:10:54.025 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2019-12-03 01:10:54.282 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
+ res=0
+ set +x
===================== Chaincode is installed on peer1.org2 =====================
Querying chaincode on peer1.org2...
===================== Querying on peer1.org2 on channel 'jackychannel'... =====================
+ peer chaincode query -C jackychannel -n mycc -c '{"Args":["query","a"]}'
Attempting to Query peer1.org2 ...3 secs
+ res=0
+ set +x
90
===================== Query successful on peer1.org2 on channel 'jackychannel' =====================
========= All GOOD, BYFN execution completed ===========
_____ _ _ ____
| ____| | \ | | | _ \
| _| | \| | | | | |
| |___ | |\ | | |_| |
|_____| |_| \_| |____/
当最终出现了All GOOD, BYFN execution completed
就表示已经成功了。
使用top
命令可以查看到会有4个peer
节点进程
#top
31923 root 20 0 797956 102148 15476 S 1.3 5.4 0:26.02 peer
31948 root 20 0 865864 106228 16468 S 1.3 5.6 0:27.58 peer
32029 root 20 0 865864 72788 16252 S 1.3 3.9 0:27.32 peer
32046 root 20 0 865864 106540 16364 S 1.3 5.7 0:27.60 peer
关闭实例进程:
注: 关闭命令:./byfn.sh -m down
启动网络服务后会启动排序服务节点、4 个 Peer 节点,以及 1 个命令行容器 cli。
4.部署fabric V1.0.0版本
4.1 下载源码
cd ~/go/src/github.com/hyperledger
git clone https://github.com/hyperledger/fabric.git
cd ~/go/src/github.com/hyperledger/fabric
必须切换分支到v1.0.0
git checkout -b v1.0.0
4.2 e2e_cli样例实例
e2e_cli是fabric下面的一个独立样例:与e2e_cli同级的还有
进入e2e项目目录:
cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/
下载fabric相关镜像:
source download-dockerimages.sh -c x86_64-1.0.0 -f x86_64-1.0.0
===> List out hyperledger docker images
hyperledger/fabric-tools latest 0403fd1c72c7 2 years ago 1.32GB
hyperledger/fabric-tools x86_64-1.0.0 0403fd1c72c7 2 years ago 1.32GB
hyperledger/fabric-couchdb latest 2fbdbf3ab945 2 years ago 1.48GB
hyperledger/fabric-couchdb x86_64-1.0.0 2fbdbf3ab945 2 years ago 1.48GB
hyperledger/fabric-kafka latest dbd3f94de4b5 2 years ago 1.3GB
hyperledger/fabric-kafka x86_64-1.0.0 dbd3f94de4b5 2 years ago 1.3GB
hyperledger/fabric-zookeeper latest e545dbf1c6af 2 years ago 1.31GB
hyperledger/fabric-zookeeper x86_64-1.0.0 e545dbf1c6af 2 years ago 1.31GB
hyperledger/fabric-orderer latest e317ca5638ba 2 years ago 179MB
hyperledger/fabric-orderer x86_64-1.0.0 e317ca5638ba 2 years ago 179MB
hyperledger/fabric-peer latest 6830dcd7b9b5 2 years ago 182MB
hyperledger/fabric-peer x86_64-1.0.0 6830dcd7b9b5 2 years ago 182MB
hyperledger/fabric-javaenv latest 8948126f0935 2 years ago 1.42GB
hyperledger/fabric-javaenv x86_64-1.0.0 8948126f0935 2 years ago 1.42GB
hyperledger/fabric-ccenv latest 7182c260a5ca 2 years ago 1.29GB
hyperledger/fabric-ccenv x86_64-1.0.0 7182c260a5ca 2 years ago 1.29GB
hyperledger/fabric-ca latest a15c59ecda5b 2 years ago 238MB
hyperledger/fabric-ca x86_64-1.0.0 a15c59ecda5b 2 years ago 238MB
4.3 运行脚本文件
./network_setup.sh up
自己没能成功,卡在了不知名的状态
root@iZuf6cc8lqocb36rk8u38kZ:~/go/src/github.com/hyperledger/fabric/examples/e2e_cli# ./network_setup.sh up
setting to default channel 'mychannel'
mychannel
Using cryptogen -> /root/go/src/github.com/hyperledger/fabric/examples/e2e_cli/../../release/linux-amd64/bin/cryptogen
##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
org1.example.com
org2.example.com
Using configtxgen -> /root/go/src/github.com/hyperledger/fabric/examples/e2e_cli/../../release/linux-amd64/bin/configtxgen
##########################################################
######### Generating Orderer Genesis block ##############
##########################################################
2019-12-12 14:24:47.645 CST [common/configtx/tool] main -> INFO 001 Loading configuration
2019-12-12 14:24:47.663 CST [common/configtx/tool] doOutputBlock -> INFO 002 Generating genesis block
2019-12-12 14:24:47.664 CST [common/configtx/tool] doOutputBlock -> INFO 003 Writing genesis block
#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
2019-12-12 14:24:47.672 CST [common/configtx/tool] main -> INFO 001 Loading configuration
2019-12-12 14:24:47.676 CST [common/configtx/tool] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
2019-12-12 14:24:47.677 CST [common/configtx/tool] doOutputChannelCreateTx -> INFO 003 Writing new channel tx
#################################################################
####### Generating anchor peer update for Org1MSP ##########
#################################################################
2019-12-12 14:24:47.686 CST [common/configtx/tool] main -> INFO 001 Loading configuration
2019-12-12 14:24:47.690 CST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2019-12-12 14:24:47.690 CST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
#################################################################
####### Generating anchor peer update for Org2MSP ##########
#################################################################
2019-12-12 14:24:47.699 CST [common/configtx/tool] main -> INFO 001 Loading configuration
2019-12-12 14:24:47.703 CST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2019-12-12 14:24:47.703 CST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
Creating network "e2e_cli_default" with the default driver
Creating peer1.org1.example.com ... done
Creating peer1.org2.example.com ... done
Creating orderer.example.com ... done
Creating peer0.org2.example.com ... done
Creating peer0.org1.example.com ... done
Creating cli ... done
____ _____ _ ____ _____ _____ ____ _____
/ ___| |_ _| / \ | _ \ |_ _| | ____| |___ \ | ____|
\___ \ | | / _ \ | |_) | | | _____ | _| __) | | _|
___) | | | / ___ \ | _ < | | |_____| | |___ / __/ | |___
|____/ |_| /_/ \_\ |_| \_\ |_| |_____| |_____| |_____|
Channel name : mychannel
Creating channel...
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org1MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=DEBUG
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
2019-12-12 06:24:53.412 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2019-12-12 06:24:53.412 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2019-12-12 06:24:53.422 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2019-12-12 06:24:53.423 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
2019-12-12 06:24:53.423 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
2019-12-12 06:24:53.423 UTC [msp] GetLocalMSP -> DEBU 006 Returning existing local MSP
2019-12-12 06:24:53.423 UTC [msp] GetDefaultSigningIdentity -> DEBU 007 Obtaining default signing identity
2019-12-12 06:24:53.423 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0A8C060A074F7267314D53501280062D...53616D706C65436F6E736F727469756D
2019-12-12 06:24:53.423 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: 93357E31F0E7688ED33D2599E82FD377034CBF858D8790071F0627989AF1F1A6
2019-12-12 06:24:53.423 UTC [msp] GetLocalMSP -> DEBU 00a Returning existing local MSP
2019-12-12 06:24:53.423 UTC [msp] GetDefaultSigningIdentity -> DEBU 00b Obtaining default signing identity
2019-12-12 06:24:53.423 UTC [msp] GetLocalMSP -> DEBU 00c Returning existing local MSP
2019-12-12 06:24:53.423 UTC [msp] GetDefaultSigningIdentity -> DEBU 00d Obtaining default signing identity
2019-12-12 06:24:53.423 UTC [msp/identity] Sign -> DEBU 00e Sign: plaintext: 0AC3060A1508021A0608B5BAC7EF0522...54B8942CBF5580B262708931E87C3371
2019-12-12 06:24:53.423 UTC [msp/identity] Sign -> DEBU 00f Sign: digest: 8D82F410AC0EAB416222EDCF9C1E2906B6609686590F1A2E44DBD3221294DF1D
2019-12-12 06:24:53.618 UTC [msp] GetLocalMSP -> DEBU 010 Returning existing local MSP
2019-12-12 06:24:53.618 UTC [msp] GetDefaultSigningIdentity -> DEBU 011 Obtaining default signing identity
2019-12-12 06:24:53.618 UTC [msp] GetLocalMSP -> DEBU 012 Returning existing local MSP
2019-12-12 06:24:53.618 UTC [msp] GetDefaultSigningIdentity -> DEBU 013 Obtaining default signing identity
2019-12-12 06:24:53.618 UTC [msp/identity] Sign -> DEBU 014 Sign: plaintext: 0AC3060A1508021A0608B5BAC7EF0522...BF2EB54E312812080A021A0012021A00
2019-12-12 06:24:53.618 UTC [msp/identity] Sign -> DEBU 015 Sign: digest: 89AAC240731087E491A456B73413ADBE61DC0B66AE5C2150C42D64B8B340A578
2019-12-12 06:24:53.668 UTC [channelCmd] readBlock -> DEBU 016 Got status:*orderer.DeliverResponse_Status
2019-12-12 06:24:53.669 UTC [msp] GetLocalMSP -> DEBU 017 Returning existing local MSP
2019-12-12 06:24:53.669 UTC [msp] GetDefaultSigningIdentity -> DEBU 018 Obtaining default signing identity
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x63 pc=0x7fbadc9fb259]
runtime stack:
runtime.throw(0xdc37a7, 0x2a)
/opt/go/src/runtime/panic.go:566 +0x95
runtime.sigpanic()
/opt/go/src/runtime/sigpanic_unix.go:12 +0x2cc
goroutine 34 [syscall, locked to thread]:
runtime.cgocall(0xb08d50, 0xc420020df8, 0xc400000000)
/opt/go/src/runtime/cgocall.go:131 +0x110 fp=0xc420020db0 sp=0xc420020d70
net._C2func_getaddrinfo(0x7fbad00008c0, 0x0, 0xc420358ab0, 0xc420028860, 0x0, 0x0, 0x0)
??:0 +0x68 fp=0xc420020df8 sp=0xc420020db0
net.cgoLookupIPCNAME(0x7ffcc389ca83, 0x13, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/opt/go/src/net/cgo_unix.go:146 +0x37c fp=0xc420020f18 sp=0xc420020df8
net.cgoIPLookup(0xc42036a120, 0x7ffcc389ca83, 0x13)
/opt/go/src/net/cgo_unix.go:198 +0x4d fp=0xc420020fa8 sp=0xc420020f18
runtime.goexit()
/opt/go/src/runtime/asm_amd64.s:2086 +0x1 fp=0xc420020fb0 sp=0xc420020fa8
created by net.cgoLookupIP
/opt/go/src/net/cgo_unix.go:208 +0xb4
goroutine 1 [select]:
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.(*addrConn).wait(0xc4200d1340, 0x7fbadd41ea10, 0xc4203589c0, 0xc420130100, 0x8006f0, 0x7fbadd41ea10, 0xc4203589c0, 0x0)
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/clientconn.go:1032 +0x183
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.(*ClientConn).getTransport(0xc420199ba0, 0x7fbadd41ea10, 0xc4203589c0, 0xc420358900, 0x7fbadd41ea10, 0xc420358990, 0x19, 0x0, 0xc42013f900)
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/clientconn.go:724 +0x2f7
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.newClientStream(0x7fbadd41ea10, 0xc4203589c0, 0x13e1f40, 0xc420199ba0, 0xdb7f76, 0x20, 0x0, 0x0, 0x0, 0x0, ...)
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/stream.go:189 +0x599
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.NewClientStream(0x7fbadd41e990, 0xc420012290, 0x13e1f40, 0xc420199ba0, 0xdb7f76, 0x20, 0x0, 0x0, 0x0, 0x18, ...)
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/stream.go:105 +0x162
github.com/hyperledger/fabric/protos/orderer.(*atomicBroadcastClient).Deliver(0xc420028850, 0x7fbadd41e990, 0xc420012290, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc4202118c0, 0xbe4ab0)
/opt/gopath/src/github.com/hyperledger/fabric/protos/orderer/ab.pb.go:499 +0xba
github.com/hyperledger/fabric/peer/channel.InitCmdFactory(0xc420300100, 0x0, 0x0, 0x13ee140)
/opt/gopath/src/github.com/hyperledger/fabric/peer/channel/channel.go:179 +0x2c0
github.com/hyperledger/fabric/peer/channel.getGenesisBlock(0xc4202e1360, 0x0, 0x0, 0x0)
/opt/gopath/src/github.com/hyperledger/fabric/peer/channel/deliverclient.go:141 +0x11c
github.com/hyperledger/fabric/peer/channel.executeCreate(0xc4202e1360, 0xc4202e1360, 0x0)
/opt/gopath/src/github.com/hyperledger/fabric/peer/channel/create.go:183 +0x50
github.com/hyperledger/fabric/peer/channel.create(0xc42020e6c0, 0xc42020d4a0, 0x1, 0xa, 0xc4202e1360, 0xd9d943, 0x5)
/opt/gopath/src/github.com/hyperledger/fabric/peer/channel/create.go:213 +0x45
github.com/hyperledger/fabric/peer/channel.createCmd.func1(0xc42020e6c0, 0xc42020d4a0, 0x1, 0xa, 0x0, 0x0)
/opt/gopath/src/github.com/hyperledger/fabric/peer/channel/create.go:59 +0x52
github.com/hyperledger/fabric/vendor/github.com/spf13/cobra.(*Command).execute(0xc42020e6c0, 0xc42020d360, 0xa, 0xa, 0xc42020e6c0, 0xc42020d360)
/opt/gopath/src/github.com/hyperledger/fabric/vendor/github.com/spf13/cobra/command.go:599 +0x234
github.com/hyperledger/fabric/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x13e58c0, 0xf, 0xc420010035, 0x7)
/opt/gopath/src/github.com/hyperledger/fabric/vendor/github.com/spf13/cobra/command.go:689 +0x367
github.com/hyperledger/fabric/vendor/github.com/spf13/cobra.(*Command).Execute(0x13e58c0, 0x7d, 0xc420010035)
/opt/gopath/src/github.com/hyperledger/fabric/vendor/github.com/spf13/cobra/command.go:648 +0x2b
main.main()
/opt/gopath/src/github.com/hyperledger/fabric/peer/main.go:118 +0x54e
goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/opt/go/src/runtime/asm_amd64.s:2086 +0x1
goroutine 33 [select]:
net.cgoLookupIP(0x13fc8c0, 0xc42036a060, 0x7ffcc389ca83, 0x13, 0xc420118780, 0xc420027e68, 0x0, 0x0, 0x0, 0x0)
/opt/go/src/net/cgo_unix.go:209 +0x2f5
net.lookupIP(0x13fc8c0, 0xc42036a060, 0x7ffcc389ca83, 0x13, 0xc4202f9440, 0x0, 0x0, 0x0, 0x40005)
/opt/go/src/net/lookup_unix.go:70 +0xf9
net.glob..func11(0x13fc8c0, 0xc42036a060, 0xe2abc0, 0x7ffcc389ca83, 0x13, 0xc420027ec8, 0x71c6a9, 0xc420027f08, 0xc420027f18, 0x455cc0)
/opt/go/src/net/hook.go:19 +0x52
net.lookupIPContext.func1(0xc420199ba0, 0x7ffcc389ca83, 0x18, 0x0)
/opt/go/src/net/lookup.go:119 +0x5c
internal/singleflight.(*Group).doCall(0x1419790, 0xc420354a50, 0x7ffcc389ca83, 0x13, 0xc420358a50)
/opt/go/src/internal/singleflight/singleflight.go:93 +0x3c
created by internal/singleflight.(*Group).DoChan
/opt/go/src/internal/singleflight/singleflight.go:86 +0x339
goroutine 10 [syscall]:
os/signal.signal_recv(0x0)
/opt/go/src/runtime/sigqueue.go:116 +0x157
os/signal.loop()
/opt/go/src/os/signal/signal_unix.go:22 +0x22
created by os/signal.init.1
/opt/go/src/os/signal/signal_unix.go:28 +0x41
goroutine 32 [select]:
net.lookupIPContext(0x13fc8c0, 0xc42036a060, 0x7ffcc389ca83, 0x13, 0x0, 0x0, 0x0, 0x0, 0x19441901)
/opt/go/src/net/lookup.go:122 +0x7bc
net.internetAddrList(0x13fc8c0, 0xc42036a060, 0xd9cd17, 0x3, 0x7ffcc389ca83, 0x18, 0x0, 0x0, 0x0, 0x13fc8c0, ...)
/opt/go/src/net/ipsock.go:241 +0x5e0
net.resolveAddrList(0x13fc8c0, 0xc42036a060, 0xd9d317, 0x4, 0xd9cd17, 0x3, 0x7ffcc389ca83, 0x18, 0x0, 0x0, ...)
/opt/go/src/net/dial.go:179 +0x106
net.(*Dialer).DialContext(0xc4200496c8, 0x13fc8c0, 0xc42036a060, 0xd9cd17, 0x3, 0x7ffcc389ca83, 0x18, 0x0, 0x0, 0x0, ...)
/opt/go/src/net/dial.go:329 +0x238
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.dialContext(0x13fc8c0, 0xc42036a060, 0xd9cd17, 0x3, 0x7ffcc389ca83, 0x18, 0x0, 0x0, 0xc420106e10, 0xc420339780)
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/go17.go:53 +0xaa
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.DialContext.func1(0x7fbadd41ea50, 0xc42036a060, 0x7ffcc389ca83, 0x18, 0x1, 0x0, 0x13ee140, 0xc420127e50)
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/clientconn.go:341 +0x86
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.newProxyDialer.func1(0x7fbadd41ea50, 0xc42036a060, 0x7ffcc389ca83, 0x18, 0x13, 0x7fbadd41ff60, 0x0, 0x0)
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/proxy.go:136 +0x143
github.com/hyperledger/fabric/vendor/google.golang.org/grpc/transport.dial(0x7fbadd41ea50, 0xc42036a060, 0xc4203664c0, 0x7ffcc389ca83, 0x18, 0x410a5e, 0xc42032cfa0, 0xa0, 0x98)
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/transport/http2_client.go:135 +0x5a
github.com/hyperledger/fabric/vendor/google.golang.org/grpc/transport.newHTTP2Client(0x7fbadd41ea50, 0xc42036a060, 0x7ffcc389ca83, 0x18, 0x0, 0x0, 0xda8cf6, 0x11, 0x0, 0x0, ...)
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/transport/http2_client.go:173 +0xbf
github.com/hyperledger/fabric/vendor/google.golang.org/grpc/transport.NewClientTransport(0x7fbadd41ea50, 0xc42036a060, 0x7ffcc389ca83, 0x18, 0x0, 0x0, 0xda8cf6, 0x11, 0x0, 0x0, ...)
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/transport/transport.go:463 +0xae
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.(*addrConn).resetTransport(0xc4200d1340, 0xc420335400, 0x70a61c, 0x0)
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/clientconn.go:876 +0x282
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.(*ClientConn).resetAddrConn.func1(0xc4200d1340)
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/clientconn.go:648 +0x34
created by github.com/hyperledger/fabric/vendor/google.golang.org/grpc.(*ClientConn).resetAddrConn
/opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/clientconn.go:657 +0x756
!!!!!!!!!!!!!!! Channel creation failed !!!!!!!!!!!!!!!!
================== ERROR !!! FAILED to execute End-2-End Scenario ==================
4.4 运行另一个脚本试试
cd ~/go/src/github.com/hyperledger/fabric/scripts
./bootstrap-1.0.0.sh
跟v1.4版本一致操作
5. 细节问题
1.如何配置git
vim /etc/hosts
在末尾添加:
151.101.113.194 github.global.ssl.fastly.net
192.30.253.112 github.com
52.216.227.168 github-cloud.s3.amazonaws.com
最后:
source /etc/hosts
2.如何解决阿里云sudo: unable to resolve host xxx
虽然sudo 还是可以正常执行, 但是警告讯息每次都出来,而这只是机器在反解上的问题, 所以就直接从/etc/hosts 设定, 让abc(hostname) 可以解回127.0.0.1 的IP 即可.
解决方法
vi /etc/hosts 第一行信息如下: 127.0.0.1 localhost
在127.0.0.1 localhost 后面加上主机名称(hostname) 即可, /etc/hosts 内容修改成如下:
第一种方法:直接将hostname(abc)追加到后面
127.0.0.1 localhost abc #要保证这个名字与 /etc/hostname中的主机名一致才有效
第二种方法:可以分开写
127.0.0.1 localhost
127.0.0.1 abc
这样设完后, 使用sudo 就不会再有那个提示信息了。
3.docker镜像有关问题
如果失败了就可能手动删除docker。
暂停运行的容器
sudo docker stop $(sudo docker ps -aq)
删除容器
sudo docker rm $(sudo docker ps -aq)
强制删除镜像——比较危险做法,需要重新下载
docker rmi -f $(docker images -q)
4.指定安装nodejs版本
npm install -g n
n 8.15.0 stable
➜ caliper git:(master) n 8.15.0 stable
installing : node-v8.15.0
mkdir : /usr/local/n/versions/node/8.15.0
fetch : https://nodejs.org/dist/v8.15.0/node-v8.15.0-linux-x64.tar.gz
installed : v8.15.0 (with npm 6.4.1)
Note: the node command changed location and the old location may be remembered in your current shell.
old : /usr/bin/node
new : /usr/local/bin/node
To reset the command location hash either start a new shell, or execute PATH="$PATH"
vim /etc/profile
source /etc/profile