Centos7部署Fabric2.3

文章目录

目录

文章目录

前言

一、环境搭建

1.1 yum源设置

1.2 git安装

1.3 curl安装

1.4 docker安装 

1.5 安装docker-compose

1.6 Go环境安装

二、安装Fabric

三、启动Fabric测试网

四、遇到的问题 

总结

参考博客


前言

本人也是站在前人的肩膀上学习开发,借鉴前人的基础,使用阿里云服务器搭建自己的Fabric网络,记录自己的学习过程

一、环境搭建

1.1 yum源设置

1.备份本地yum源

cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base

2.设置aliyun源

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3.清理缓存

yum clean all

4.更新yum源

yum update

1.2 git安装

yum install git -y

1.3 curl安装

yum install curl -y

1.4 docker安装 

1.卸载docker的旧版本

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

2.安装依赖包

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

3.添加docker yum源

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

4.安装docker

yum install docker-ce

5.启动docker

systemctl start docker

6.设置开机自启docker 

systemctl enable docker
systemctl list-unit-files --all --type=service | grep docker

7.查看docker运行状况

systemctl status docker

8.检查docker版本

docker version

9.设置加速镜像

在/etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件)

腾讯云:https://mirror.ccs.tencentyun.com

阿里云:https://svaken38.mirror.aliyuncs.com

网易云:http://hub-mirror.c.163.com

{
  "registry-mirrors": ["https://svaken38.mirror.aliyuncs.com"]
}
systemctl daemon-reload
systemctl restart docker

1.5 安装docker-compose

1.在线安装

curl -L https://get.daocloud.io/docker/compose/releases/download/1.26.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

2.赋权

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

3.检查安装版本 

docker-compose version

1.6 Go环境安装

1.我装的是1.14.10版本,推荐安装1.13+.

cd /opt
mkdir golang && mkdir gopath
cd golang
wget https://studygolang.com/dl/golang/go1.14.10.linux-amd64.tar.gz
tar -zxvf go1.14.10.linux-amd64.tar.gz

2. 添加环境变量

vim /etc/profile
# 添加以下内容
export GOPATH=/opt/gopath
export GOROOT=/opt/golang/go
export PATH=$GOROOT/bin:$PATH

3.刷新配置文件

source /etc/profile

4.查看配置是否成功

go version
go env

二、安装Fabric

1.通过git拉取fabric源码

cd /opt
git clone https://github.com/hyperledger/fabric.git
# 通常会因为网络原因下载失败,可以改成如下
git clone git://github.com/hyperledger/fabric.git

2.查看分支

cd /fabric
git branch -a
# 切换分支(选择自己想要的版本,本人使用2.3版本)
git checkout release-2.3

下载完成后会得到一个fabric文件夹,进入fabric/scripts可以看到有一个bootstrap.sh脚本,直接运行脚本,就会自动下载fabric相关文件和镜像。

但是涉及到从github下载代码,过程会很漫长,所以为了节省时间,可以注释脚本中的pullBinaries。我们先下载docker镜像和fabric-samples。

3.拉取fabric-samples

cd /scripts
vim bootstrap.sh
# 注释掉 pullBinarie :wq 保存退出
./bootstrap.sh

下载的fabric-samples会在scripts文件夹下,把它放到上一级目录方便操作

mv fabric-samples/ ../

4.下载二进制文件(这个过程十分漫长)

vim bootstrap.sh
# 注释掉cloneSamplesRepo和pullDockerImages 单独下载 pullBinaries
./bootstrap.sh

或者可以直接从浏览器下载好在上传到服务器,将下载好的bin和config放到fabric-samples目录下。我的下载链接如下:

https://github.com/hyperledger/fabric/releases/download/v2.3.3/hyperledger-fabric-linux-amd64-2.3.3.tar.gz
https://github.com/hyperledger/fabric-ca/releases/download/v1.5.2/hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz

三、启动Fabric测试网

1.进入test-network

# 进入测试网文件夹
cd /opt/fabric/fabric-samples/test-network
# 如果第一次启动就不用执行./network.sh down(清除上次启动的网络)
./network.sh down
# 启动网络
./network.sh up 
# 启动完毕脚本自动执行docker ps -a 可以查看网络组成

2.创建通道

./network.sh createChannel

3.安装链码

./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go

详细内容可以参考官方教程:Using the Fabric test network — hyperledger-fabricdocs master documentation


四、遇到的问题 

由于当时没有及时记录报错信息,只好从浏览记录中翻看解决方法来回想自己的问题。

1.由于之前下载二进制文件非常缓慢,时常由于网络问题而下载失败,所以我选择用浏览器下载好再上传到服务器,用到的工具是FileZilla。在连接服务器是遇到连接失败的问题:

①22端口没有开放,从而发现防火墙没有开放,遇到的问题和解决方案请参考如下链接:

Centos 7 出现“FirewallD is not running”怎么办_司夏的博客-CSDN博客_firewalld is not running

但是需要注意的是,防火墙在重启之后,docker服务也需要重启

ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule_tianshuhao521的博客-CSDN博客

②在安装链码时出现ERROR,遇到的问题和解决方案请参考如下链接:

成功解决Error: failed to normalize chaincode path: ‘go list‘ failed with: go: github.com/golang/protobuf_GniLAY1022的博客-CSDN博客


总结

以上就是对fabric2.3版本的网络部署

如有错误,还请指正,相互学习


参考博客

https://blog.csdn.net/weixin_43557810/article/details/106677534

猜你喜欢

转载自blog.csdn.net/humingwei11/article/details/122536104