Hyperledger Fabric v1.1 单机多节点集群环境搭建(包括e2e_cli 例子)

Fabric v1.1

1.环境安装

1).安装go 1.9.x
下载地址
http://golang.org/dl/

配置环境

#go的安装根目录
export GOROOT=/usr/local/go
#go的工作路径根目录
export GOPATH=/opt/goroot

2).安装docker 17.06.2-ce or greater
官网https://docs.docker.com/install/linux/docker-ce/centos/#set-up-the-repository
卸载原来的版本

sudo yum remove docker
docker-client
docker-client-latest
docker-common
docker-latest
docker-latest-logrotate
docker-logrotate
docker-selinux
docker-engine-selinux
docker-engine

安装依赖包

sudo yum install -y yum-utils
device-mapper-persistent-data
lvm2

设置稳定库

sudo yum-config-manager
–add-repo
https://download.docker.com/linux/centos/docker-ce.repo
安装docker-ce
sudo yum install docker-ce

如果需要某个特定版本,安装如下:
列出所有可安装的版本

yum list docker-ce --showduplicates | sort -r

安装

sudo yum install docker-ce-
v1.1需要 docker-ce-17.09.1.ce或更高版本
sudo yum install docker-ce-17.09.1.ce

启动 docker

systemctl start docker

设置docker 开机自启

chkconfig docker on

启动docker,错误解决

docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit) since Wed 2018-07-18 04:12:40 EDT; 15s ago
Docs: https://docs.docker.com
Process: 7850 ExecStart=/usr/bin/dockerd (code=exited, status=1/FAILURE)
Main PID: 7850 (code=exited, status=1/FAILURE)

Jul 18 04:12:40 vmnode1 systemd[1]: Failed to start Docker Application Container Engine.
Jul 18 04:12:40 vmnode1 systemd[1]: Unit docker.service entered failed state.
Jul 18 04:12:40 vmnode1 systemd[1]: docker.service failed.
Jul 18 04:12:40 vmnode1 systemd[1]: docker.service holdoff time over, scheduling restart.
Jul 18 04:12:40 vmnode1 systemd[1]: start request repeated too quickly for docker.service
Jul 18 04:12:40 vmnode1 systemd[1]: Failed to start Docker Application Container Engine.
Jul 18 04:12:40 vmnode1 systemd[1]: Unit docker.service entered failed state.
Jul 18 04:12:40 vmnode1 systemd[1]: docker.service failed.

解决方法

vim /etc/docker/daemon.json
{
“graph”: “/mnt/docker-data”,
“storage-driver”: “overlay”
}
systemctl restart docker

3).安装docker-compose

curl -L https://github.com/docker/compose/releases/download/1.15.0/docker-compose-uname -s-uname -m > >/usr/local/bin/docker-composechmod +x /usr/local/bin/docker-compose

cp /usr/local/bin/docker-compose /usr/bin

2.Fabric源码及镜像文件

1).下载Fabric源码 v1.1

mkdir -p /opt/goroot/src/github.com/hyperledger/

cd /opt/goroot/src/github.com/hyperledger/

git clone -b v1.1.0 http://github.com/hyperledger/fabric
#切换分支到1.1版本
git checkout -b v1.1

2).下载相应的二进制文件和镜像文件

cd scripts

修改bootstrap.sh如下:

export VERSION=${1:-1.1.0}
export THIRDPARTY_IMAGE_VERSION=1.1.0

执行bootstrap.sh

./bootstrap.sh

执行这步得到以下镜像

REPOSITORY TAG
hyperledger/fabric-ca latest
hyperledger/fabric-ca x86_64-1.1.0
hyperledger/fabric-tools latest
hyperledger/fabric-tools x86_64-1.1.0
hyperledger/fabric-orderer latest
hyperledger/fabric-orderer x86_64-1.1.0
hyperledger/fabric-peer latest
hyperledger/fabric-peer x86_64-1.1.0
hyperledger/fabric-javaenv latest
hyperledger/fabric-javaenv x86_64-1.1.0
hyperledger/fabric-ccenv latest
hyperledger/fabric-ccenv x86_64-1.1.0
hyperledger/fabric-zookeeper latest
hyperledger/fabric-kafka latest
hyperledger/fabric-couchdb latest

并且在当前目前下会得到/bin文件下

configtxgen configtxlator cryptogen fabric-ca-client get-byfn.sh get-docker-images.sh orderer peer

e2e_cli的例子中需要把bin文件放到/fabric/release/linux-amd64/ 目錄下

3.启动例子中的e2e_cli测试环境

cd examples/e2e_cli

修改base下的peer-base.yaml

- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=e2e_cli_default

这里CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE的设置为 当前文件夹名称_default

bash network_setup.sh up

1.e2e_cli启动过程中出现:Error: Error endorsing chaincode: rpc error: code = Unknown desc = timeout expired while starting chaincode fabcar

关掉所有容器

docker stop $(docker ps -a -q)

删除所有容器

docker rm $(docker ps -a -q)

2.删除红框中的容器docker rmi IMAGEID2.e2e_cli启动中出现:ERROR:Encountered errors while bringing up the projectERROR!!!Unable to pull the images

删除所有运行的容器

关掉所有容器

docker stop $(docker ps -a -q)

删除所有容器

docker rm $(docker ps -a -q)

3.e2e_cli启动中出现:Error: Error endorsing chaincode: rpc error: code = Unknown desc = Error starting container: API error (404): {“message”:“network e2ecli_default not found”}

进入目录

cd /opt/goroot/src/github.com/hyperledger/fabric/example/e2e_cli

修改./e2e_cli/base/下的 peer-base.yaml

修改下面一行就行了

CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=e2e_cli_default

4.e2e_cli启动中出现:CRIT 004 Error on outputBlock:Error writing genesis block:open ./channel-artifacts/get:is a directory

原因是没有正确生成genesis.block 所以docker在挂载文件时,会自动生成一个genesis.block文件.

直接删除e2e_cli下的channel-artifacts里的genesis.block,重新生成这个文件

5.Docker挂载主机目录,访问相应的文件出现Premission denied的权限

在主机中修改/soft目录的安全性文档,假设要挂载的文件是/soft

chcon -Rt svirt_sandbox_file_t /soft

注意:每次重新执行bash network_setup.sh up 前
需要做以下几句
删除所有容器删除常见问题1中的三个镜像
删除e2e_cli下的crypto-config
删除e2e_cli下的channel-artifacts里的所有文件

出现:

2019-07-24 12:37:25.992 UTC [channelCmd] InitCmdFactory -> INFO 109 Endorser and orderer connectio initialized
Error: timeout waiting for channel creation

把orderer改为solo模式

你可能感兴趣的:(区块链)