天天看點

ubuntu 16.04 搭建fabric環境

1、安裝go環境

https://mp.csdn.net/postedit/84666768

2、安裝docker

參考 https://blog.csdn.net/diligent_lee/article/details/79098302

1、更新apt安裝包索引
sudo apt-get update

2、安裝軟體包以允許apt通過HTTPS使用存儲庫:
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

3、添加Docker官方的GPG密鑰:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

4、確定現在系統已經擁有密鑰指紋的後八個字元串:9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
輸入指令:sudo apt-key fingerprint 0EBFCD88

顯示結果
pub 4096R/0EBFCD88 2017-02-22 密鑰指紋 = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C    0EBF CD88 uid Docker Release (CE deb) <[email protected]> sub 4096R/F273FCD8 2017-02-22

5、更新apt安裝包索引:

sudo apt-get update

6、安裝最新版的Docker CE:
sudo apt-get install docker.io

7、通過運作hello-world鏡像驗證Docker CE已被正确安裝:
sudo docker run hello-world
8、若出現以下資訊則表明安裝成功:
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world ca4f61b1923c: Pull complete Digest: sha256:66ef312bbac49c39a89aa9bcc3cb4f3c9e7de3788c944158df3ee0176d32b751 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/

9、檢查版本資訊:

sudo docker version


Client: Version: 17.12.0-ce API version: 1.35 Go version: go1.9.2 Git commit: c97c6d6 Built: Wed Dec 27 20:11:19 2017 OS/Arch: linux/amd64 
Server: Engine: Version: 17.12.0-ce API version: 1.35 (minimum version 1.12) Go version: go1.9.2 Git commit: c97c6d6 Built: Wed Dec 27 20:09:53 2017 OS/Arch: linux/amd64 Experimental: false

10、以非root使用者身份管理Docker

建立docke組
sudo groupadd docker
将自己的使用者添加到docker組中:
sudo usermod -aG docker 使用者名
登出并重新登陸以重新驗證組成員關系
sudo service docker restart
驗證不需要sudo運作docker指令
docker run hello-world

sudo systemctl enable docker
           

安裝docker-compose

sudo apt-get install python-pip
sudo pip install docker-compose
           

3、下載下傳源碼

git clone https://github.com/hyperledger/fabric.git
cd fabric
cd scripts
./bootstrap.sh
           

稍等一會,鏡像下載下傳完畢

進入fabric/examples/e2e_cli目錄
./network_setup.sh up

等待啟動成功

           

4、重新打開一個指令行視窗,輸入

docker exec -it cli bash
           
查詢賬戶a的餘額
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
查詢賬戶b的餘額
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","b"]}'
賬戶a向賬戶b轉賬
peer chaincode invoke -o orderer.example.com:7050  --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem  -C mychannel -n mycc -c '{"Args":["invoke","b","a","100"]}'

再次查詢賬戶餘額
           

5、退出cli容器  關閉fabric網絡

exit


./network_setup.sh down