第一章 九析带你轻松完爆 fabric 区块链安装

目录

1 前言

2 操作系统环境设置

    2.1 主机与操作系统

    2.2 设置主机名

    2.3 设置 DNS

    2.4 关闭防火墙

    2.5 关闭 selinux

    2.6 关闭 swap

3 操作系统软件安装

4 安装 docker

5 安装 docker-compose

    5.1 jsonschema 版本不匹配

    5.2 cffi 版本不匹配

    5.3 dnspython 版本不匹配

    5.4 python-ldap 版本不匹配

    5.5  subprocess32 卸载失败

6 安装配置 go

    6.1 安装 go

    6.2 配置 go

7 下载 fabric 源码


1 前言

        本文介绍如何手动部署 fabric 区块链,通过 fabric 的搭建来了解区块链的网络结构和组件运用。


2 操作系统环境设置

        除 2.2 外,其他每台主机都需要执行如下步骤。

2.1 主机与操作系统

        本区块链需要三台主机。底层操作系统为 centos7。

2.2 设置主机名

        三台主机的主机名分别为 peer0.example.com、peer1.example.com、peer2.example.com。

hostnamectl set-hostname peer0.example.com

hostnamectl set-hostname peer1.example.com

hostnamectl set-hostname peer2.example.com

2.3 设置 DNS

        三台主机运行四个节点(其中一台主机既做 order 节点,也做 peer 节点)。编辑 /etc/hosts:

192.168.182.168 peer0.example.com order.example.com

192.168.182.169 peer1.example.com

192.168.182.170 peer2.example.com

2.4 关闭防火墙

systemctl disable firewalld && systemctl stop firewalld

2.5 关闭 selinux

sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config

setenforce 0

2.6 关闭 swap

sed -i '$d' /etc/fstab

swapoff -a


3 操作系统软件安装

        每台主机都需要安装。

yum update

yum install -y git

yum install -y curl

yum install -y epel-release

yum install -y openldap-devel

yum install -y python-devel

yum install -y python-pip

pip install --upgrade pip


4 安装 docker

        docker 版本 1.13.1。每台主机都需要安装。

yum install docker

systemctl enable docker && systemctl start docker

docker version // 验证是否安装成功


5 安装 docker-compose

        docker-compose 版本 1.25.0。每台主机都需要安装。

pip install docker-compose

docker-compose version // 验证是否安装成功

        如果安装报错,可以参考如下情况进行修改。

5.1 jsonschema 版本不匹配

ERROR: jsonschema 3.2.0 has requirement six>=1.11.0, but you'll have six 1.9.0 which is incompatible.

        执行如下语句:

pip install six --user -U

pip install ipython --user -U

5.2 cffi 版本不匹配

ERROR: cryptography 2.8 has requirement cffi!=1.11.3,>=1.8, but you'll have cffi 1.6.0 which is incompatible.

        执行如下语句:

pip install cffi --user -U

5.3 dnspython 版本不匹配

ERROR: ipapython 4.6.5 has requirement dnspython>=1.15, but you'll have dnspython 1.12.0 which is incompatible.

        执行如下语句:

pip install dnspython --user -U

5.4 python-ldap 版本不匹配

ERROR: ipapython 4.6.5 has requirement python-ldap>=3.0.0b1, but you'll have python-ldap 2.4.15 which is incompatible.

        执行如下语句:

pip install --upgrade python-ldap --user -U

5.5  subprocess32 卸载失败

ERROR: Cannot uninstall 'subprocess32'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

        执行如下语句:

pip install docker-compose --ignore-installed subprocess32


6 安装配置 go

        每台主机都要安装和配置 go。

6.1 安装 go

cd /usr/local

wget https://studygolang.com/dl/golang/go1.13.1.linux-amd64.tar.gz 

tar -xvf go1.13.1.linux-amd64.tar.gz

mkdir -p /workspace // fabric 源码存放目录

mkdir -p /workspace/fabric/bin // fabric 目标代码存放目录

6.2 配置 go

vi /etc/profile

export GOROOT=/usr/local/go 

export GOPATH=/workspace/fabricexport 

PATH=$PATH:$GOROOT/bin:$GOPATH/bin


7 下载 fabric 源码

        每台主机都需要下载 fabric 源码。

cd /workspace

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

        编辑 /workspace/fabric/scripts/bootstrap.sh,修改 download() 方法,去掉 curl 下载的静默模式,否则整个下载过程中,你会看不到任何下载的状态。

curl -L -s "${URL}" | tar xz || rc=$?

改为:

curl -L "${URL}" | tar xz || rc=$?

        修改完,执行一下 bootstrap.sh 脚本,脚本执行会下载 fabric-sample 代码和大量镜像。而且下载过程也可能会时不时被中断,具体原因你自己反省一下,不要尖叫,人生就是这样,你接受就好。脚本执行完毕,本地就会多出如下的镜像:spacer.gif1.png

        自此,fabric 安装成功。下小节将介绍 fabric 的部署。

猜你喜欢

转载自blog.51cto.com/14625168/2461386