【Fabric 1】v1.0环境搭建

基于Ubuntu 16.04

1.安装docker

sudo apt-get install docker.io  //安装docker
docker --version        //查看docker版本,确认是否安装成功
sudo usermod -aG docker ${USER}    //将当前用户加入docker组,使用docker命令时可以不加sudo
user logout - login

2.安装docker-compose

sudo curl -L https://github.com/docker/compose/releases/download/1.17.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose     //授权
docker-compose --version

3.安装golang

wget https://studygolang.com/dl/golang/go1.10.3.linux-amd64.tar.gz  //下载golang安装包
sudo tar -zxvf go1.10.3.linux-amd64.tar.gz -C /opt
/*---make dirs, for fabric net,the dirs must be as following---*/
cd $HOME
mkdir gopath
cd gopath
mkdir bin
mkdir pkg
mkdir src
cd src
mkdir github.com
cd github.com
mkdir hyperledger
/*---------------------------------------------------------------*/
sudo vi /etc/profile    //配置如下环境变量
...
export GOPATH=$HOME/gopath
export GOROOT=/opt/go
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
...
source /etc/profile //载入环境变量
go version      //验证安装是否成功

4.从github下载fabric源码

cd $HOME/gopath/github.com/hyperledger/        //dir should be this
git clone https://github.com/hyperledger/fabric.git
git checkout v1.0.0 //切换到v1.0.0版本,初次练习就用这个稳定版了,也可以使用最新code测试

5.下载fabric docker镜像

cd fabric/examples/e2e_cli/
source download-dockerimages.sh -c x86_64-1.0.0 -f x86_64-1.0.0

6.查看第5步下载的docker镜像

docker images

【Fabric 1】v1.0环境搭建_第1张图片
7.启动fabric网络

sudo ./network_setup.sh up

【Fabric 1】v1.0环境搭建_第2张图片
8.测试fabric网络

//另外打开一个terminal窗口
docker exec -it cli bash    //进入cli
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'   //查看a账户余额
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","a","b","40"]}'  //a向b转账40
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'   //再次查看a账户余额

【Fabric 1】v1.0环境搭建_第3张图片
9.关闭网络

./network_setup.sh down

just go ahead~~~

你可能感兴趣的:(fabric)