環境
Centos7
Fabric 1.4.1
Docker 18.3
Docker-compose 1.14.0
GoLang 1.11.5
安裝必備工具
git
- sudo yum install -y git
curl
- sudo yum install -y curl
golang
(1)下載 Golang
可以 wget 工具安裝 Golang:
Golang 的版本要求查看 Fabric 依賴的軟件版本,不是越新版本越好,新版本會出現不兼容的情況,Fabric1.4 要求 Golang 版本為 go1.11.x。
如果網絡不行,上述命令執行失敗,可以直接從 https://studygolang.com/dl 下載相應的 Golang 版本壓縮包,拷貝到虛擬機。
(2)解壓文件
下載完 Golang 壓縮包之后,使用 tar 命令將壓縮包解壓到指定的 /usr/local/
路徑下:
- sudo tar -zxvf go1.11.11.linux-amd64.tar.gz -C /usr/local/
(3)配置環境變量
如果想讓系統所有用戶使用 Golang,則編輯 /etc/profile 文件;如果只是想讓當前用戶使用 Golang,則編輯當前用戶 $HOME 目錄下的 .bashrc 或 .profile 文件。
在 profile 文件最后添加如下內容:
使用 source 命令,使剛剛添加的配置信息生效:
- source /etc/profile
使用 go version 命令驗證是否安裝成功:
docker
下載docker-ce rpm文件
- wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm
安裝docker-ce
- yum install -y docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm
啟動docker
- systemctl start docker
- systemctl enable docker (開機自啟)
測試 docker version
[root@localhost ~]# docker version Client: Version: 18.03.1-ce API version: 1.37 Go version: go1.9.5 Git commit: 9ee9f40 Built: Thu Apr 26 07:20:16 2018 OS/Arch: linux/amd64 Experimental: false Orchestrator: swarm Server: Engine: Version: 18.03.1-ce API version: 1.37 (minimum version 1.12) Go version: go1.9.5 Git commit: 9ee9f40 Built: Thu Apr 26 07:23:58 2018 OS/Arch: linux/amd64 Experimental: false
配置鏡像加速器
這里選擇的是阿里雲的鏡像加速器:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors,不配置鏡像加速器下載速度很慢。
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["加速器地址"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
docker-compose
- curl -L https://github.com/docker/compose/releases/download/1.14.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
- sudo chmod +x /usr/local/bin/docker-compose
測試
[root@localhost ~]# docker-compose version docker-compose version 1.14.0, build c7bdf9e docker-py version: 2.3.0 CPython version: 2.7.13 OpenSSL version: OpenSSL 1.0.1t 3 May 2016
拉取fabric源碼
在gopath下創建目錄並進入。(gopath 默認為/root/go,可以通過 go env | grep GOPATH查看)
- mkdir -p ~/go/src/github.com/hyperledger
- cd ~/go/src/github.com/hyperledger
拉取1.4.1版本的farbic源碼
- git clone --branch v1.4.1 https://github.com/hyperledger/fabric.git
拉取fabric依賴
由於 e2e 網絡在 Fabric1.4 已經移除,所以測試網絡使用 fabric-samples
中的 first-network
。
可以在 fabric/scripts
目錄下找到 bootstrap.sh
腳本
- chmod +x bootstrap.sh
該腳本會幫你干很多事情:
- 如果當前目錄沒有
hyperledger/fabric-samples
,會從github.com
克隆hyperledger/fabric-samples
存儲庫; - 使用 checkout 簽出對應指定的版本標簽;
- 將指定版本的
Hyperledger Fabric
平台特定的二進制文件和配置文件安裝到fabric-samples
存儲庫的根目錄中; - 下載指定版本的
Hyperledger Fabric Docker
鏡像文件; - 將下載的 Docker 鏡像文件標記為 “lastest"。
自動安裝
修改bootstrap.sh找到第137行、145行,將".nexus"刪除
執行
- ./bootstrap.sh 1.4.1 1.4.1 0.4.15
如果下載二進制文件失敗,可以如下面手動安裝或者拉取得出
進入fabric目錄下
- make release
拉取二進制工具,執行完成后,在fabric/release/linux-amd64/bin的目錄下有拉取好的二進制文件
cp cryptogen configtxgen configlator fabric-samples/bin
copy 工具到fabric-samples的bin目錄下
手動安裝
查看 bootstrap.sh
腳本,該腳本主要幫我們干以下三件事,一般會卡在 binariesInstall 步驟,我們可以手動完成這三個步驟。
if [ "$SAMPLES" == "true" ]; then echo echo "Installing hyperledger/fabric-samples repo" echo samplesInstall fi if [ "$BINARIES" == "true" ]; then echo echo "Installing Hyperledger Fabric binaries" echo binariesInstall fi if [ "$DOCKER" == "true" ]; then echo echo "Installing Hyperledger Fabric docker images" echo dockerInstall fi
下載 fabric-samples
源碼
查看 bootstrap.sh 腳本:
samplesInstall() { # clone (if needed) hyperledger/fabric-samples and checkout corresponding # version to the binaries and docker images to be downloaded if [ -d first-network ]; then # if we are in the fabric-samples repo, checkout corresponding version echo "===> Checking out v${VERSION} of hyperledger/fabric-samples" git checkout v${VERSION} elif [ -d fabric-samples ]; then # if fabric-samples repo already cloned and in current directory, # cd fabric-samples and checkout corresponding version echo "===> Checking out v${VERSION} of hyperledger/fabric-samples" cd fabric-samples && git checkout v${VERSION} else echo "===> Cloning hyperledger/fabric-samples repo and checkout v${VERSION}" git clone -b master https://github.com/hyperledger/fabric-samples.git && cd fabric-samples && git checkout v${VERSION} fi }
其實就是將 fabric-samples
源碼克隆到當前目錄下,並切換到指定版本:
- git clone --branch v1.4.1 https://github.com/hyperledger/fabric-samples.git
下載可執行二進制文件
下載指定版本的 Hyperledger Fabric
平台特定的二進制文件和配置文件,查看 bootstrap.sh 腳本:
binariesInstall() { echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries" binaryDownload "${BINARY_FILE}" "https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/${ARCH}-${VERSION}/${BINARY_FILE}" if [ $? -eq 22 ]; then echo echo "------> ${FABRIC_TAG} platform specific fabric binary is not available to download <----" echo fi echo "===> Downloading version ${CA_TAG} platform specific fabric-ca-client binary" binaryDownload "${CA_BINARY_FILE}" "https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/${ARCH}-${CA_VERSION}/${CA_BINARY_FILE}" if [ $? -eq 22 ]; then echo echo "------> ${CA_TAG} fabric-ca-client binary is not available to download (Available from 1.1.0-rc1) <----" echo fi }
該腳本從下面兩個鏈接中下載二進制文件,我們直接訪問該頁面,選擇相應的版本下載即可,此處選擇的是 linux-amd64-1.4.3
版本
下載的 hyperledger-fabric-linux-amd64-1.4.1.tar
壓縮包內有 bin 和 config 兩個文件夾,hyperledger-fabric-ca-linux-amd64-1.4.1.tar
壓縮包內有 bin 文件夾,將兩個 bin 文件夾內的二進制文件匯總在一個 bin 文件夾內。 最后將 bin 和 config 文件夾復制到 fabric-samples
文件夾內。
賦予可執行權限
- chmod +x -R
fabric-samples
/bin
由於上面鏈接無法訪問,可以去github相應項目中下載。
- https://github.com/hyperledger/fabric/releases/download/v1.4.1/hyperledger-fabric-linux-amd64-1.4.1.tar.gz
- https://github.com/hyperledger/fabric-ca/releases/download/v1.4.1/hyperledger-fabric-ca-linux-amd64-1.4.1.tar.gz
下載 Docker鏡像
上一個步驟的下載 hyperledger-fabric-linux-amd64-1.4.1.tar
的 bin 文件夾下還有一個 get-docker-images.sh
腳本,可以運行該腳本下載鏡像,但是該腳本不會下載 fabric-ca
和 fabric-javaenv
鏡像,所以不推薦。
轉到 bootstrap.sh
腳本同級目錄下,將 bootstrap.sh
中 174、175行SAMPLES、BINARIES改為false,即不執行下載fabric-samples和下載二進制腳本
執行 bootstrap.sh
腳本:
- ./bootstrap.sh 1.4.1 1.4.1 0.4.15
===> List out hyperledger docker images hyperledger/fabric-ca 1.4.1 3a1799cda5d7 15 months ago 252MB hyperledger/fabric-ca latest 3a1799cda5d7 15 months ago 252MB hyperledger/fabric-tools 1.4.1 432c24764fbb 15 months ago 1.55GB hyperledger/fabric-tools latest 432c24764fbb 15 months ago 1.55GB hyperledger/fabric-ccenv 1.4.1 d7433c4b2a1c 15 months ago 1.43GB hyperledger/fabric-ccenv latest d7433c4b2a1c 15 months ago 1.43GB hyperledger/fabric-orderer 1.4.1 ec4ca236d3d4 15 months ago 173MB hyperledger/fabric-orderer latest ec4ca236d3d4 15 months ago 173MB hyperledger/fabric-peer 1.4.1 a1e3874f338b 15 months ago 178MB hyperledger/fabric-peer latest a1e3874f338b 15 months ago 178MB hyperledger/fabric-javaenv 1.4.1 b8c9d7ff6243 15 months ago 1.74GB hyperledger/fabric-javaenv latest b8c9d7ff6243 15 months ago 1.74GB hyperledger/fabric-zookeeper 0.4.15 20c6045930c8 16 months ago 1.43GB hyperledger/fabric-zookeeper latest 20c6045930c8 16 months ago 1.43GB hyperledger/fabric-kafka 0.4.15 b4ab82bbaf2f 16 months ago 1.44GB hyperledger/fabric-kafka latest b4ab82bbaf2f 16 months ago 1.44GB hyperledger/fabric-couchdb 0.4.15 8de128a55539 16 months ago 1.5GB hyperledger/fabric-couchdb latest 8de128a55539 16 months ago 1.5GB
測試網絡
-
cd ./fabric-samples/first-network/
-
./byfn.sh up
===================== Query successful on peer1.org2 on channel 'mychannel' ===================== ========= All GOOD, BYFN execution completed =========== _____ _ _ ____ | ____| | \ | | | _ \ | _| | \| | | | | | | |___ | |\ | | |_| | |_____| |_| \_| |____/
查看容器docker ps
[root@localhost first-network]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6a655dde5bb0 dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab "chaincode -peer.add…" 13 minutes ago Up 13 minutes dev-peer1.org2.example.com-mycc-1.0 34a8a580a62f dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9 "chaincode -peer.add…" 13 minutes ago Up 13 minutes dev-peer0.org1.example.com-mycc-1.0 1f1587e5c1ac dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b "chaincode -peer.add…" 14 minutes ago Up 14 minutes dev-peer0.org2.example.com-mycc-1.0 a72c28627767 hyperledger/fabric-tools:latest "/bin/bash" 16 minutes ago Up 16 minutes cli d9ffca3a63b8 hyperledger/fabric-peer:latest "peer node start" 17 minutes ago Up 16 minutes 0.0.0.0:8051->8051/tcp peer1.org1.example.com 3eee4e3bb1eb hyperledger/fabric-peer:latest "peer node start" 17 minutes ago Up 16 minutes 0.0.0.0:10051->10051/tcp peer1.org2.example.com e3feeec711e3 hyperledger/fabric-orderer:latest "orderer" 17 minutes ago Up 16 minutes 0.0.0.0:7050->7050/tcp orderer.example.com 94acf9259d41 hyperledger/fabric-peer:latest "peer node start" 17 minutes ago Up 16 minutes 0.0.0.0:9051->9051/tcp peer0.org2.example.com e97bfcc4bd62 hyperledger/fabric-peer:latest "peer node start" 17 minutes ago Up 16 minutes 0.0.0.0:7051->7051/tcp peer0.org1.example.com
關閉網絡
[root@localhost first-network]# ./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 peer1.org1.example.com ... done Stopping peer1.org2.example.com ... done Stopping orderer.example.com ... done Stopping peer0.org2.example.com ... done Stopping peer0.org1.example.com ... done Removing cli ... done Removing peer1.org1.example.com ... done Removing peer1.org2.example.com ... done Removing orderer.example.com ... done Removing peer0.org2.example.com ... done Removing peer0.org1.example.com ... done Removing network net_byfn 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. Removing volume net_orderer2.example.com WARNING: Volume net_orderer2.example.com not found. Removing volume net_orderer.example.com Removing volume net_peer0.org2.example.com Removing volume net_peer0.org1.example.com Removing volume net_peer1.org1.example.com Removing volume net_peer1.org2.example.com Removing volume net_orderer5.example.com WARNING: Volume net_orderer5.example.com not found. Removing volume net_orderer4.example.com WARNING: Volume net_orderer4.example.com not found. Removing volume net_orderer3.example.com WARNING: Volume net_orderer3.example.com not found.
參考:https://www.cnblogs.com/zongmin/p/11635686.html#_label0_4