1. 程式人生 > >fabric V1.1 網路及sdk nodejs搭建手冊

fabric V1.1 網路及sdk nodejs搭建手冊

0.許可權 獲取管理員許可權: $ sudo passwd #設定root密碼 $ su #切換到root使用者

1.基礎工具準備 1.1.git $ apt install git 1.2.curl $ apt install curl 1.3.pip $ apt install python-pip $ pip install --upgrade pip 1.4.vim $ apt install vim

2.安裝docker和docker compose 2.0.解除安裝舊版本 如果有的話,解除安裝舊版本 $ apt remove docker docker-engine docker.io

2.1.安裝docker 1].設定docker儲存庫 $ apt -y install apt-transport-https ca-certificates 2].新增docker的GPG金鑰,並新增倉庫 $ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add $ sudo add-apt-repository “deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable” 3].更新apt軟體包 $ apt update 4].安裝 $ apt install docker-ce 5].docker版本 $ docker version 2.2.安裝docker-compose 從github下載docker-compose二進位制檔案 $ curl -L
https://github.com/docker/compose/releases/download/1.21.2/docker-compose-
uname -s-uname -m -o /usr/local/bin/docker-compose $ chmod +x /usr/local/bin/docker-compose 檢查docker-compose版本 $ docker-compose version 2.3.docker 常用命令 刪除一個容器:docker rm 強制刪除一個容器:docker rm -f 強制刪除全部容器:docker rm -f $(docker ps -aq) 殺死所有正在執行的容器:docker kill $(docker ps -a -q) 刪除所有已經停止的容器:docker rm $(docker ps -a -q) 刪除所有映象:docker rmi $(docker images -q) 強制刪除所有映象:docker rmi -f $(docker images -q) 2.4.新增國內映象下載源 修改docker hub的映象,編輯/etc/docker/daemon.json檔案,沒有就建立一個,需要管理員提權,寫入以下內容: { “registry-mirrors”: [“
https://registry.docker-cn.com
”] } 重啟docker服務生效: sudo service docker restart,這樣docker就可以從國內映象站進行pull操作,大大提高了pull image的速度。

3.安裝go 3.1.下載安裝包 可前往這裡下載最新版安裝包,當前版本為go1.10.3.linux-amd64.tar.gz 3.2.解壓 $ tar -C /usr/local -zxf go1.10.3.linux-amd64.tar.gz 3.3.配置環境變數 1].開啟/etc/profile $ vim /etc/profile 2].寫入環境變數

Go environment

export PATH=$PATH:/usr/local/go/bin export GOPATH=/opt/gopath 然後ESC,:wq儲存退出。 3].環境變數生效 $ source /etc/profile 3.4.檢視go版本 $ go version

4.安裝nodejs 4.1 更新ubuntu軟體源 sudo apt-get update sudo apt-get install -y python-software-properties software-properties-common sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update 4.2 安裝nodejs sudo apt-get install nodejs sudo apt install nodejs-legacy sudo apt install npm 4.3 更新npm的包映象源,方便快速下載 sudo npm config set registry https://registry.npm.taobao.org sudo npm config list 4.4全域性安裝n管理器(用於管理nodejs版本) sudo npm install n -g 4.5安裝最新的nodejs(stable版本) sudo n stable sudo node -v v10.8.0 5.下載fabric程式碼和fabric-samples程式碼 5.1.構建資料夾目錄 $ mkdir -p /opt/gopath/src/github.com/hyperledger/ 5.2.下載程式碼 5.2.1.fabric 1].下載fabric程式碼 $ cd /opt/gopath/src/github.com/hyperledger/ $ git clone https://github.com/hyperledger/fabric.git 2].進入fabric $ cd fabric 3].切換程式碼分之 $ git checkout release-1.1 5.2.2 fabric-simples 1].下載fabric-simples程式碼 $ cd /opt/gopath/src/github.com/hyperledger/ $ git clone https://github.com/hyperledger/fabric-samples.git 2].進入fabric-samples $ cd fabric-samples 3].切換程式碼分支 $ git checkout release-1.1 5.3.下載docker映象 $ cd /opt/gopath/src/github.com/hyperledger/fabric/scripts $ ./bootstrap.sh 5.4.檢視已安裝的docker images $ docker images 5.5.拉取二進位制執行程式 1].手動下載檔案 $ cd /opt/gopath/src/github.com/hyperledger/fabric-samples $ 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 $ tar -zxvf hyperledger-fabric-linux-amd64-1.1.0.tar.gz 2].將二進位制檔案寫入環境變數 $ cd bin $ pwd $ vim /etc/profile 寫入如下內容: export PATH=/opt/gopath/src/github.com/hyperledger/fabric-samples/bin:$PATH 3].使環境變數生效 $ source /etc/profile 6.測試fabric-simples 6.1.啟動 $ cd /opt/gopath/src/github.com/hyperledger/fabric-simaples/fabcar $ ./startFabric.sh 6.2 安裝sdk npm install node-gyp npm install node-pre-gyp npm install grpc sudo npm install 6.3.測試 1].新增管理員 $ node enrollAdmin.js 結果: [email protected]:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar# node enrollAdmin.js Store path:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar/hfc-key-store Successfully enrolled admin user “admin” Assigned the admin user to the fabric client … 2].註冊使用者 $ node registerUser.js 結果: [email protected]:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar# node registerUser.js Store path:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar/hfc-key-store Successfully loaded admin from persistence Successfully registered user1 - secret:YuarHrEEygUw Successfully enrolled member user “user1” User1 was successfully registered and enrolled and is ready to intreact with the fabric network 3].查詢docker $ node query.js docker 結果: [email protected]:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar# node query.js docker Store path:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar/hfc-key-store Successfully loaded user1 from persistence Query has completed, checking results