centos7快速搭建一个Fabric 1.0的环境

安装docker

yum -y install docker
docker version
启用docker官方中国区加速器:
vim /etc/sysconfig/docker
--registry-mirror=https://registry.docker-cn.com
service docker start

安装docker-compose

yum -y install epel-release
yum -y install python-pip
pip install --upgrade pip
pip install docker-compose

安装go

wget https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz
tar -xvf go1.8.3.linux-amd64.tar.gz
mv go /usr/local/
mkdir -p /root/golang
vim /etc/profile
export GOPATH=/root/golang
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
source /etc/profile
ln -s $GOPATH /opt/gopath

安装git

yum -y install git

Fabric源码下载

git clone https://github.com/hyperledger/fabric $GOPATH/src/github.com/hyperledger/fabric
git clone https://github.com/hyperledger/fabric-ca $GOPATH/src/github.com/hyperledger/fabric-ca

go get github.com/hyperledger/fabric
go get github.com/hyperledger/fabric-ca

Fabric Docker镜像下载

cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/
source download-dockerimages.sh -c x86_64-1.0.0 -f x86_64-1.0.0

启动Fabric网络并完成ChainCode测试

cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/
./network_setup.sh up
  1编译生成Fabric公私钥、证书的程序,程序在目录:fabric/release/linux-amd64/bin
  2基于configtx.yaml生成创世区块和通道相关信息,并保存在channel-artifacts文件夹。
  3基于crypto-config.yaml生成公私钥和证书信息,并保存在crypto-config文件夹中。
  4基于docker-compose-cli.yaml启动1Orderer+4Peer+1CLI的Fabric容器。
  5在CLI启动的时候,会运行scripts/script.sh文件,这个脚本文件包含了创建Channel,加入Channel,安装Example02,运行Example02等功能。

手动测试一下Fabric网络

docker exec -it cli bash
以下命令可以查询a账户的余额
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
把a账户的余额再转20元给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","a","b","20"]}'
查询a账户的余额
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'

关闭Fabric网络

cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/
./network_setup.sh down

参考文档

快速搭建一个Fabric 1.0的环境
http://www.cnblogs.com/studyzy/p/7437157.html

推荐阅读更多精彩内容