1. 程式人生 > >Hyperledger fabric 1.1環境的搭建實操

Hyperledger fabric 1.1環境的搭建實操

一、環境整理

這一步並非必須,但鑑於docker容器的實際情況,理論上linux核心需要在3.10及以上。有朋友在3.10上跑通過,具體是什麼核心版本沒詳細去確認,為了順利起見,請首先升級linux核心到4.x(最後不成功才要升,新測3.10可跑,linuux要2G記憶體以上)
1、CentOS升核心
檢視CentOS系統
cat /etc/redhat-release

結果顯示(7.4版本)

CentOS Linux release 7.4.1708 (Core) 
檢查當前 CentOS 系統核心版本
uname -sr 

結果顯示(4.15版本)

Linux 4.15.14-1.el7.elrepo.x86_64

升核心要CentOS 允許使用 ELRepo,這是一個第三方倉庫,可以將核心升級到最新主線穩定核心
啟動ELRepo,執行以下命令

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org 
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
倉庫啟用後,你可以使用下面的命令列出可用的系統核心相關包:
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
接下來,安裝最新的主線穩定核心
yum --enablerepo=elrepo-kernel install kernel-ml
檢視可用的核心
cat /boot/grub2/grub.cfg |grep menuentry 

結果顯示:

Linux 4.15.14-1.el7.elrepo.x86_64
[[email protected]_0_14_centos hyperledger]# cat /boot/grub2/grub.cfg |grep menuentry 
if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
  menuentry_id_option=""
export menuentry_id_option menuentry 'CentOS Linux (4.15.14-1.el7.elrepo.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.el7.x86_64-advanced-49f819fd-e56d-48a4-86d3-7ebe0a68ec88' { menuentry 'CentOS Linux (0-rescue-f9d400c5e1e8c3a8209e990d887d4ac1) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-f9d400c5e1e8c3a8209e990d887d4ac1-advanced-49f819fd-e56d-48a4-86d3-7ebe0a68ec88' {
替代要用的核心例如:

CentOS Linux (4.15.14-1.el7.elrepo.x86_64) 7 (Core)

grub2-set-default 'CentOS Linux (4.15.14-1.el7.elrepo.x86_64) 7 (Core)'
檢視核心啟動項是否設定成功檢視核心啟動項是否設定成功
grub2-editenv list

結果顯示:

saved_entry=CentOS Linux (4.15.14-1.el7.elrepo.x86_64) 7 (Core)
查詢多餘的核心
rpm -qa | grep kernel
刪除多餘核心
yum remove 你要刪除的核心
重啟系統即可
reboot

二、環境安裝配置

1、docker安裝
1.1安裝Docker CE版,如果有舊的先解除安裝
sudo yum remove docker \ 
                               docker-common \ 
                               docker-selinux \ 
                               docker-engine
1.2 開始安裝Docker ce
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
$ sudo yum-config-manager \
 --add-repo \
 https://download.docker.com/linux/centos/docker-ce.repo
 sudo yum-config-manager --enable docker-ce-edge
 sudo yum-config-manager --enable docker-ce-test
 sudo yum-config-manager --disable docker-ce-edge
 sudo yum makecache fast
 sudo yum install docker-ce
1.3檢查是否安裝成功
[[email protected]_0_14_centos hyperledger]# docker --version
Docker version 18.04.0-ce-rc1, build 0c7f7c6
1.4 啟動docker
/bin/systemctl start docker.service
2、Docker-Compose安裝

需要伺服器支援curl功能,如果伺服器不支援curl,需要執行如下操作安裝curl依賴

yum install curl
2.1 安裝最新版本

根據官網所指向github專案,目前docker-compose最新版為1.15.0</br>
執行命令

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

給於許可權

chmod +x /usr/local/bin/docker-compose
2.2、檢視版本
[[email protected]_0_14_centos hyperledger]# docker-compose --version
docker-compose version 1.15.0, build e12f3b9

docker常用命令

殺死所有正在執行的容器
docker kill $(docker ps -a -q)

刪除所有已經停止的容器
docker rm $(docker ps -a -q)

刪除所有映象
docker rmi $(docker images -q)

強制刪除所有映象
docker rmi -f $(docker images -q)
3、GO語言安裝

GO安裝連結</br>
==最後環境如下==

image

三、原始碼下載

1、首先進入到go的path目錄
cd $GOPATH
2、新建資料夾
mkdir -p src/github.com/hyperledger
3、然後進入到如下路徑
/opt/gopath/src/github.com/hyperledger
4、下載fabric
git clone https://github.com/hyperledger/fabric.git
4.1、進入到fabric目錄檢視fabric的git版本
cd fabric/
git branch -a

結果顯示(當前使用的是master分支)

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/feature/ca
  remotes/origin/feature/convergence
  remotes/origin/master
  remotes/origin/release-1.0
  remotes/origin/release-1.1
  remotes/origin/v0.6
  remotes/origin/v1.0.0-preview

4.2、切換到release-1.1分支
git checkout release-1.1

檢視有沒有切換成功

git branch -a

結果顯示

  master
* release-1.1
  remotes/origin/HEAD -> origin/master
  remotes/origin/feature/ca
  remotes/origin/feature/convergence
  remotes/origin/master
  remotes/origin/release-1.0
  remotes/origin/release-1.1
  remotes/origin/v0.6
  remotes/origin/v1.0.0-preview
5、下載fabric-samples
5.1、進入到與fabric平級的目錄
cd $GOPATH/src/github.com/hyperledger
5.2、下載原始碼
git clone https://github.com/hyperledger/fabric-samples.git
5.3,進入fabric-samples目錄,檢視分支並切換到1.1
cd fabric-samples/
git branch -a
git checkout release-1.1
下載完成後的結構應該如下圖所示
image

四、下載映象和要執行的二進位制檔案

1、進入到fabric-samples目錄

==如果網路環境足夠好,能訪問外網的話,可以直接執行下面這條語句就會下載所有映象和要執行的二進位制的檔案==

curl -sSL https://goo.gl/6wtTN5 | bash -s 1.1.0
下載完成後要會多出這兩個檔案bin和config
image
2、連不了外網的按下面執行(下載映象和二進位制檔案這兩個步驟)

進到fabric目錄下的scripts
並修改bootstrap.sh

cd fabric/scripts/
vim bootstrap.sh

修改圖中圈的部分,修改為1.1.0版本,然後儲存


image
執行bootstrap.sh下載映象(要等幾分鐘)
./bootstrap.sh 
3、下載二進位制執行檔案
進入到fabric-samples檔案
 cd fabric-samples/
通過wget下載1.1.0版本的二進位制檔案
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
解壓下載的檔案,會發現多了bin和config兩個個資料夾
tar -zxvf hyperledger-fabric-linux-amd64-1.1.0.tar.gz 
把bin配置到環境
cd bin/
pwd
vim /etc/profile
source /etc/profile

修改的項


image
五、執行檔案
進到fabric-samples/first-network
cd fabric-samples/first-network/
生成配置檔案
./byfn.sh -m generate

選擇同意,會預設生成mychannel

起動專案
./byfn.sh -m up

成功的結果:

image
成功後關閉
./byfn.sh -m down

==阿里雲伺服器要修改base資料夾的docker-compose-base.yaml,所有的environment下新增 -

GODEBUG=netdns=go,如下圖==