如何在Ubuntu 16.04 LTS中安裝Hyperledger Fabric 1.2
注: 這裡使用的是全新安裝的ubuntu 16.04 LTS 作業系統。
- 更新package:
sudo apt-get update
安裝curl和軟體包以設定Docker儲存庫
sudo apt-get install curl apt-transport-https ca-certificates software-properties-common
- 新增Docker gpg key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- 校驗gpg key
sudo apt-key fingerprint 0EBFCD88
- 新增Docker 的儲存(repository)
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- 再一次更新package index
sudo apt-get update
- 安裝最新穩定版本的Docker
sudo apt-get install docker-ce
- 檢查Docker的版本
docker --version
- 下載Docker Compose
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
- 新增Docker Compose 二進位制檔案的執行許可權
sudo chmod +x /usr/local/bin/docker-compose
- 檢查Docker Compose的對應版本
docker-compose --version
下載並配置Go語言的程式設計環境
注: 可以通過https://golang.org/dl/ 來檢視最新的穩定版本,並通過編輯 *.tar.gz來確定下載的二進位制檔案
curl -O https://storage.googleapis.com/golang/go1.10.3.linux-amd64.tar.gz sha256sum go1.10.3.linux-amd64.tar.gz tar -xvf go1.10.3.linux-amd64.tar.gz sudo mv go /usr/local
- 開啟profile檔案來設定Go的環境變數
sudo vim ~/.profile
- 將以下內容新增到~/.profile 檔案
export GOPATH=$HOME/go export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
- 重新載入profile 檔案
source ~/.profile
安裝Node.js
注:這裡我們需要站樁Ubuntu的一些packages,並且重新根據原始碼編譯Node.js因為Hyperledger 1.2 只支援Node.js 8.9+ <9的版本。
- 再一次更新package index,安裝一些必要的packages
sudo apt-get update sudo apt-get install build-essential openssl libssl-dev pkg-config
- 前往src目錄,建立一個node資料夾,然後進入node資料夾
cd /usr/local/src sudo mkdir node cd node
- 下載Node.js
sudo wget [https://nodejs.org/dist/v8.9.3/node-v8.9.3.tar.gz](https://nodejs.org/dist/v8.9.3/node-v8.9.3.tar.gz)
- 解壓縮tar檔案,進入新建立的node-v8.9.3資料夾,然後make, make install命令
sudo tar zxvf node-v8.9.3.tar.gz cd node-v8.9.3 sudo ./configure sudo make sudo make install
- 檢視Node.js的安裝版本
node --version
- 更新NPM版本
sudo npm install [email protected] -g npm --version
下載Fabric的引導指令碼bootstrap.sh
$ 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
-
執行引導指令碼
通過執行指令碼去安裝fabric,並且下載Fabric-sample,摘取docker映象。
$ cd ~/hyperledger-fabric/ $ chmod 755 bootstrap.sh $ sudo ./bootstrap.sh 1.2.0 1.2.0 0.4.10
- 新增環境變數
$ vi ~/.bashrc
- 增加下面的環境變數,儲存並退出
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin:/home/blockchain/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
建立和管理網路
- 執行./byfn.sh generate 命令生成相應的檔案
$ 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 ... .......
- 執行./byfn.sh up 啟動網路
$ ./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_IMAGE_VERSION=1.2.0 Creating network "net_byfn" with the default driver Creating volume "net_orderer.example.com" with default driver Creating volume "net_peer0.org1.example.com" with default driver Creating volume "net_peer1.org1.example.com" with default driver Creating volume "net_peer0.org2.example.com" with default driver Creating volume "net_peer1.org2.example.com" with default driver Creating peer0.org2.example.com ... done Creating orderer.example.com... done Creating peer0.org1.example.com ... done Creating peer1.org1.example.com ... done Creating peer1.org2.example.com ... done Creating cli... done ___________________ / ___||__|/ \|_ \|__| \___ \| |/ _ \| |_) || | ___) || |/ ___ \|_ <| | |____/|_|/_/\_\ |_| \_\|_| Build your first network (BYFN) end-to-end test Channel name : mychannel Creating channel... .......
- 看到START,表示啟動成功
- 執行結束,顯示END
- 停止網路,執行./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.org2.example.com ... done Stopping orderer.example.com... done Stopping peer1.org1.example.com ... done Stopping peer0.org2.example.com ... done Removing cli... done Removing peer0.org1.example.com ... done Removing peer1.org2.example.com ... done Removing orderer.example.com... done Removing peer1.org1.example.com ... done Removing peer0.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. 7c129154a34a 3746b3295e48 d2cdb7e80c20 Untagged: dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab:latest Deleted: sha256:af423f72155affe6f12819384004ffdbf3506274458e85ace79b85afa9f2edaf Deleted: sha256:b3fbcd50f54c60d9454612a3ed2a01b0c4d060b27113fc1a9d1289647d43d0fe Deleted: sha256:71212a99a5c510e8d4e06d998c9238f8aeab0d39b43585c0f592bcb783212115 Deleted: sha256:6a155ef7756a3361c3c549a4bb9bb8b9138ef53ebfada38d65dc00d874ebc5b6 Untagged: dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9:latest Deleted: sha256:c4c8845cab7101ee6a4456ee544c4a6599c42bbca545b11045d6b47c1223f205 Deleted: sha256:f2f179f4758793728780f909833f710c71f40e77303bd64eb910d572a641c66b Deleted: sha256:03f9cd5e163dc2fae818d7864f8f068330eb7e0b0709a34d40dfcf0e40bd5d43 Deleted: sha256:8747af4513550fd8f0f6cfd22c61fd531b073a1a733d02ff6e3fb97fb6def027 Untagged: dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b:latest Deleted: sha256:2bffc21709916a8d9bd1c20a65134ac3ca31ef5cc6e1282cea3b6be28d295acb Deleted: sha256:7cf57b3452456b8da30c08d92d0c054fe32b2c91cd047dc8075706af2c14dc0d Deleted: sha256:6e5b8c88c9d03c7d776953ee8c1b638d02a60438130c9d174b99455bc43d07b8 Deleted: sha256:b9eee4e0944c3b35fec12aa4bb5624d02825ab12e71d8a6a73e3de9702831382