一、安装docker

执行代码如下:curl -sSL https://get.daocloud.io/docker | sh

安装完成后,查看安装情况:

docker -v



  • 修改docker服务配置,
  • 服务配置的意思是 开启docker远程配置,如下:
DOCKER_OPTS="$DOCKER_OPTS -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --api-cors-header='*'"
 
 
  • 1
  • 1
  • 重启docker服务
sudo service docker restart
 
 
  • 1
  • 1

二、安装docker-compose

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

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

下面开始安装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
 
 
  • 1
  • 1
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
 
 
  • 1
  • 1

重启docker服务:

sudo service docker restart

2:下载镜像

docker pull yeasy/hyperledger-fabric-base:0.8.1 \
  && docker pull yeasy/hyperledger-fabric-peer:0.8.1 \
  && docker pull yeasy/hyperledger-fabric-orderer:0.8.1 \
  && docker pull yeasy/hyperledger-fabric-ca:0.8.1 \
  && docker pull yeasy/blockchain-explorer:latest \
  && docker tag yeasy/hyperledger-fabric-peer:0.8.1 hyperledger/fabric-peer \
  && docker tag yeasy/hyperledger-fabric-orderer:0.8.1 hyperledger/fabric-orderer \
  && docker tag yeasy/hyperledger-fabric-ca:0.8.1 hyperledger/fabric-ca \
  && docker tag yeasy/hyperledger-fabric-base:0.8.1 hyperledger/fabric-baseimage \
  && docker tag yeasy/hyperledger-fabric-base:0.8.1 hyperledger/fabric-ccenv:x86_64-1.0.0-snapshot-preview

3:设置网络

docker network create fabric_noops
docker network create fabric_pbft


4:安装git

 yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
 
 
  • 1
wget https://github.com/git/git/archive/v2 .3 .0 .zip

unzip v2.3.0.zip$ cd git-2.3.0

make prefix=/usr/local/git all

make prefix=/usr/local/git install


vim /etc/profile

然后在文件的最后一行,添加下面的内容,然后保存退出。

export PATH=/usr/local/git/bin:$PATH

生效变量

source /etc/profile

查看版本



5:下载compose模板文件

git clone https://github.com/yeasy/docker-compose-files

进入 hyperledger/1.0


6:开始一个 MVE fabric cluster.

docker-compose -f docker-compose.yml up

查看fabric cluster状态


这个地方,第一次执行时,可能他的ip地址会是172网段,所以不能用

需要重启所有容器

docker restart fabric-peer0 fabric-ca fabric-orderer

再次查看


现在网络状态正确了

7:开始测试chaincode

hyperledger 1.0没得deploy,改成install和instantiate了

执行

docker exec -it fabric-peer0 bash

进入后

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"]}'


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"]}'

这两步很可能会失败,比如报:

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`
反复几次直到提示:

root@peer0:/go/src/github.com/hyperledger/fabric# 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"]}'
2017-02-20 06:07:49.175 UTC [container] WriteGopathSrc -> INFO 001 rootDirectory = /go/src
2017-02-20 06:07:49.176 UTC [container] WriteFolderToTarPackage -> INFO 002 rootDirectory = /go/src
Installed remotely response:<status:200 payload:"OK" > 
2017-02-20 06:07:51.906 UTC [main] main -> INFO 003 Exiting.....
root@peer0:/go/src/github.com/hyperledger/fabric# 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"]}'
2017-02-20 06:08:10.401 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2017-02-20 06:08:10.402 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2017-02-20 06:08:10.789 UTC [SW_BCCSP] createKeyStoreIfNotExists -> INFO 003 KeyStore path [/tmp] missing [true]: [<clean>]
2017-02-20 06:08:10.790 UTC [main] main -> INFO 004 Exiting.....
root@peer0:/go/src/github.com/hyperledger/fabric# peer chaincode invoke -n test_cc -c '{"Args":["query","a"]}'
2017-02-20 06:08:49.241 UTC [SW_BCCSP] createKeyStoreIfNotExists -> INFO 001 KeyStore path [/tmp] missing [true]: [<clean>]
2017-02-20 06:08:49.242 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 002 Invoke result: version:1 response:<status:200 message:"OK" payload:"100" > payload:"\n #\216\315\261\351;\347\312\266PWVow\254\010-\027s\332\300=\206+\320w\333\3514\301\225p\0224\n(\002\004lccc\001\007test_cc\004\001\001\001\001\000\000\007test_cc\001\001a\004\001\001\001\001\000\000\032\010\010\310\001\032\003100" endorsement:<endorser:"\n\007DEFAULT\022\232\007-----BEGIN -----\nMIICjDCCAjKgAwIBAgIUBEVwsSx0TmqdbzNwleNBBzoIT0wwCgYIKoZIzj0EAwIw\nfzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh\nbiBGcmFuY2lzY28xHzAdBgNVBAoTFkludGVybmV0IFdpZGdldHMsIEluYy4xDDAK\nBgNVBAsTA1dXVzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMTYxMTExMTcwNzAw\nWhcNMTcxMTExMTcwNzAwWjBjMQswCQYDVQQGEwJVUzEXMBUGA1UECBMOTm9ydGgg\nQ2Fyb2xpbmExEDAOBgNVBAcTB1JhbGVpZ2gxGzAZBgNVBAoTEkh5cGVybGVkZ2Vy\nIEZhYnJpYzEMMAoGA1UECxMDQ09QMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\nHBuKsAO43hs4JGpFfiGMkB/xsILTsOvmN2WmwpsPHZNL6w8HWe3xCPQtdG/XJJvZ\n+C756KEsUBM3yw5PTfku8qOBpzCBpDAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYw\nFAYIKwYBBQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFOFC\ndcUZ4es3ltiCgAVDoyLfVpPIMB8GA1UdIwQYMBaAFBdnQj2qnoI/xMUdn1vDmdG1\nnEgQMCUGA1UdEQQeMByCCm15aG9zdC5jb22CDnd3dy5teWhvc3QuY29tMAoGCCqG\nSM49BAMCA0gAMEUCIDf9Hbl4xn3z4EwNKmilM9lX2Fq4jWpAaRVB97OmVEeyAiEA\n25aDPQHGGq2AvhKT0wvt08cX1GTGCIbfmuLpMwKQj38=\n-----END -----\n" signature:"0D\002 HV\322\245\324\033\225i;\034\231\216\307\320\344)\374\004\001\276\003\351r\220\222\363\345\260\n\013XX\002 oXU\332\245\213\330\r~GX\261\244\265\265\331y\337\3708\356*\0313pXq\202\310\332\027\314" > 
2017-02-20 06:08:49.242 UTC [main] main -> INFO 003 Exiting.....


环境搭建成功






Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐