linux搭建Fabric

这一步并非必须,但鉴于docker容器的实际情况,理论上linux内核需要在3.10及以上。有朋友在3.10上跑通过,具体是什么内核版本没详细去确认,为了顺利起见,请首先升级linux内核到4.x(最后不成功才要升,新测3.10可跑,linuux要2G内存以上)

一、环境整理

1、CentOS升内核

查看CentOS系统

cat /etc/redhat-release

结果显示(7.4版本)

CentOS Linux release 7.4.1708 (Core)
检查当前 CentOS 系统内核版本

uname -sr

结果显示(4.15版本)

Linux 4.15.14-1.el7.elrepo.x86_64
升内核要CentOS 允许使用 ELRepo,这是一个第三方仓库,可以将内核升级到最新主线稳定内核
启动ELRepo,运行以下命令

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org 
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

仓库启用后,你可以使用下面的命令列出可用的系统内核相关包:

yum --disablerepo="*" --enablerepo="elrepo-kernel" list available

接下来,安装最新的主线稳定内核

yum --enablerepo=elrepo-kernel install kernel-ml

查看可用的内核

cat /boot/grub2/grub.cfg |grep menuentry

结果显示:

Linux 4.15.14-1.el7.elrepo.x86_64
[root@VM_0_14_centos hyperledger]# cat /boot/grub2/grub.cfg |grep menuentry 
if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
  menuentry_id_option=""
export menuentry_id_option
menuentry 'CentOS Linux (4.15.14-1.el7.elrepo.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.el7.x86_64-advanced-49f819fd-e56d-48a4-86d3-7ebe0a68ec88' {
menuentry 'CentOS Linux (0-rescue-f9d400c5e1e8c3a8209e990d887d4ac1) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-f9d400c5e1e8c3a8209e990d887d4ac1-advanced-49f819fd-e56d-48a4-86d3-7ebe0a68ec88' {

替代要用的内核例如:

CentOS Linux (4.15.14-1.el7.elrepo.x86_64) 7 (Core)
grub2-set-default 'CentOS Linux (4.15.14-1.el7.elrepo.x86_64) 7 (Core)

'
查看内核启动项是否设置成功查看内核启动项是否设置成功

grub2-editenv list

结果显示:

saved_entry=CentOS Linux (4.15.14-1.el7.elrepo.x86_64) 7 (Core)

查询多余的内核

rpm -qa | grep kernel

删除多余内核

yum remove

你要删除的内核
重启系统即可

reboot

二、环境安装配置

1、docker安装

1.1安装Docker CE版,如果有旧的先卸载

sudo yum remove docker \ 
                               docker-common \ 
                               docker-selinux \ 
                               docker-engine

1.2 开始安装Docker ce

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
 sudo yum-config-manager --enable docker-ce-edge
 sudo yum-config-manager --enable docker-ce-test
 sudo yum-config-manager --disable docker-ce-edge
 sudo yum makecache fast
 sudo yum install docker-ce

1.3检查是否安装成功

[root@VM_0_14_centos hyperledger]# docker --version
Docker version 18.04.0-ce-rc1, build 0c7f7c6

1.4 启动docker

/bin/systemctl start docker.service

2、Docker-Compose安装

需要服务器支持curl功能,如果服务器不支持curl,需要执行如下操作安装curl依赖

yum install curl

2.1 安装最新版本
根据官网所指向github项目,目前docker-compose最新版为1.15.0
执行命令

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

给于权限

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

2.2、查看版本

[root@VM_0_14_centos hyperledger]# docker-compose --version
docker-compose version 1.15.0, build e12f3b9

docker常用命令

杀死所有正在运行的容器

docker kill $(docker ps -a -q)

删除所有已经停止的容器

docker rm $(docker ps -a -q)

删除所有镜像

docker rmi $(docker images -q)

强制删除所有镜像

docker rmi -f $(docker images -q)

3、GO语言安装

GO安装链接
==最后环境如下==

linux搭建Fabriclinux搭建Fabric

三、源码下载

1、首先进入到go的path目录

cd $GOPATH

2、新建文件夹

mkdir -p src/github.com/hyperledger

3、然后进入到如下路径

/opt/gopath/src/github.com/hyperledger

4、下载fabric

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

4.1、进入到fabric目录查看fabric的git版本

cd fabric/
git branch -a

结果显示(当前使用的是master分支)

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/feature/ca
  remotes/origin/feature/convergence
  remotes/origin/master
  remotes/origin/release-1.0
  remotes/origin/release-1.1
  remotes/origin/v0.6
  remotes/origin/v1.0.0-preview

4.2、切换到release-1.1分支

git checkout release-1.1

查看有没有切换成功

git branch -a

结果显示

  master
* release-1.1
  remotes/origin/HEAD -> origin/master
  remotes/origin/feature/ca
  remotes/origin/feature/convergence
  remotes/origin/master
  remotes/origin/release-1.0
  remotes/origin/release-1.1
  remotes/origin/v0.6
  remotes/origin/v1.0.0-preview

5、下载fabric-samples
5.1、进入到与fabric平级的目录

cd $GOPATH/src/github.com/hyperledger

5.2、下载源码

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

5.3,进入fabric-samples目录,查看分支并切换到1.1

cd fabric-samples/
git branch -a
git checkout release-1.1

下载完成后的结构应该如下图所示
linux搭建Fabriclinux搭建Fabric

四、下载镜像和要执行的二进制文件

1、进入到fabric-samples目录
==如果网络环境足够好,能访问外网的话,可以直接执行下面这条语句就会下载所有镜像和要执行的二进制的文件==

curl -sSL https://goo.gl/6wtTN5 | bash -s 1.1.0

下载完成后要会多出这两个文件bin和config
linux搭建Fabriclinux搭建Fabric

2、连不了外网的按下面执行(下载镜像和二进制文件这两个步骤)
进到fabric目录下的scripts
并修改bootstrap.sh

cd fabric/scripts/
vim bootstrap.sh

修改图中圈的部分,修改为1.1.0版本,然后保存
linux搭建Fabriclinux搭建Fabric

image

运行bootstrap.sh下载镜像(要等几分钟)

./bootstrap.sh

3、下载二进制执行文件
进入到fabric-samples文件

cd fabric-samples/

通过wget下载1.1.0版本的二进制文件

wget https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.1.0/hyperledger-fabric-linux-amd64-1.1.0.tar.gz

解压下载的文件,会发现多了bin和config两个个文件夹

tar -zxvf hyperledger-fabric-linux-amd64-1.1.0.tar.gz

把bin配置到环境

cd bin/
pwd
vim /etc/profile
source /etc/profile

修改的项
linux搭建Fabriclinux搭建Fabric

五、运行文件

进到fabric-samples/first-network

cd fabric-samples/first-network/

生成配置文件

./byfn.sh -m generate

选择同意,会默认生成mychannel

起动项目

./byfn.sh -m up

成功的结果:
linux搭建Fabriclinux搭建Fabric

成功后关闭

./byfn.sh -m down

==阿里云服务器要修改base文件夹的docker-compose-base.yaml,所有的environment下添加 -GODEBUG=netdns=go,如下图==

linux搭建Fabriclinux搭建Fabric

本文地址:https://www.linuxprobe.com/fabric.html

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值