系統:Ubuntu16.04 LTS
一、環境准備
1.1 Ubuntu下安裝 crul
sudo apt install curl
curl是利用URL語法在命令行方式下工作的開源文件傳輸工具。它被廣泛應用在Unix、多種Linux發行版中,並且有DOS和Win32、Win64下的移植版本。
作用:文件傳輸
1.2 安裝 Docker and Docker Compose
Docker-compose是支持通過模板腳本批量創建Docker容器的一個組件。
- 前期准備:
由於apt官方庫里的docker版本可能比較舊,所以先卸載可能存在的舊版本:
$ sudo apt-get remove docker-engine docker-ce docker.io
更新apt包索引:
$ sudo apt-get update

- 配置CE環境(Docker CE(Community Edition),即 Docker社區版)
-
配置apt允許以 HTTPS方式拉取鏡像安裝:
$ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common
-
添加Docker官方 GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
校驗
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
.$ sudo apt-key fingerprint 0EBFCD88
- 利用如下命令配置穩定鏡像
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- 安裝Docker
- 更新apt包索引
$ sudo apt-get update
- 安裝最新版Docker
sudo apt-get install docker-ce
s
- 驗證Docker是否已經安裝成功
$ sudo docker run hello-world
此命令會下載一個測試鏡像,並且啟動一個container來運行該鏡像,打印一些信息后退出。
可參考官方教程:https://docs.docker.com/install/linux/docker-ce/ubuntu/#supported-storage-drivers
至此,Docker在Ubuntu上已經安裝成功!
1.3 安裝GO和NodeJS
1.3.1 GO
安裝go語言包:
$ curl -O https://storage.googleapis.com/golang/go1.10.1.linux-amd64.tar.gz
下載完成后,解壓至/usr/local 目錄下:
$ sudo tar -C /usr/local -xzf go1.10.1.linux-amd64.tar.gz
配置go語言環境變量:
進入.bashrc 配置環境變量:
$ sudo vim ~/.bashrc
或者是:
$ sudo vim /etc/profile
在最后面加入如下代碼:
export GOPATH=/usr/local/GO
export PATH=$GOPATH/bin:$PATH
保存,退出。
使環境變量生效:
$ source ~/.bashrc
或者是:
$ source /etc/profile
查看版本號后沒問題,說明配置成功。
1.3.2 node.js
下載node.js
$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash
安裝node.js
$ sudo apt-get install -y nodejs
檢查版本:
二、Fabric 安裝
2.1 Fabric 源碼下載
首先建立對應的目錄,然后進入該目錄,使用Git命令下載源碼:
mkdir -p ~/go/src/github.com/hyperledger cd ~/go/src/github.com/hyperledger git clone https://github.com/hyperledger/fabric.git
由於Fabric一直在更新,所有我們並不需要最新最新的源碼,需要切換到v1.0.0版本的源碼即可:
cd ~/go/src/github.com/hyperledger/fabric git checkout -b v1.0.0
我們可以看到fabric源碼下有許多文件。我們進入/examples/e2e_cli文件夾下。
通過如下命令,下載鏡像:
sudo download-dockerimages.sh -c x86_64-1.0.0 -f x86_64-1.0.0
下載完后,通過 docker images 查看版本即可。
至此fabric環境已經搭建完成。
三、大坑集錦
3.1 權限問題
出現以下問題:
Warning: failed to get default registry endpoint from daemon (Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.38/info: dial unix /var/run/docker.sock: connect: permission denied). Using system default: https://index.docker.io/v1/ Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.38/images/create?fromImage=hyperledger%2Ffabric-peer&tag=latest: dial unix /var/run/docker.sock: connect: permission denied Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.38/images/hyperledger/fabric-peer:latest/tag?repo=hyperledger%2Ffabric-peer&tag=latest: dial unix /var/run/docker.sock: connect: permission denied
當在查詢docker 版本時,也會出現類似錯誤:
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.38/version: dial unix /var/run/docker.sock: connect: permission denied
這主要就是未獲得root權限,所造成的錯誤。
解決方法:
授予root權限即可。
sudo ./download-dockerimages.sh
3.2 版本問題
如果直接獲取最新版本,最后會出現如下問題:
Error response from daemon: manifest for hyperledger/fabric-javaenv:latest not found
原因:主要是因為一些組件還沒有更新到最新版本,只有幾個組建有最新版本。所以下載組件時要加上版本號。為了學習資料較全的v1.0.0,故我下載的是1.0.0版本。
sudo ./download-dockerimages.sh -c x86_64-1.0.0 -f x86_64-1.0.0
===> List out hyperledger docker images hyperledger/fabric-ccenv <none> 6acf31e2d9a4 7 weeks ago 1.43GB hyperledger/fabric-orderer <none> 4baf7789a8ec 7 weeks ago 152MB hyperledger/fabric-peer <none> 82c262e65984 7 weeks ago 159MB hyperledger/fabric-couchdb <none> 3092eca241fc 2 months ago 1.61GB hyperledger/fabric-tools latest 0403fd1c72c7 13 months ago 1.32GB hyperledger/fabric-tools x86_64-1.0.0 0403fd1c72c7 13 months ago 1.32GB hyperledger/fabric-couchdb latest 2fbdbf3ab945 13 months ago 1.48GB hyperledger/fabric-couchdb x86_64-1.0.0 2fbdbf3ab945 13 months ago 1.48GB hyperledger/fabric-kafka latest dbd3f94de4b5 13 months ago 1.3GB hyperledger/fabric-kafka x86_64-1.0.0 dbd3f94de4b5 13 months ago 1.3GB hyperledger/fabric-zookeeper latest e545dbf1c6af 13 months ago 1.31GB hyperledger/fabric-zookeeper x86_64-1.0.0 e545dbf1c6af 13 months ago 1.31GB hyperledger/fabric-orderer latest e317ca5638ba 13 months ago 179MB hyperledger/fabric-orderer x86_64-1.0.0 e317ca5638ba 13 months ago 179MB hyperledger/fabric-peer latest 6830dcd7b9b5 13 months ago 182MB hyperledger/fabric-peer x86_64-1.0.0 6830dcd7b9b5 13 months ago 182MB hyperledger/fabric-javaenv latest 8948126f0935 13 months ago 1.42GB hyperledger/fabric-javaenv x86_64-1.0.0 8948126f0935 13 months ago 1.42GB hyperledger/fabric-ccenv latest 7182c260a5ca 13 months ago 1.29GB hyperledger/fabric-ccenv x86_64-1.0.0 7182c260a5ca 13 months ago 1.29GB hyperledger/fabric-ca latest a15c59ecda5b 13 months ago 238MB hyperledger/fabric-ca x86_64-1.0.0 a15c59ecda5b 13 months ago 238MB
3.3 更改獲取的源
如果是國外的源會很慢很慢,需要保證apt source是國內的。具體做法:
方法一:
sudo vi /etc/apt/sources.list
打開這個apt源列表,如果其中看到是http://us.xxxxxx之類的,那么就是外國的,如果看到是http://cn.xxxxx之類的,那么就不用換的。我的是美國的源,所以需要做一下批量的替換。在命令模式下,輸入:
:%s/us./cn./g
就可以把所有的us.改為cn.了。然后輸入:wq即可保存退出。
方法二:
界面操作,后續補充。
3.4 測試e2e網絡時,ERR 001:
最常見的就是ERRO 001 cannot run peer because error when setting up MSP from directory /opt/gopath/src/......。出現這個問題主要是由於鏡像沒下全以及缺少ltdl.h文件的原因,當然還要確定你的fabric版本與你下的鏡像版本一致,我使用的是v1.0.0。
解決方式如下:
1.確定fabric版本與你下的鏡像版本一致(推薦使用v1.0.0):
在fabric目錄下輸入git checkout v1.0.0
通過輸入docker images查看你已下載的鏡像。
不正確的話則在fabric目錄下輸入git clone https://gerrit.hyperledger.org/r/fabric -b v1.0.0
確保你下的版本是v1.0.0
2.erro 001的錯誤往往是由無法正確生成公私鑰和證書的原因,測試如下:
參考資料:
環境配置:
1.https://blog.csdn.net/agecntao/article/details/78580746
2.https://blog.csdn.net/xxxslinyue/article/details/79396618
3.https://blog.csdn.net/sun13465816527/article/details/80393119
4.https://blog.csdn.net/tiandiwuya/article/details/78771475
6.https://blog.csdn.net/sinat_36742186/article/details/78510191
7.http://www.netkiller.cn/journal/hyperledger.html
錯誤解決:
1.https://blog.csdn.net/mx1222/article/details/80888830 不太推薦
【時間倉促,如有錯誤,歡迎指正! || 歡迎一起學習交流, 請在評論區留言!】
【本作品采用知識共享署名-非商業性使用-相同方式共享 4.0 國際許可協議進行許可。】
【轉載請聯系博主,同意后務必注明出處:http://www.cnblogs.com/X-knight/】