ubuntu16.04 HyperLedger Fabric 1.2.0 開發環境搭建

安裝準備

1. 安裝git、cRUL、gcc/g++和make

$ sudo apt-get update
$ sudo apt-get install build-essential git curl make 
$ $ which gcc
/usr/bin/gcc

2. 安裝Docker和Docker Compose

安裝Docker-CE

參考: ubuntu16.04下docker安裝和簡單使用
! 注意安裝的docker版本是否知足要求
查看docker版本html

$ docker --version
Docker version 18.06.1-ce, build e68fc7a

安裝docker-compose

! 注意版本
參考:
docker-compose安裝node

# 下載
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 添加寫權限
$ sudo chmod +x /usr/local/bin/docker-compose

# 查看docker-compose版本
$ docker-compose --version
docker-compose version 1.22.0, build f46880fe

3. 安裝go

go下載地址
! 注意go版本是否知足要求python

1) 安裝

$ wget https://dl.google.com/go/go1.10.1.linux-amd64.tar.gz
$ tar zxvf go1.10.1.linux-amd64.tar.gz
$ sudo mv go /usr/local/
$ mkdir -p ~/go/{src,bin}
$ vi ~/.bashrc

2) 設置環境變量

須要在~/.bashrc中設置環境變量GOPATH,GOROOT,PATH,例如:linux

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

保存退出,使得配置當即生效git

source ~/.bashrc

3) 驗證配置是否正常

$ echo $GOROOT
/usr/local/go
$ echo $GOPATH
/home/bob/go
$ which go
/usr/local/go/bin/go

4. 安裝Nodejs和NPM

! 注意版本
參考: nodejs ubuntu安裝github

# 查看版本
$ node -v
v8.11.4
$ npm -v
5.6.0

5. 安裝python

# 安裝python
$ sudo apt-get install python 
$ python -V
Python 2.7.12

# 安裝pip
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py 

# 切換到root用戶
$ su 
# python get-pip.py

!!!!!! 友情提示: 若是使用了VMware Workstation,作到這裏的時候,最好先使用快照(snapshot)進行快速備份,防止以後出現莫名其妙的問題實在解決不了,能夠從備份點恢復再來,以避免徹底從新開始,建立虛擬機。golang

使用腳本安裝fabric

1. 下載啓動腳本並安裝

$ cd ~
$ mkdir hyperledger-fabric
$ cd hyperledger-fabric
$ curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/release-1.2/scripts/bootstrap.sh -o bootstrap.sh
$ ls
bootstrap.sh
$ chmod +x bootstrap.sh 
$ ./bootstrap.sh 1.2.0 1.2.0 0.4.10

注意:
hyperledger-fabric

hyperledger-fabric-ca下載速度較慢
能夠考慮使用代理加速下載docker

安裝過程記錄:npm

===> List out hyperledger docker images
hyperledger/fabric-ca          1.2.0               66cc132bd09c        
hyperledger/fabric-ca          latest              66cc132bd09c       
hyperledger/fabric-tools       1.2.0               379602873003       
hyperledger/fabric-tools       latest              379602873003      
hyperledger/fabric-ccenv       1.2.0               6acf31e2d9a4       
hyperledger/fabric-ccenv       latest              6acf31e2d9a4       
hyperledger/fabric-orderer     1.2.0               4baf7789a8ec       
hyperledger/fabric-orderer     latest              4baf7789a8ec        
hyperledger/fabric-peer        1.2.0               82c262e65984        
hyperledger/fabric-peer        latest              82c262e65984        
hyperledger/fabric-zookeeper   0.4.10              2b51158f3898      
hyperledger/fabric-zookeeper   latest              2b51158f3898       
hyperledger/fabric-kafka       0.4.10              936aef6db0e6       
hyperledger/fabric-kafka       latest              936aef6db0e6       
hyperledger/fabric-couchdb     0.4.10              3092eca241fc       
hyperledger/fabric-couchdb     latest              3092eca241fc

2. 設置環境變量

在PATH中加入~/~/hyperledger-fabric/fabric-samples/bin,形如:bootstrap

$ vi ~/.bashrc
# 修改PATH
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin:~/hyperledger-fabric/fabric-samples/bin:.

使得環境變量當即生效

$ source ~/.bashrc

測試修改是否生效

$ fabric-ca-client version
fabric-ca-client:
 Version: 1.2.0
 Go version: go1.10
 OS/Arch: linux/amd64

3. 建立和管理網絡

1> 生成數字證書和創世區塊

$ cd ~/hyperledger-fabric/fabric-samples/first-network/
$ ./byfn.sh generate
Generating certs and genesis block for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
/home/bob/hyperledger-fabric/fabric-samples/first-network/../bin/cryptogen
...

其中byfn.sh爲啓動這個網絡的啓動腳本,啓動腳本中除創建一個包含4個節點和1個Order service的網絡外,還會啓動一個容器用來執行腳本在channel中加入節點,部署和初始化chaincode,以及在部署的chaincode上執行交易。默認channel名稱爲mychannel,腳本程序會給網絡實例生成數字證書和密鑰;生成genesis block用來啓動ordering service;一些用來配置channel的配置交易

2> 使用docker-compose啓動網絡

$ ./byfn.sh up
Starting for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
LOCAL_VERSION=1.2.0
...

安裝過程記錄:

使用docker ps來查看節點啓動狀況

使用docker images查看安裝鏡像

關閉網絡

使用./byfn.sh down

$ ./byfn.sh down
Stopping for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
Stopping cli                    ... done
Stopping peer0.org1.example.com ... done
Stopping peer1.org1.example.com ... done
Stopping orderer.example.com    ... done
Stopping peer0.org2.example.com ... done
Stopping peer1.org2.example.com ... done
Removing cli                    ... done
Removing peer0.org1.example.com ... done
Removing peer1.org1.example.com ... done
Removing orderer.example.com    ... done
Removing peer0.org2.example.com ... done
Removing peer1.org2.example.com ... done
Removing network net_byfn
Removing volume net_orderer.example.com
Removing volume net_peer0.org1.example.com
Removing volume net_peer1.org1.example.com
Removing volume net_peer0.org2.example.com
Removing volume net_peer1.org2.example.com
Removing volume net_peer0.org3.example.com
WARNING: Volume net_peer0.org3.example.com not found.
Removing volume net_peer1.org3.example.com
WARNING: Volume net_peer1.org3.example.com not found.
...

參考:

相關文章
相關標籤/搜索