fabric2.X环境部署教程

总结为几个步骤:

二进制和CA文件下载源地址链接(经常打不开且下载极慢):
二进制
CA
二进制和CA文件下载链接(本人上载了部分资源)mac选择下载darwin版本、linux选择linux版本即可:
https://download.csdn.net/user/weixin_44336181/uploads
一、Prerequisite
1、安装Git
2、安装cURL
3、安装docker
4、安装JQ(可选不安装,仅在与通道配置事务相关的教程中需要)

MAC版:

1、安装Homebrew

	$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
	$ brew --version
	Homebrew 2.5.2

2、Git

$ brew install git
$ git --version
git version 2.23.0

3、cURL

$ brew install curl
$ curl --version
curl 7.64.1 (x86_64-apple-darwin19.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.39.2
Release-Date: 2019-03-27

4、Docker
如果是Home-brew v2.x:

$ brew cask install --appdir="/Applications" docker

如果是Homebrew v3.x:

$ brew install --cask --appdir="/Applications" docker

Docker安装好以后必须要保证开启docker服务。

$ open /Applications/Docker.app

5、安装GO

$ brew install go
$ go version
go1.15.7 darwin/amd64

6、安装JQ

$ brew install jq
$ jq --version
jq-1.6

Linux版

(ubuntu为例,如果是centos只需将apt-get改为yum即可)
1、git

$ sudo apt-get install git

2、Git

$ sudo apt-get install curl

3、Docker

sudo apt-get -y install docker-compose

当安装完后确认一下Docker和Docker Compose是否都安装好,如果出现版本号则说明已安装好

$ docker --version
Docker version 19.03.12, build 48a66213fe
$ docker-compose --version
docker-compose version 1.27.2, build 18f557f9

若以上命令不能安装docker-compose,就可以试着用pip命令安装。用yum命令安装的docker compose在运行网络时可能会版本报错。
如果有pip则直接执行此命令即可: sudo pip install -U docker-compose

安装依赖

yum -y install epel-release

安装PIP

yum -y install python-pip

升级PIP

pip install --upgrade pip

验证pip 版本

pip --version

安装docker compose

pip install -U docker-compose==1.25.0

验证docker compose版本

docker-compose --version

安装补全插件

curl -L https://raw.githubusercontent.com/docker/compose/1.25.0/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose

如果需要你卸载docker-compose,

#pip卸载
pip uninstall docker-compose

确保Docker daemon 处于运行状态

sudo systemctl start docker

如果你想在系统启动时就启动Docker daemon,

sudo systemctl enable docker

将你的用户名添加进Docker group

sudo usermod -a -G docker  

上述若不能安装好docker,再试试下面方法,若安装成功则可跳过:

安装docker
安装依赖包:

sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common

添加GPG密钥:

curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

添加软件源:

sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

更新并安装Docker-CE

sudo apt-get update
sudo apt-get install docker-ce

安装docker-compose
用curl将Compose文件下载到/usr/local/bin目录中:

sudo curl -L https://github.com/docker/compose/releases/download/1.25.0-rc1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

下载完成后,将文件更改为可执行权限:

sudo chmod +x /usr/local/bin/docker-compose

验证是否安装成功,查看docker-compose版本信息

docker-compose -v

4、Go

安装GoLang
下载Golang包:https://studygolang.com/dl

tar -zxvf go1.14.12.linux-amd64.tar.gz
sudo mv go /usr/local/

配置环境变量

sudo vim ~/.profile

添加如下内容

export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

保存文件,并且重新加载新的环境变量

source ~/.profile

查看go版本

go version

出现版本则表示安装成功


4.Fabric环境搭建
下载Fabric源码
首先创建文件夹

mkdir HyperledgerFabric2.x

进入刚刚创建的文件夹

cd HyperledgerFabric2.x

GitHub上下载Fabric源码

git clone https://github.com/hyperledger/fabric

如果下载太慢,可以使用Gitee上的镜像仓库

git clone https://gitee.com/mirrors/fabric.git

下载fabric-samples源码。
因为用bootstrap.sh下载binary文件太慢,所以通过vi bootstrap.sh 命令找到Binary=true,将true改为false。这样就可以避免下载binary文件。如果下载很快当我没说。
二进制和CA文件下载源地址链接:
二进制
CA
(二进制和CA下载下来解压后生成bin目录和config目录,直接拷贝到fabric目录下即可。)
进入fabric下的scripts目录,在该目录下启动脚本:bootstrap.sh。

cd fabric/scripts
sudo ./bootstrap.sh # 该命令会下载官方提供的示例代码和镜像文件,然后进入漫长的等待。

将提前下好的binary,和fabric-ca文件解压到fabric-sample文件夹。
如果没有成功clone下fabric-samples。可以直接通过命令 git clone https://gitee.com/lidengjia/fabric-samples.git
在scripts目录下会有fabric-sample文件夹,进入后找到bin目录,里面存放的是二进制程序。
进入test-network文件夹

cd test-network

可以看到有哪些文件

ls
addOrg3  configtx  docker  network.sh  organizations  README.md  scripts  system-genesis-block

运行network.sh

./network.sh up
Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' 
LOCAL_VERSION=2.3.0
DOCKER_IMAGE_VERSION=2.3.1
Local fabric binaries and docker images are out of  sync. This may cause problems.
WARNING: The Docker Engine you're using is running in swarm mode.

Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.

To deploy your application across the swarm, use `docker stack deploy`.

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 peer0.org2.example.com ... done
Creating cli ... done
Creating peer0.org2.example.com ... 
Creating orderer.example.com ... 
Creating cli ... 
CONTAINER ID   IMAGE                               COMMAND                  CREATED         STATUS                    PORTS                                            NAMES
3b6f5257c27b   hyperledger/fabric-tools:latest     "/bin/bash"              1 second ago    Up Less than a second                                                      cli
981eb6be98d4   hyperledger/fabric-orderer:latest   "orderer"                3 seconds ago   Up 1 second               0.0.0.0:7050->7050/tcp, 0.0.0.0:7053->7053/tcp   orderer.example.com
e4709010337b   hyperledger/fabric-peer:latest      "peer node start"        3 seconds ago   Up 1 second               0.0.0.0:7051->7051/tcp                           peer0.org1.example.com
36286d86a1a5   hyperledger/fabric-peer:latest      "peer node start"        3 seconds ago   Up 1 second               7051/tcp, 0.0.0.0:9051->9051/tcp                 peer0.org2.example.co


在启动网络时遇到错误
ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule: (iptables failed: iptables --wait -t nat -I DOCKER -i br-2add1a39bc5d -j RETURN: iptables: No chain/target/match by that name.
原因是关闭防火墙之后docker需要重启,执行以下命令重启docker即可:

systemctl stop firewalld.service
service docker restart

你可能感兴趣的:(区块链技术,fabric)