Hyperledger-fabric 环境搭建

Hyperledger-fabric 环境搭建

按着官方文档的步骤先配置前置环境

https://hyperledger-fabric.readthedocs.io/en/latest/prereqs.html

Hyperledger fbric 1.4.5

Ubuntu 18.04

0. 配置下虚拟机网络

因为众所周知的原因,国内网络不是很通畅,使用魔法后设置允许局域网使用。

在wired settings中设置Network Proxy,全部指向本机的魔法端口

1. 安装git

Install Git

Download the latest version of git if it is not already installed, or if you have problems running the curl commands.

先装个Git

sudo apt install git

# 安装完后查询git版本
nykuvl@ubuntu:~$ git version
git version 2.17.1

2. 安装curl

Install cURL

Download the latest version of the cURL tool if it is not already installed or if you get errors running the curl commands from the documentation.

安装curl工具

sudo apt install curl

# 安装完后查询curl版本
nykuvl@ubuntu:~$ curl --version
curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Release-Date: 2018-01-24
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 

3. 安装wget

Install wget

If you will be downloading Fabric binaries based on the Install Samples, Binaries, and Docker Images documentation, you will need wget installed.

sudo apt install wget

# 安装完后查询wget版本
nykuvl@ubuntu:~$ wget --version
GNU Wget 1.19.4 built on linux-gnu.

4. 安装Docker和Docker-compose

Docker and Docker Compose

You will need the following installed on the platform on which you will be operating, or developing on (or for), Hyperledger Fabric:

  • MacOSX, *nix, or Windows 10: Docker Docker version 17.06.2-ce or greater is required.
  • Older versions of Windows: Docker Toolbox - again, Docker version Docker 17.06.2-ce or greater is required.

操作来源:https://zhuanlan.zhihu.com/p/106186391

# 安装工具让apt可以支持HTTPS方式获取包
sudo apt install apt-transport-https ca-certificates curl software-properties-common

# 将官方Docker库的GPG公钥添加到系统中
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# 将Docker库添加到apt里
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"

# 再次更新下apt库列表
sudo apt update

# 开始安装docker-ce
sudo apt install docker-ce

# 安装完成查询版本号
docker --version

nykuvl@ubuntu:~$ docker --version
Docker version 19.03.6, build 369ce74a3c

# 开始安装docker-compose
sudo apt install docker-compose

# 安装完成后查询docker-compose版本号
docker-compose --version

nykuvl@ubuntu:~$ docker-compose --version
docker-compose version 1.17.1, build unknown

安装完docker之后还需要将使用的用户加入docker的用户组中,不然使用docker会报permission denied错误

nykuvl@ubuntu:~$ docker images
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/images/json: dial unix /var/run/docker.sock: connect: permission denied

执行以下语句

sudo usermod -a -G docker <username>

此处填上使用的用户名

5. 安装Golang

进入 https://golang.org/dl/ 官网下载最新版go安装包

安装后进行解压操作

sudo tar -C /usr/local -xzf go1.13.8.linux-amd64.tar.gzip

添加路径

Add /usr/local/go/bin to the PATH environment variable. You can do this by adding this line to your /etc/profile (for a system-wide installation) or $HOME/.profile:

export PATH=$PATH:/usr/local/go/bin

# 使用source命令让配置生效
source ~/.profile

# 查看go的版本
go version

nykuvl@ubuntu:~$ go version
go version go1.13.8 linux/amd64

# 设置GOROOT和GOPATH环境变量
vim ~/.bashrc
# 在最后一行加入
export GOROOT=/usr/local/go #GOROOT是系统上安装Go软件包的位置。
export GOPATH=/home/hadoop/GOPATH #GOPATH是工作目录的位置。
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

# 使用source命令更新配置
source ~/.bashrc

# 验证环境变量配置
nykuvl@ubuntu:~$ echo $GOROOT
/usr/local/go
nykuvl@ubuntu:~$ echo $GOPATH
/home/nykuvl/go

6. 安装Node.js和NPM

Node.js Runtime and NPM

If you will be developing applications for Hyperledger Fabric leveraging the Hyperledger Fabric SDK for Node.js, version 8 is supported from 8.9.4 and higher. Node.js version 10 is supported from 10.15.3 and higher.

sudo apt isntall node.js

sudo apt install npm

# 更新node到长服务版
sudo npm install -g n
sudo n lts

# 更新npm
sudo npm i -g npm

# 查看版本
nykuvl@ubuntu:~/go$ npm -v
6.13.4
nykuvl@ubuntu:~/go$ node -v
v12.16.1

7. 安装python

# 安装python2
sudo apt install python
# 安装python3
sudo apt install python3

# 查看版本
nykuvl@ubuntu:~/go$ python --version
Python 2.7.17
nykuvl@ubuntu:~/go$ python3 --version
Python 3.6.9

8. 安装Hyperledger fabric

curl -sSL https://bit.ly/2ysbOFE | bash -s

一键安装fabric最新环境,但是网络条件不允许安装过程及其满并且出现错误没法及时处理

先把fabric的GitHub项目拉下来

# 创建$GOPATH目录下的src/github.com/hyperledger目录
mkdir -p /home/nykuvl/go/src/github.com/hyperledger
# 进入目录
cd $GOPATH/src/github.com/hyperledger

# 拉取项目
git clone https://github.com/hyperledger/fabric.git

# 切换版本到1.4
git branch -a
git checkout release-1.4

# 安装相关依赖软件 先进入GOPATH路径再进行以下操作
go get github.com/golang/protobuf/protoc-gen-go
mkdir -p $GOPATH/src/github.com/hyperledger/fabric/build/docker/gotools/bin
cp $GOPATH/bin/protoc-gen-go $GOPATH/src/github.com/hyperledger/fabric/build/docker/gotools/bin

# 编译Fabric模块,进入Fabric源码所在文件夹
cd $GOPATH/src/github.com/hyperledger/fabric

make release

# 将编译后的二进制文件复制到系统文件夹中
sudo cp $GOPATH/src/github.com/hyperledger/fabric/release/linux-amd64/bin/* /usr/local/bin

# 确认版本号
nykuvl@ubuntu:~/go/src/github.com/hyperledger/fabric$ configtxgen -version
configtxgen:
 Version: 1.4.5
 Commit SHA: 11ff99170
 Go version: go1.13.8
 OS/Arch: linux/amd64
nykuvl@ubuntu:~/go/src/github.com/hyperledger/fabric$ configtxlator version
configtxlator:
 Version: 1.4.5
 Commit SHA: 11ff99170
 Go version: go1.13.8
 OS/Arch: linux/amd64
nykuvl@ubuntu:~/go/src/github.com/hyperledger/fabric$ peer version
peer:
 Version: 1.4.5
 Commit SHA: 11ff99170
 Go version: go1.13.8
 OS/Arch: linux/amd64
 Chaincode:
  Base Image Version: 0.4.18
  Base Docker Namespace: hyperledger
  Base Docker Label: org.hyperledger.fabric
  Docker Namespace: hyperledger

nykuvl@ubuntu:~/go/src/github.com/hyperledger/fabric$ orderer version
orderer:
 Version: 1.4.5
 Commit SHA: 11ff99170
 Go version: go1.13.8
 OS/Arch: linux/amd64

nykuvl@ubuntu:~/go/src/github.com/hyperledger/fabric$ cryptogen version
cryptogen:
 Version: 1.4.5
 Commit SHA: 11ff99170
 Go version: go1.13.8
 OS/Arch: linux/amd64

接下来处理docker镜像

# 拉取docker镜像,我使用时问题很多,就不使用这个脚本了,手动拉取镜像
// make docker

docker pull hyperledger/fabric-baseos:0.4.18 # 基础镜像文件,其他镜像文件在该镜像文件的基础上生成
docker pull hyperledger/fabric-baseimage:0.4.18 # 基础镜像文件包含了jdk、golang、nodejs等,可以用来生成chaincode
docker pull hyperledger/fabric-peer:1.4 # peer模块镜像文件
docker pull hyperledger/fabric-ca:1.4 # ca模块镜像文件
docker pull hyperledger/fabric-tools:1.4 # 相关工具镜像文件,包含了cryptogen、configtxgen、configtxlator等工具
docker pull hyperledger/fabric-couchdb:0.4.18 # couchdb数据库镜像文件
docker pull hyperledger/fabric-kafka:0.4.18 # kafka库镜像文件
docker pull hyperledger/fabric-zookeeper:0.4.18 # zookeeper库镜像文件
docker pull hyperledger/fabric-orderer:1.4 # orderer节点库镜像文件
docker pull hyperledger/fabric-ccenv:1.4 # Go语言chaincode运行环境镜像文件
posted @ 2020-02-21 22:57  NykuvL  阅读(673)  评论(0编辑  收藏  举报