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

猜你喜欢

转载自blog.csdn.net/mozai147/article/details/84727178
今日推荐