如何使用Docker设置具有多个主机的超级账本结构? [英] How can I set up hyperledger fabric with multiple hosts using Docker?

查看:66
本文介绍了如何使用Docker设置具有多个主机的超级账本结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Hyperledger Fabric v1.0,并且希望使设置可在多个主机上使用.现在,2会很棒.

I work on the Hyperledger Fabric v1.0 and would like to make the Getting Setup work on multiple hosts. For now, 2 would be great.

这就是我想做的:

  1. 主机1 :启动一个订购者和2个对等端
  2. 主机2 :开始1个对等方
  3. Host2 :客户端创建一个频道(使用使用良好主机IP更新的channel_test.sh)并加入所有3个对等端
  4. Host1 :调用给定示例的deploy.js来部署链码
  1. Host1: start an orderer and 2 peers
  2. Host2: start 1 peer
  3. Host2: A client creates a channel (using the channel_test.sh updated with the good hosts IP) and join all the 3 peers
  4. Host1: Call de deploy.js of the given example to deploy the chaincode

我在第3步遇到问题.我认为创建频道是可行的,但是在我的对等日志中,我对3个对等警告相同:

I have a problem on the 3rd step. I think the channel creation works but on my peers log I have the same warnings on the 3 peers:

Remote endpoint claims to be a different peer, expected [host1 IP:8051] but got [172.17.0.4:7051]
Failed obtaining connection for 172.31.9.126:8051, PKIid:[49 55 50 ...] reason: Authentication failure

看来他们无法互相交流. 知道问题出在哪里吗?

It looks like they can't communicate with each other. Any idea where the problem is?

我仍然尝试了第4步,但是除非我从config.json中删除host2:peer1,否则我将无法部署它.即使这样,我也只能从host1:peer0进行查询,而不能从host1:peer2进行查询.

I still tried my step 4 but I can't deploy it unless I remove the host2: peer1 from the config.json. And even then, I can only query from the host1: peer0, not the host1: peer2.

以下是我用来设置网络的命令:

Here are the commands I use to set up my network:

主机1:订购者

docker run --rm -it --name orderer -p 8050:7050 
-e ORDERER_GENERAL_LEDGERTYPE=ram 
-e ORDERER_GENERAL_BATCHTIMEOUT=10s 
-e ORDERER_GENERAL_BATCHSIZE_MAXMESSAGECOUNT=10 
-e ORDERER_GENERAL_MAXWINDOWSIZE=1000 
-e ORDERER_GENERAL_ORDERERTYPE=solo 
-e ORDERER_GENERAL_LOGLEVEL=debug 
-e ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 
-e ORDERER_GENERAL_LISTENPORT=7050 
-e ORDERER_RAMLEDGER_HISTORY_SIZE=100 
sfhackfest22017/fabric-orderer:x86_64-0.7.0-snapshot-c7b3fe0 orderer

主机1:对等0

docker run --rm -it --name peer0 -p 8051:7051 -p 8053:7053
-v /var/run/:/host/var/run/ -v $BASE_DIR/tmp/peer0:/etc/hyperledger/fabric/msp/sampleconfig 
-e CORE_PEER_ADDRESSAUTODETECT=true 
-e CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock 
-e CORE_LOGGING_LEVEL=DEBUG 
-e CORE_PEER_NETWORKID=peer0 
-e CORE_NEXT=true 
-e CORE_PEER_ENDORSER_ENABLED=true 
-e CORE_PEER_ID=peer0 
-e CORE_PEER_PROFILE_ENABLED=true 
-e CORE_PEER_COMMITTER_LEDGER_ORDERER=$ORDERER_IP:7050 
-e CORE_PEER_GOSSIP_ORGLEADER=true 
-e CORE_PEER_GOSSIP_IGNORESECURITY=true 
sfhackfest22017/fabric-peer:x86_64-0.7.0-snapshot-c7b3fe0 peer node start --peer-defaultchain=false

主机1:对等2

docker run --rm -it --name peer2 -p 8055:7051 -p 8057:7053 
-v /var/run/:/host/var/run/ -v $BASE_DIR/tmp/peer0:/etc/hyperledger/fabric/msp/sampleconfig
-e CORE_PEER_ID=peer2 
[Other parameters are the same as Peer0]
sfhackfest22017/fabric-peer:x86_64-0.7.0-snapshot-c7b3fe0 peer node start --peer-defaultchain=false

主机2:对等1

docker run --rm -it --name peer1 -p 8051:7051 
-v /var/run/:/host/var/run/ -v $BASE_DIR/tmp/peer0:/etc/hyperledger/fabric/msp/sampleconfig
-e CORE_PEER_ID=peer1 
[Other parameters are the same as Peer0]
sfhackfest22017/fabric-peer:x86_64-0.7.0-snapshot-c7b3fe0 peer node start --peer-defaultchain=false

主机2:Cli

docker run --rm -it --name cli
    -v /var/run/:/host/var/run/ -v $BASE_DIR/tmp/peer3:/etc/hyperledger/fabric/msp/sampleconfig -v $BASE_DIR/src/github.com/example_cc/example_cc.go:/opt/gopath/src/github.com/hyperledger/fabric/examples/example_cc.go -v $BASE_DIR/channel_test.sh:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel_test.sh
    --workdir /opt/gopath/src/github.com/hyperledger/fabric/peer  
    -e GOPATH=/opt/gopath 
    -e CORE_PEER_ADDRESSAUTODETECT=true
    -e CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock 
    -e CORE_LOGGING_LEVEL=DEBUG 
    -e CORE_NEXT=true 
    -e CORE_PEER_ID=cli 
    -e CORE_PEER_ENDORSER_ENABLED=true 
    -e CORE_PEER_COMMITTER_LEDGER_ORDERER=$ORDERER_IP:8050 
    -e CORE_PEER_ADDRESS=$PEER0_IP:8051 
    sfhackfest22017/fabric-peer:x86_64-0.7.0-snapshot-c7b3fe0 ./channel_test.sh

如果您需要更多信息,请随时询问.

If you need more information feel free to ask.

注意:我对docker不太熟悉,欢迎对我的使用方法进行任何改进/建议:)

推荐答案

我找到了一个似乎可以在 docker swarm模式下工作的解决方案.

I found a solution that seems to work using docker swarm mode.

  1. 初始化群组:( docker群组文档了解更多信息)
  2. 与其他主持人一起加入群组
  3. 创建网络(在我的情况下为"hyp-net")

  1. Initialize a swarm: (docker swarm documentation for mor information)
  2. Join the swarm with the other host as a manager
  3. Create a network ("hyp-net" in my case)

docker network create --attachable --driver overlay hyp-net

我必须做的更改:

  • 使用-link docker参数
  • 链接容器
  • 添加了-network 泊坞参数(--network = hyp-net)
  • 为使用的docker run命令添加了一个新的环境变量:

  • Linked the containers with the --link docker parameter
  • Added the --network docker parameter (--network=hyp-net)
  • Added a new environment varialble todocker run command used:

-e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=hyp-net

以下是对我有用的命令:

Here are the commands that works for me:

订购者

docker run --rm -it --network="hyp-net" --name orderer -p 8050:7050 
-e ORDERER_GENERAL_LEDGERTYPE=ram 
-e ORDERER_GENERAL_BATCHTIMEOUT=10s 
-e ORDERER_GENERAL_BATCHSIZE_MAXMESSAGECOUNT=10 
-e ORDERER_GENERAL_MAXWINDOWSIZE=1000 
-e ORDERER_GENERAL_ORDERERTYPE=solo 
-e ORDERER_GENERAL_LOGLEVEL=debug 
-e ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 
-e ORDERER_GENERAL_LISTENPORT=7050 
-e ORDERER_RAMLEDGER_HISTORY_SIZE=100 
-e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=hyp-net 
sfhackfest22017/fabric-orderer:x86_64-0.7.0-snapshot-c7b3fe0 orderer

Peer0

docker run --rm -it --link orderer:orderer --network="hyp-net" --name peer0 -p 8051:7051 -p 8053:7053 
-v /var/run/:/host/var/run/ -v $BASE_DIR/tmp/peer0:/etc/hyperledger/fabric/msp/sampleconfig  
-e CORE_PEER_ADDRESSAUTODETECT=true 
-e CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock 
-e CORE_LOGGING_LEVEL=DEBUG 
-e CORE_PEER_NETWORKID=peer0 
-e CORE_NEXT=true 
-e CORE_PEER_ENDORSER_ENABLED=true 
-e CORE_PEER_ID=peer0 
-e CORE_PEER_PROFILE_ENABLED=true
-e CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 
-e CORE_PEER_GOSSIP_ORGLEADER=true 
-e CORE_PEER_GOSSIP_IGNORESECURITY=true 
-e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=hyp-net 
sfhackfest22017/fabric-peer:x86_64-0.7.0-snapshot-c7b3fe0 peer node start --peer-defaultchain=false

Peer1

docker run --rm -it --network="hyp-net" --link orderer:orderer --link peer0:peer0 [...] -e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=hyp-net sfhackfest22017/fabric-peer:x86_64-0.7.0-snapshot-c7b3fe0 peer node start --peer-defaultchain=false

Peer2

docker run --rm -it --network="hyp-net" --link orderer:orderer --link peer0:peer0 --link peer1:peer1 [...] -e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=hyp-net sfhackfest22017/fabric-peer:x86_64-0.7.0-snapshot-c7b3fe0 peer node start --peer-defaultchain=false

Cli

docker run --rm -it --network="hyp-net" --link orderer:orderer --link peer0:peer0 --link peer1:peer1 --link peer2:peer2 [...] -e CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=hyp-net sfhackfest22017/fabric-peer:x86_64-0.7.0-snapshot-c7b3fe0 ./channel_test.sh

有了这个,我就能部署,调用和查询我的链码了.

With this, I am able to deploy, invoke and query my chaincode.

这篇关于如何使用Docker设置具有多个主机的超级账本结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆