curl -sSL https://get.daocloud.io/docker | sh
docker -v
先安装python-pip,具体安装步奏如下:
sudo yum -y install epel-release
sudo yum -y install python-pip
sudo yum clean all
下面开始安装docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
下面配置一下docker镜像加速,目的是下载镜像速度更快:
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://860eaa91.m.daocloud.io
最后重启一下docker服务:
sudo service docker restart
1.安装依赖包:
sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
2.下载git源码并解压:
$ wget https://github.com/git/git/archive/v2.3.0.zip
$ unzip v2.3.0.zip
$ cd git-2.3.0
3.编译安装:
make prefix=/usr/local/git all
sudo make prefix=/usr/local/git install
4.修改环境变量:
sudo vim /etc/profile
然后在文件的最后一行,添加下面的内容,然后保存退出。
export PATH=/usr/local/git/bin:$PATH
5.使用source命令立即保存:
source /etc/profile
6.查看版本
git version
- 下载镜像命令如下:
docker pull yeasy/hyperledger-fabric-base:latest \
&& docker pull yeasy/hyperledger-fabric-peer:latest \
&& docker pull yeasy/hyperledger-fabric-orderer:latest \
&& docker pull yeasy/hyperledger-fabric-ca:latest \
&& docker pull yeasy/blockchain-explorer:latest \
&& docker tag yeasy/hyperledger-fabric-peer hyperledger/fabric-peer \
&& docker tag yeasy/hyperledger-fabric-orderer hyperledger/fabric-orderer \
&& docker tag yeasy/hyperledger-fabric-ca hyperledger/fabric-ca \
&& docker tag yeasy/hyperledger-fabric-base hyperledger/fabric-baseimage \
&& docker tag yeasy/hyperledger-fabric-base hyperledger/fabric-ccenv:x86_64-1.0.0-preview
- 下载完成后,查看下载镜像
docker images
创建2个docker网络,如下:
docker network create fabric_noops
docker network create fabric_pbft
git clone https://github.com/yeasy/docker-compose-files
docker-compose up
docker ps -a
容器如下:
c10f128ab8f5 hyperledger/fabric-peer "peer node start" 16 hours ago Up 16 hours 7050/tcp, 7052-7059/tcp, 0.0.0.0:7051->7051/tcp fabric-vp0
443083f3b2b9 hyperledger/fabric-orderer "orderer" 16 hours ago Up 16 hours 0.0.0.0:7050->7050/tcp fabric-orderer
08330f858c6f hyperledger/fabric-cop "cop server start ..." 16 hours ago Up 16 hours 0.0.0.0:8888->8888/tcp fabric-cop
容器如图:
docker exec -it fabric-vp0 bash
peer chaincode deploy -n test_cc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Args":["init","a","100","b","200"]}'
peer chaincode invoke -n test_cc -c '{"Args":["query","a"]}'
a的值如下:
peer chaincode invoke -n test_cc -c '{"Args":["query","b"]}'
b的值如下:
交易,a向b转账10元,如下:
peer chaincode invoke -n test_cc -c '{"Args":["invoke","a","b","10"]}'
查询a的值,结果如下:
peer chaincode invoke -n test_cc -c '{"Args":["query","a"]}'
这时“a”的值为:**90** ![这里写图片描述](https://img-blog.csdn.net/20170124115510812?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb2xpYW5nMTEzMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
再次查询b的值,结果如下:
peer chaincode invoke -n test_cc -c '{"Args":["query","b"]}'
这时“b”的值为:**210** ![这里写图片描述](https://img-blog.csdn.net/20170124115633646?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb2xpYW5nMTEzMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) 已经完成超级账本的 转账的实例,每转一次,都会记录一个块。
文件的内容如下:
# This compose file will start a cluster with 1 hyperledger peer nodes
# vp1: validating node as peer
# https://github.com/yeasy/docker-compose-files
version: '2.0'
services:
vp1:
extends:
file: peer.yml
service: peer
container_name: fabric-vp1
hostname: vp1
environment:
- CORE_PEER_ID=vp1
- CORE_PEER_DISCOVERY_ROOTNODE=172.17.0.2:7051
- CORE_PEER_COMMITTER_LEDGER_ORDERER=172.17.0.2:7050
#networks:
# default:
# external:
# name: fabric_pbft
docker-compose -f add-peer.yml up
b67e34917f38 hyperledger/fabric-peer "peer node start" 4 hours ago Up 4 hours 7050-7059/tcp fabric-vp1
b826ea7b9260 hyperledger/fabric-peer "peer node start" 4 hours ago Up 4 hours 7050/tcp, 7052-7059/tcp, 0.0.0.0:7051->7051/tcp fabric-vp0
a35046f53af3 hyperledger/fabric-orderer "orderer" 4 hours ago Up 4 hours 0.0.0.0:7050->7050/tcp fabric-orderer
78acca35125b hyperledger/fabric-ca "fabric-ca server ..." 4 hours ago Up 4 hours 7054/tcp, 0.0.0.0:8888->8888/tcp fabric-ca
说明动态创建已经成功。下面验证一下这些节点是否关联一块。
docker exec -it fabric-vp1 bash
查询a的值为:
peer chaincode invoke -n test_cc -c '{"Args":["query","a"]}'
这时“a”的值为:90
查询b的值为:
peer chaincode invoke -n test_cc -c '{"Args":["query","b"]}'
这时“b”的值为:210
在 fabric-vp1容器里 ,执行交易,a再向b转账10元,如下:
peer chaincode invoke -n test_cc -c '{"Args":["invoke","a","b","10"]}'
在 “fabric-vp1”容器里,查询a的值,结果如下:
peer chaincode invoke -n test_cc -c '{"Args":["query","a"]}'
这时“a”的值为:**80** ![这里写图片描述](https://img-blog.csdn.net/20170206192205707?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb2xpYW5nMTEzMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
再次查询b的值,结果如下:
peer chaincode invoke -n test_cc -c '{"Args":["query","b"]}'
这时“b”的值为:**220** ![这里写图片描述](https://img-blog.csdn.net/20170206192328771?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb2xpYW5nMTEzMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
我们进入 “fabric-vp0”执行查询看看数值是否变化,在vp0容器里查询a的值应该为“80”,b的值应该为“220”。下面我们来验证下:
docker exec -it fabric-vp0 bash
查询a的值为:
peer chaincode invoke -n test_cc -c '{"Args":["query","a"]}'
这时“a”的值为:80,说明已经关联在一起
查询b的值为:
peer chaincode invoke -n test_cc -c '{"Args":["query","b"]}'
这时“b”的值为:220,说明节点是关联在一起的。
查看镜像:
docker images
可以看到vp1也有一个镜像,说明vp1已经创建好容器
查看容器:
docker ps -a
可以看到vp1已经创建好容器
到此,整个Hyperledger Fabric1.0超级账本环境已经部署完成,动态增加节点也已经完成。