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
top命令:顯示linux進程信息
關閉實例進程:
注: 關閉命令:./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/Admin@org1.example.com/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