Ubuntn 16.04 部署Hyperledger Fabric

Ubuntn 16.04 部署Hyperledger Fabric

本教程依照官网文档部署 https://hyperledger-fabric.readthedocs.io/en/release-1.4/getting_started.html
部署环境为Ubuntn16.04,在root用户下。

一、安装cURL

如果之前没有安装curl,或者运行文档中的curl命令出错时,则安装最新版本curl工具,在命令行中输入以下命令。

apt install curl

二、Docker 和Docker-compose

1 、安装Docker

参考官方文档https://docs.docker.com/install/linux/docker-ce/ubuntu/

1.1 卸载旧版本

旧版本的docker名称为docker或者docker-engine,如果之前安装过,那么将其卸载。

$ sudo apt-get remove docker docker-engine docker.io
1.2安装docker-CE(使用Repository安装Docker)
1.2.1设置Repository
(1) 更新apt包索引
$ sudo apt-get update
(2) 安装包以允许通过HTTPS使用存储库
$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
(3) 添加Docker的官方GPG密钥
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

通过查看指纹的最后8个字符,验证您现在拥有指纹9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88的密钥

$ sudo apt-key fingerprint 0EBFCD88

pub   4096R/0EBFCD88 2017-02-22
      Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <docker@docker.com>
sub   4096R/F273FCD8 2017-02-22
(4) 设置stable版本Repository
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
1.2.2 安装docker-CE
(1) 更新apt包索引
$ sudo apt-get update
(2) 安装最新版本的Docker-CE
$ sudo apt-get install docker-ce

查看docker版本

docker --version

显示如下

Docker version 18.09.0, build 4d60db4
(3)测试
$ sudo docker run hello-world

结果如下,docker安装成功。

Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

2 、安装docker-compose

参考官方文档https://docs.docker.com/compose/install/

方法一

1、下载最新版本Docker-compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

2、应用可执行权限

sudo chmod +x /usr/local/bin/docker-compose
方法二

上面的方法貌似有时在国内访问速度很慢,也可以尝试下面这种替代的安装方式

pip install docker-compose
测试
$ docker-compose --version
docker-compose version 1.23.1, build 1719ceb

三、安装Go

需要1.11.x以上版本

1、下载

切换至/usr/local目录下

root@ubuntu:~# cd /usr/local
root@ubuntu:/usr/local# 
root@ubuntu:/usr/local# wget https://studygolang.com/dl/golang/go1.11.linux-amd64.tar.gz
root@ubuntu:/usr/local# tar -xzvf go1.11.linux-amd64.tar.gz
解压后如下所示
root@ubuntu:/usr/local# ls
bin  games  go1.11.linux-amd64.tar.gz  lib  sbin   src
etc  go     include                    man  share
2、添加环境变量

添加环境变量

root@ubuntu:~# vim /etc/profile

在文件末尾处添加以下文本

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

保存后退出,让更改生效

root@ubuntu:~# source /etc/profile

查看安装版本

root@ubuntu:~# go version
go version go1.11 linux/amd64

四、安装node.js

需要8.9.x及以上版本

root@ubuntu:~# curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
root@ubuntu:~# sudo apt-get install -y nodejs
root@ubuntu:~# node -v
v8.15.1

五、安装二进制文件和配置文件

下载fabric-samples文件

root@DESKTOP-UQ8L8G4:~# mkdir -p  ~/go/src/github/hyperledger
root@DESKTOP-UQ8L8G4:~# cd ~/go/src/github/hyperledger/
root@DESKTOP-UQ8L8G4:~/go/src/github/hyperledger# 
root@DESKTOP-UQ8L8G4:~/go/src/github/hyperledger# git clone https://github.com/hyperledger/fabric-samples.git

下载并解压configtxgen文件

root@DESKTOP-UQ8L8G4:~/go/src/github/hyperledger# cd fabric-samples
root@DESKTOP-UQ8L8G4:~/go/src/github/hyperledger/fabric-samples# wget https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.4.1/hyperledger-fabric-linux-amd64-1.4.1.tar.gz
root@DESKTOP-UQ8L8G4:~/go/src/github/hyperledger/fabric-samples# tar -xzvf hyperledger-fabric-linux-amd64-1.4.1.tar.gz
解压后得到bin和config两个文件夹
有时下载configtxgen文件会很慢,可以直接再windows上用迅雷下载之后再使用xftp上传到服务器的~/go/src/github/hyperledger/fabric-samples目录下,也可以用百度云下载后上传到该目录下。
链接:https://pan.baidu.com/s/1aX_vdTmqQvnf-0zH31X4KQ 
提取码:ghub 

六、启动fabric网络

root@DESKTOP-UQ8L8G4:~/go/src/github.com/hyperledger/fabric-samples# cd first-network/
root@DESKTOP-UQ8L8G4:~/go/src/github.com/hyperledger/fabric-samples/first-network# ./byfn.sh up
执行完成后,如果显示如下,则fabric network已经成功启动。
========= All GOOD, BYFN execution completed =========== 


 _____   _   _   ____   
| ____| | \ | | |  _ \  
|  _|   |  \| | | | | | 
| |___  | |\  | | |_| | 
|_____| |_| \_| |____/  

如果你使用的是阿里云服务器,需要进行如下操作

vim /etc/resolv.conf
#options timeout:2 attempts:3 rotate single-request-reopen	//把这一行注释掉,不然会报如下错误。
Error: error getting endorser client for channel: endorser client failed to connect to peer0.org1.example.com:7051: failed to create new connection: connection error: desc = "transport: error while dialing: dial tcp: lookup peer0.org1.example.com: no such host"

问题及解决

问题一 :报错"cryptogen tool not found. exiting"
root@iZt4ndwoa23ksu38g5tjeaZ:~/go/src/github.com/hyperledger/fabric-samples/first-network# ./byfn.sh up
Starting for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
./byfn.sh: line 122: configtxlator: command not found
LOCAL_VERSION=
DOCKER_IMAGE_VERSION=1.4.1
=================== WARNING ===================
  Local fabric binaries and docker images are  
  out of  sync. This may cause problems.       
===============================================
cryptogen tool not found. exiting

解决:缺少cryptogen以及configtxgen文件

下载并解压configtxgen文件
```java
root@DESKTOP-UQ8L8G4:~/go/src/github/hyperledger# cd fabric-samples
root@DESKTOP-UQ8L8G4:~/go/src/github/hyperledger/fabric-samples# wget https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.4.1/hyperledger-fabric-linux-amd64-1.4.1.tar.gz
root@DESKTOP-UQ8L8G4:~/go/src/github/hyperledger/fabric-samples# tar -xzvf hyperledger-fabric-linux-amd64-1.4.1.tar.gz
解压后得到bin和config两个文件夹
问题二 :报错“Error: got unexpected status: BAD_REQUEST – error applying config update to existing channel ‘mychannel’: error authorizing update: error validating ReadSet: proposed update requires that key [Group] /Channel/Application be at version 0, but it is currently at version 1”
2019-07-12 01:42:26.538 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
Error: got unexpected status: BAD_REQUEST -- error applying config update to existing channel 'mychannel': error authorizing update: error validating ReadSet: proposed update requires that key [Group]  /Channel/Application be at version 0, but it is currently at version 1
!!!!!!!!!!!!!!! Channel creation failed !!!!!!!!!!!!!!!!

解决 : 已经存在mychannel,之前启动的fabric network没有正常停止,如果之前执行./byfn.sh up,那么相应的执行./byfn.sh down来停止fabric network。不要直接使用docker stop 或者 docker rm 停止删除容器。

你可能感兴趣的:(Hyperledger,Fabric,区块链,超级账本,Hyperledger,Fabric)