本文主要介绍fabric安装

基础环境安装

官方文档参考

linux环境情况如下
1
2
3
4
5
6
7
8
qinghua@qinghua-virtual-machine:~/project/src$ lsb_release -a 
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 19.10
Release: 19.10
Codename: eoan
qinghua@qinghua-virtual-machine:~/project/src$ cat /proc/version
Linux version 5.3.0-23-generic (buildd@lgw01-amd64-002) (gcc version 9.2.1 20191008 (Ubuntu 9.2.1-9ubuntu2)) #25-Ubuntu SMP Tue Nov 12 09:22:33 UTC 2019

go项目放在/home/qinghua/project目录下

go环境安装

go的下载地址,我这里使用的是go1.13.4.linux-amd64.tar.gz

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
qinghua@qinghua-virtual-machine:~$ pwd
/home/qinghua

#下载
qinghua@qinghua-virtual-machine:~$ wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz

#移动
qinghua@qinghua-virtual-machine:~$ sudo mv go1.13.4.linux-amd64.tar.gz /usr/

#解压,解压出的文件夹是go
qinghua@qinghua-virtual-machine:~$ cd /usr && sudo tar -zxvf go1.13.4.linux-amd64.tar.gz

#配置环境变量
qinghua@qinghua-virtual-machine:/usr$ sudo vim /etc/profile
#########=====添加如下内容=======######
GOROOT=/usr/go

#对qinghua这个用户配置go的环境变量
qinghua@qinghua-virtual-machine:/usr$ cd ~

#更改用户环境变量
qinghua@qinghua-virtual-machine:~$ vim .bashrc
#########=====添加如下内容=======######
source /etc/profile
export GOPATH=/home/qinghua/project
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN

#生效环境变量
qinghua@qinghua-virtual-machine:~$ source .bashrc

#查看go版本
qinghua@qinghua-virtual-machine:/usr$ go version
go version go1.13.4 linux/amd64

#创建文件夹
#src 包含项目的源代码文件;
#pkg 包含编译后生成的包/库文件;
#bin 包含编译后生成的可执行文件。
qinghua@qinghua-virtual-machine:~$ cd project && mkdir src pkg bin
设置ubuntu源

我们需设置源sources.list,这里我们设置清华源

docker安装时,会报如下错误

1
2
3
4
5
Err:11 https://download.docker.com/linux/ubuntu eoan Release
404 Not Found [IP: 13.226.77.16 443]

#在sources.list加如下内容:
deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
docker安装

docker安装,查看官方文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#卸载
qinghua@qinghua-virtual-machine:~/project$ sudo apt-get remove docker docker-engine docker.io containerd runc

#apt更新
qinghua@qinghua-virtual-machine:~/project$ sudo apt-get update

#apt添加源
qinghua@qinghua-virtual-machine:~/project$ sudo apt-get install \
> apt-transport-https \
> ca-certificates \
> curl \
> gnupg-agent \
> software-properties-common

#office key
qinghua@qinghua-virtual-machine:~/project$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

#fingerprint
qinghua@qinghua-virtual-machine:~/project$ sudo apt-key fingerprint 0EBFCD88

#stable
qinghua@qinghua-virtual-machine:~/project$ sudo add-apt-repository \
> "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
> $(lsb_release -cs) \
> stable"

#update
qinghua@qinghua-virtual-machine:~/project$ sudo apt-get update

#install
qinghua@qinghua-virtual-machine:~/project$ sudo apt-get install docker-ce docker-ce-cli containerd.io

#test 会报错,需要将当前用户加入docker用户组
qinghua@qinghua-virtual-machine:~/project$ sudo groupadd docker
groupadd: group 'docker' already exists

#加入docker组
qinghua@qinghua-virtual-machine:~/project$ sudo gpasswd -a ${USER} docker
Adding user qinghua to group docker

#重启docker
qinghua@qinghua-virtual-machine:~/project$ sudo service docker restart

#查看docker版本
qinghua@qinghua-virtual-machine:~/project$ docker -v
Docker version 19.03.5, build 633a0ea838
docker-compose安装

官方教程

1
2
3
4
5
6
7
8
9
10
11
12
13

#download && install
qinghua@qinghua-virtual-machine:~/project$ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

#增加可执行权限
qinghua@qinghua-virtual-machine:~/project$ sudo chmod +x /usr/local/bin/docker-compose

#查看docker-compose版本
qinghua@qinghua-virtual-machine:~/Desktop$ docker-compose version
docker-compose version 1.24.1, build 4667896b
docker-py version: 3.7.3
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.1.0j 20 Nov 2018
linux基金会账号

后面我们获取fabric代码,会直接从linux基金会project中clone,这里我们需要先创建账号

账号申请

git安装
1
2
3
4
qinghua@qinghua-virtual-machine:~/Desktop$ sudo apt install git

qinghua@qinghua-virtual-machine:~/Desktop$ git version
git version 2.20.1

在linux基金会账号上配置ssh key,配置地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#生成ssh-key,一路enter
qinghua@qinghua-virtual-machine:~/Desktop$ ssh-keygen -t rsa -C qinghua

#查看/home/qinghua/.ssh
qinghua@qinghua-virtual-machine:~/.ssh$ pwd
/home/qinghua/.ssh
qinghua@qinghua-virtual-machine:~/.ssh$ ll
total 16
drwx------ 2 qinghua qinghua 4096 11月 22 16:15 ./
drwxr-xr-x 25 qinghua qinghua 4096 11月 21 15:24 ../
-rw------- 1 qinghua qinghua 1811 11月 22 16:15 id_rsa
-rw-r--r-- 1 qinghua qinghua 389 11月 22 16:15 id_rsa.pub

#将id_rsa.pub粘贴到ssh配置中https://gerrit.hyperledger.org/r/settings/

下载源代码 && 编译

下载fabric源码
1
2
3
qinghua@qinghua-virtual-machine:~/hyperledger$ git clone "ssh://qinghua0310@gerrit.hyperledger.org:29418/fabric" && scp -p -P 29418 qinghua0310@gerrit.hyperledger.org:hooks/commit-msg "fabric/.git/hooks/"

qinghua@qinghua-virtual-machine:~/hyperledger$ cd fabric && make dist-clean all
下载fabric-sample源码
1
2
3
4
qinghua@qinghua-virtual-machine:~/project/src/github.com/hyperledger$ git clone "ssh://qinghua0310@gerrit.hyperledger.org:29418/fabric-samples" && scp -p -P 29418 qinghua0310@gerrit.hyperledger.org:hooks/commit-msg "fabric-samples/.git/hooks/"

#对于ubuntu系统,需执行下边的脚本,安装项目所需的一些依赖
qinghua@qinghua-virtual-machine:~/project/src/github.com/hyperledger$ cd devenv && sudo ./setupUbuntuOnPPC64le.sh

执行make dist-clean all

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 执行项目make
qinghua@qinghua-virtual-machine:/project/src/github.com/hyperledger/fabric$ make dist-clean all

## 报错'module' object has no attribute 'PROTOCOL_SSLv3'
qinghua@qinghua-virtual-machine:~$ sudo pip install requests==2.22.0

## 卸载pyOpenssl
qinghua@qinghua-virtual-machine:~$ sudo pip uninstall pyopenssl

# 报错: File "/usr/local/lib/python2.7/dist-packages/compose/cli/formatter.py", line 15, in <module>
# from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size
#ImportError: No module named shutil_get_terminal_size

qinghua@qinghua-virtual-machine:~$ sudo vim /usr/local/lib/python2.7/dist-packages/compose/cli/formatter.py

##### 对应行作如下处理 ########
try:
from backports import get_terminal_size as _get_terminal_size
except ImportError:
# use backport on Python 2
from shutil_backports import get_terminal_size as _get_terminal_size
##### 对应行作如下处理 ########

# 再次make dist-clean all,这次就可以编译通过,但有一些test没有通过,后续我们再分析
qinghua@qinghua-virtual-machine:/project/src/github.com/hyperledger/fabric$ make dist-clean all

删除一些none镜像

1
qinghua@qinghua-virtual-machine:/project/src/github.com/hyperledger/fabric$ docker rmi $(docker images | awk '/^<none>/ { print $3 }')

 评论