云网牛站
所在位置:首页 > Linux教程 > Ubuntu 18.04安装Fabric 1.1的步骤

Ubuntu 18.04安装Fabric 1.1的步骤

2018-07-04 10:51:20作者:刘一和刘稿源:linux站

本文将在Ubuntu 18.04操作系统下安装Fabric 1.1版本,以下是具体步骤。

 

0.权限

获取管理员权限:

$ sudo passwd #设置root密码

$ su #切换到root用户

 

1.基础工具准备

1.1.git

$ apt install git

1.2.curl

$ apt install curl

1.3.pip

$ apt install python-pip

$ pip install --upgrade pip

1.4.vim

$ apt install vim

 

2.安装docker和docker compose

2.0.卸载旧版本

如果有的话,卸载旧版本

$ apt remove docker docker-engine docker.io

2.1.安装docker

1].设置docker存储库

$ apt -y install apt-transport-https ca-certificates

2].添加docker的GPG密钥,并添加仓库

$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add

$ sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

3].更新apt软件包

$ apt update

4].安装

$ apt install docker-ce

5].docker版本

$ docker version

2.2.安装docker-compose

从github下载docker-compose二进制文件

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

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

检查docker-compose版本

$ docker-compose version

2.3.docker 常用命令

删除一个容器:docker rm 

强制删除一个容器:docker rm -f 

强制删除全部容器:docker rm -f $(docker ps -aq)

杀死所有正在运行的容器:docker kill $(docker ps -a -q)

删除所有已经停止的容器:docker rm $(docker ps -a -q)

删除所有镜像:docker rmi $(docker images -q)

强制删除所有镜像:docker rmi -f $(docker images -q)

2.4.添加国内镜像下载源

修改docker hub的镜像,编辑/etc/docker/daemon.json文件,没有就创建一个,需要管理员提权,写入以下内容:

{

"registry-mirrors": ["https://registry.docker-cn.com"]

}

重启docker服务生效: sudo service docker restart,这样docker就可以从国内镜像站进行pull操作,大大提高了pull image的速度。

 

3.安装go

3.1.下载安装包

可前往这里下载最新版安装包,当前版本为go1.10.3.linux-amd64.tar.gz

3.2.解压

$ tar -C /usr/local -zxf go1.10.3.linux-amd64.tar.gz

3.3.配置环境变量

1].打开/etc/profile

$ vim /etc/profile

2].写入环境变量

# Go environment

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

export GOPATH=/opt/gopath

然后ESC,:wq保存退出。

3].环境变量生效

$ source /etc/profile

3.4.查看go版本

$ go version

 

4.安装Node.js

4.1.安装node

1].安装

$ apt install nodejs

2].检查版本

$ node -v

4.2.安装npm

1].安装

$ apt install npm

2].升级至新版

$ npm install -g npm@latest

3].重新开启终端后检测版本

$ npm -v

4.3.版本

root@lzj-ThinkCentre-M910t-D562:/# npm -v

6.1.0

root@lzj-ThinkCentre-M910t-D562:/# node -v

v8.10.0

 

5.下载fabric代码和fabric-samples代码

5.1.构建文件夹目录

$ mkdir -p /opt/gopath/src/github.com/hyperledger/

5.2.下载代码

5.2.1.fabric

1].下载fabric代码

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

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

2].进入fabric

$ cd fabric

3].切换代码分之

$ git checkout release-1.1

5.2.2 fabric-simples

1].下载fabric-simples代码

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

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

2].进入fabric-samples

$ cd fabric-samples

3].切换代码分支

$ git checkout release-1.1

5.3.下载docker镜像

$ cd /opt/gopath/src/github.com/hyperledger/fabric/scripts

$ ./bootstrap.sh

5.4.查看已安装的docker images

$ docker images

5.5.拉取二进制执行程序

1].手动下载文件

$ cd /opt/gopath/src/github.com/hyperledger/fabric-samples

$ 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

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

2].将二进制文件写入环境变量

$ cd bin

$ pwd

$ vim /etc/profile

写入如下内容:

export PATH=/opt/gopath/src/github.com/hyperledger/fabric-samples/bin:$PATH

3].使环境变量生效

$ source /etc/profile

 

6.测试fabric-simples

6.1.启动

$ cd /opt/gopath/src/github.com/hyperledger/fabric-simaples/fabcar

$ ./startFabric.sh

启动成功出现:

root@lzj-ThinkCentre-M910t-D562:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar# ./startFabric.sh 

# don't rewrite paths for Windows Git Bash users

export MSYS_NO_PATHCONV=1

docker-compose -f docker-compose.yml down

Removing network net_basic

WARNING: Network net_basic not found.

docker-compose -f docker-compose.yml up -d ca.example.com orderer.example.com peer0.org1.example.com couchdb

Creating network "net_basic" with the default driver

Creating ca.example.com      ... done

Creating orderer.example.com ... done

Creating couchdb             ... done

Creating peer0.org1.example.com ... done

# wait for Hyperledger Fabric to start

# incase of errors when running later commands, issue export FABRIC_START_TIMEOUT=<larger number>

export FABRIC_START_TIMEOUT=10

#echo ${FABRIC_START_TIMEOUT}

sleep ${FABRIC_START_TIMEOUT}

# Create the channel

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/configtx/channel.tx

2018-07-04 10:34:30.256 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized

2018-07-04 10:34:30.284 UTC [channelCmd] InitCmdFactory -> INFO 002 Endorser and orderer connections initialized

2018-07-04 10:34:30.495 UTC [main] main -> INFO 003 Exiting.....

# Join peer0.org1.example.com to the channel.

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel join -b mychannel.block

2018-07-04 10:34:30.648 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized

2018-07-04 10:34:31.198 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel

2018-07-04 10:34:31.198 UTC [main] main -> INFO 003 Exiting.....

Creating cli ... done

2018-07-04 10:34:35.168 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP

2018-07-04 10:34:35.168 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity

2018-07-04 10:34:35.168 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc

2018-07-04 10:34:35.168 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc

2018-07-04 10:34:35.168 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled

2018-07-04 10:34:35.866 UTC [golang-platform] getCodeFromFS -> DEBU 006 getCodeFromFS github.com/fabcar/go

2018-07-04 10:34:36.499 UTC [golang-platform] func1 -> DEBU 007 Discarding GOROOT package bytes

2018-07-04 10:34:36.499 UTC [golang-platform] func1 -> DEBU 008 Discarding GOROOT package encoding/json

2018-07-04 10:34:36.499 UTC [golang-platform] func1 -> DEBU 009 Discarding GOROOT package fmt

2018-07-04 10:34:36.499 UTC [golang-platform] func1 -> DEBU 00a Discarding provided package github.com/hyperledger/fabric/core/chaincode/shim

2018-07-04 10:34:36.499 UTC [golang-platform] func1 -> DEBU 00b Discarding provided package github.com/hyperledger/fabric/protos/peer

2018-07-04 10:34:36.499 UTC [golang-platform] func1 -> DEBU 00c Discarding GOROOT package strconv

2018-07-04 10:34:36.499 UTC [golang-platform] GetDeploymentPayload -> DEBU 00d done

2018-07-04 10:34:36.499 UTC [container] WriteFileToPackage -> DEBU 00e Writing file to tarball: src/github.com/fabcar/go/fabcar.go

2018-07-04 10:34:36.520 UTC [msp/identity] Sign -> DEBU 00f Sign: plaintext: 0A9C070A5C08031A0C08FC92EED90510...F1F3DF000000FFFF06BA999800200000 

2018-07-04 10:34:36.520 UTC [msp/identity] Sign -> DEBU 010 Sign: digest: FBCB257B6BD6523860A624A84B6F9041A6F7186C4F1F82DC5D95E95D868D3E2F 

2018-07-04 10:34:36.775 UTC [chaincodeCmd] install -> DEBU 011 Installed remotely response:<status:200 payload:"OK" > 

2018-07-04 10:34:36.775 UTC [main] main -> INFO 012 Exiting.....

2018-07-04 10:34:36.925 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP

2018-07-04 10:34:36.925 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity

2018-07-04 10:34:36.925 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc

2018-07-04 10:34:36.925 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc

2018-07-04 10:34:36.926 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled

2018-07-04 10:34:36.926 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0AA7070A6708031A0C08FC92EED90510...324D53500A04657363630A0476736363 

2018-07-04 10:34:36.926 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: B796AF19973CF558DB681686D28ED88E46D0725829C1A140812F2A81D1EACA5F 

2018-07-04 10:35:00.448 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0AA7070A6708031A0C08FC92EED90510...5B7F92427E8339FC92919844438BA5CD 

2018-07-04 10:35:00.448 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: E1F6F1FB45DE5BD2DDCEBC183557AAAB95E478AB053166E7F72DC0A47FA35DDB 

2018-07-04 10:35:00.449 UTC [main] main -> INFO 00a Exiting.....

2018-07-04 10:35:10.607 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP

2018-07-04 10:35:10.607 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity

2018-07-04 10:35:10.608 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc

2018-07-04 10:35:10.608 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc

2018-07-04 10:35:10.608 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled

2018-07-04 10:35:10.608 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0AA9070A6908031A0C089E93EED90510...1A0E0A0A696E69744C65646765720A00 

2018-07-04 10:35:10.608 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: 895CCD994678D31504C9AC6DDD0C66CE799BC85CDAF9E121DDAB36999565B838 

2018-07-04 10:35:10.614 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0AA9070A6908031A0C089E93EED90510...12F62521B7B102EB56F1DED55F72234D 

2018-07-04 10:35:10.614 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: CECA4B1757CC96C01A3D9590E3A3935667B9CD5F404628129A71E117EEBF9484 

2018-07-04 10:35:10.615 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> DEBU 00a ESCC invoke result: version:1 response:<status:200 message:"OK" >

......

2018-07-04 10:35:10.615 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00b Chaincode invoke successful. result: status:200 

2018-07-04 10:35:10.615 UTC [main] main -> INFO 00c Exiting.....

Total setup execution time : 62 secs ...

Start by installing required packages run 'npm install'

Then run 'node enrollAdmin.js', then 'node registerUser'

The 'node invoke.js' will fail until it has been updated with valid arguments

The 'node query.js' may be run at anytime once the user has been registered

启动好后,使用docker ps -a可以看到一下容器进程:

root@lzj-ThinkCentre-M910t-D562:/opt/gopath/src/github.com/hyperledger/fabric-samples# docker ps -a

6.2.安装node第三方模块

$ npm install

6.3.测试

1].添加管理员

$ node enrollAdmin.js

结果:

root@lzj-ThinkCentre-M910t-D562:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar# node enrollAdmin.js 

Store path:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar/hfc-key-store

Successfully enrolled admin user "admin"

Assigned the admin user to the fabric client

......

2].注册用户

$ node registerUser.js

结果:

root@lzj-ThinkCentre-M910t-D562:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar# node registerUser.js 

Store path:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar/hfc-key-store

Successfully loaded admin from persistence

Successfully registered user1 - secret:YuarHrEEygUw

Successfully enrolled member user "user1" 

User1 was successfully registered and enrolled and is ready to intreact with the fabric network

3].查询docker

$ node query.js docker

结果:

root@lzj-ThinkCentre-M910t-D562:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar# node query.js docker

Store path:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar/hfc-key-store

Successfully loaded user1 from persistence

Query has completed, checking results

......

 

到此,搭建完毕!

 

相关主题

Docker入门教程

精选文章
热门文章