ubuntu中Hyperledger Fabric2.2環境搭建
- 一、ubuntu更換國內源
- 1、備份原始源檔案source.list
- 2、修改源檔案
- 3、更新源
- 二、軟體安裝
- 1、Git安裝
- 2、cURL安裝
- 3、Go語言安裝
- 4、Docker安裝
- 5、Docker-Compose安裝
- 三、Fabric網路安裝
- 1、獲取fabric原始碼
- 2、 二進制檔案、docker檔案、fabric-samples下載
一、ubuntu更換國內源
1、備份原始源檔案source.list
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
2、修改源檔案
(1) 編輯源檔案
sudo gedit /etc/apt/sources.list
(2)進入后洗掉里面的內容,添加阿里源并保存(以下的源是18.04的)
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
P.S.:不同版本的Ubuntu對應的源不同(參考這篇文章:Ubuntu換阿里源的方法)
3、更新源
sudo apt update
二、軟體安裝
1、Git安裝
sudo apt-get install git
2、cURL安裝
sudo apt install curl
3、Go語言安裝
(1)安裝依賴
sudo apt install libtool libltdl-dev
(2)下載go語言安裝包
下載地址:https://studygolang.com/dl
(3)解壓
cd /usr/local
sudo tar zxvf go1.14.6.linux-amd64.tar.gz
(4)配置go的環境變數
編輯組態檔
P.S.:~/.bashrc 、/etc/profile都配置一下(我不確定是哪一個組態檔生效,只配置下面這個可能會導致關閉終端再打開新的終端后,后面某步顯示go的環境變數不正確類似陳述句)
sudo gedit ~/.profile
添加路徑在最后并保存
#go
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
更新組態檔:(同理:~/.bashrc 、/etc/profile都需要更新)
source ~/.profile
測驗是否安裝成功
go version
如果顯示了版本號資訊,則說明安裝成功了,
4、Docker安裝
安裝必要的一些系統工具
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
安裝GPG證書:
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
寫入軟體源資訊
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
安裝Docker-CE
sudo apt-get -y install docker-ce
將當前用戶添加到Docker用戶組并更新
//如果還沒有 docker group 就添加一個
sudo groupadd docker
//將用戶加入該 group ,然后退出并重新登錄后生效
sudo gpasswd -a ${USER} docker
//重啟 docker 服務
sudo service docker restart
//切換當前會話到新 group
newgrp - docker
P.S.:解決加入docker組后依舊需要sudo運行docker的方法

sudo su
USERNAME是你的用戶名
su USERNAME

創建/etc/docker/daemon.json檔案
sudo gedit /etc/docker/daemon.json
添加以下內容
{
"registry-mirrors": ["http://f1361db2.m.daocloud.io","https://hub-mirror.c.163.com","https://xsoeja86.mirror.aliyuncs.com"]
}
重啟服務
sudo systemctl daemon-reload
sudo systemctl restart docker
檢查是否安裝成功,如果顯示client和server資訊則成功
docker version
5、Docker-Compose安裝
sudo curl -L https://github.com/docker/compose/releases/download/1.25.0-rc1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
更改權限
sudo chmod +x /usr/local/bin/docker-compose
檢查是否安裝成功,如果顯示版本資訊則成功
docker-compose version
三、Fabric網路安裝
1、獲取fabric原始碼
P.S.:先退出當前終端,重新打開一個
創建一個目錄并進入
mkdir -p go/src/github.com/hyperledger/
cd go/src/github.com/hyperledger/
從github上下載fabric原始碼
git clone "https://github.com/hyperledger/fabric.git"
P.S.:下載原始碼可能失敗,可以利用gitee來下載,具體方法詳見:git clone失敗解決方法
下載完成后,查看版本并選擇分支2.2
cd fabric
git branch -a
git checkout release-2.2
2、 二進制檔案、docker檔案、fabric-samples下載
執行腳本
cd scripts/
sudo ./bootstrap.sh
成功后會在該目錄下生成fabric-samples,進入測驗網路目錄,用腳本開啟網路
設定環境變數
sudo vim /etc/profile
加入
#fabric
export PATH=$PATH:$HOME/go/src/github.com/hyperledger/fabric-samples/config
export PATH=$PATH:$HOME/go/src/github.com/hyperledger/fabric-samples/bin
進入測驗網路目錄,用腳本開啟網路
cd fabric-samples
cd test-network/
./network.sh up

參考文章:
https://blog.csdn.net/shengsikandan/article/details/107656060
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/255267.html
標籤:區塊鏈
上一篇:《On-device federated learning via blockchain and its latency analysis》論文筆記
下一篇:2021-01-31
