centos7安装Hyperledgrt1.0

原创
2017/05/01 11:14
阅读数 260

1、安装docker

#执行代码如下:
curl -sSL https://get.daocloud.io/docker | sh
#安装完成后,查看安装情况:
docker -v

2、安装docker-compose

#先安装Python-pip,具体安装步奏如下:
 

#1.首先安装epel扩展源:
sudo yum -y install epel-release
#2.然后安装python-pip
sudo yum -y install python-pip
#安装完成后,清除以下缓存 cache
sudo yum clean all

下面开始安装Docker-compose

#1.安装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
#2.为docker-compose添加执行权限:
chmod +x /usr/local/bin/docker-compose

3.查看安装情况:

下面配置一下docker镜像加速,目的是下载镜像速度更快:

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://860eaa91.m.daocloud.io
#最后重启一下docker服务:
sudo service docker restart

三、安装git

yum -y install wget unzip  
#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

六、启动集群

#1.首先,下载 Compose 模板文件。
git clone https://github.com/yeasy/docker-compose-files

2.查看下载情况:

3.进入 hyperledger/1.0 目录,查看包括若干模板文件

4.快速 启动一个 MVE fabric 集群:

docker-compose up

5.查看 启动后的容器镜像:

docker ps -a

七、开始部署chaincode

#集群启动后,进入 VP 节点,节点名称为 fabric-cli
docker exec -it fabric-cli bash
#部署example02
peer chaincode  install -v 1.0 -n test_cc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Args":["init","a","100","b","200"]}' -o orderer0:7050

peer chaincode  instantiate -v 1.0 -n test_cc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Args":["init","a","100","b","200"]}' -o orderer0:7050

#这两步很可能会失败,比如报:
Error: Error endorsing invoke: rpc error: code = 2 desc = failed to obtain cds for test_cc - transaction
 not found test_cc/testchainid

Error: Error endorsing chaincode: rpc error: code = 2 desc = Error installing chaincode code test_cc:1.0(chaincode
 /var/hyperledger/production/chaincodes/test_cc.1.0 exits)

#这两个错误,需要把容器删除,重新创建
docker rm `docker ps -a -q`
#反复几次直到提示成功
#查询a和b的值
peer chaincode query -n test_cc -c '{"Args":["query","a"]}' -o orderer0:7050
peer chaincode query -n test_cc -c '{"Args":["query","b"]}' -o orderer0:7050
#a向b转账10
peer chaincode invoke -n test_cc -c '{"Args":["invoke","a","b","10"]}' -o orderer0:7050
#查询a和b的值
peer chaincode query -n test_cc -c '{"Args":["query","a"]}' -o orderer0:7050
peer chaincode query -n test_cc -c '{"Args":["query","b"]}' -o orderer0:7050

到此安装成功!

展开阅读全文
打赏
0
1 收藏
分享
加载中
更多评论
打赏
0 评论
1 收藏
0
分享
返回顶部
顶部