简体   繁体   English

Hyperledger-fabric 不适用于 docker swarm

[英]Hyperledger-fabric not working with docker swarm

I 'm using the Fabric 1.1 alpha release and trying to set it up using docker swarm.我正在使用 Fabric 1.1 alpha 版本并尝试使用 docker swarm 进行设置。 I 'm using docker compose files with docker stack to deploy the containers.我正在使用 docker compose 文件和 docker stack 来部署容器。

The issue I 'm having is my chaincode listening port which is 7052 hardcoded somewhere in the peer container is not listening on docker swarm.我遇到的问题是我的链码侦听端口是 7052 硬编码在对等容器中的某处没有侦听 docker swarm。

The same compose file with minor changes work, if I don't use docker swarm.如果我不使用 docker swarm,则具有较小更改的相同撰写文件可以工作。

I 'm not sure if it's something wrong with the peer itself or with docker-swarm.我不确定对等方本身或 docker-swarm 是否有问题。

This is from my peer container, which clearly is not allowing any connections on 7052 port.这是来自我的对等容器,它显然不允许 7052 端口上的任何连接。

root@71c1b8f22052:/opt/gopath/src/github.com/hyperledger/fabric/peer# telnet 10.0.0.6 7051
Trying 10.0.0.6...
Connected to 10.0.0.6.
Escape character is '^]'.
^CConnection closed by foreign host.
root@71c1b8f22052:/opt/gopath/src/github.com/hyperledger/fabric/peer# telnet 10.0.0.6 7052
Trying 10.0.0.6...
telnet: Unable to connect to remote host: Connection refused
root@71c1b8f22052:/opt/gopath/src/github.com/hyperledger/fabric/peer# telnet 10.0.0.6 7053
Trying 10.0.0.6...
Connected to 10.0.0.6.
Escape character is '^]'.
^CConnection closed by foreign host.

But it's listening on 7052 port.但它正在监听 7052 端口。

root@71c1b8f22052:/opt/gopath/src/github.com/hyperledger/fabric/peer# netstat -nalp | grep 7052
tcp        0      0 10.0.0.6:7052           0.0.0.0:*               LISTEN      7/peer         

I 'm getting this in my chaincode container logs, when I 'm instantiating the chaincode.当我实例化链码时,我在我的链码容器日志中得到了这个。

2018-02-06 09:45:11.886 UTC [bccsp] initBCCSP -> DEBU 001 Initialize BCCSP [SW]
2018-02-06 09:45:11.906 UTC [grpc] Printf -> DEBU 002 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: Error while dialing dial tcp 10.0.0.10:7052: getsockopt: connection refused"; Reconnecting to {peer0.org1.example.com:7052 <nil>}
2018-02-06 09:45:12.905 UTC [grpc] Printf -> DEBU 003 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: Error while dialing dial tcp 10.0.0.10:7052: getsockopt: connection refused"; Reconnecting to {peer0.org1.example.com:7052 <nil>}
2018-02-06 09:45:14.612 UTC [grpc] Printf -> DEBU 004 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: Error while dialing dial tcp 10.0.0.10:7052: getsockopt: connection refused"; Reconnecting to {peer0.org1.example.com:7052 <nil>}
2018-02-06 09:45:14.904 UTC [shim] userChaincodeStreamGetter -> ERRO 005 context deadline exceeded
error trying to connect to local peer
github.com/hyperledger/fabric/core/chaincode/shim.userChaincodeStreamGetter
        /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim/chaincode.go:111
github.com/hyperledger/fabric/core/chaincode/shim.Start
        /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim/chaincode.go:150
main.main
        /chaincode/input/src/github.com/chaincode/alepomm/alepomm.go:355
runtime.main
        /opt/go/src/runtime/proc.go:195
runtime.goexit
        /opt/go/src/runtime/asm_amd64.s:2337
Error creating new Smart Contract: error trying to connect to local peer: context deadline exceeded

^^Ignore the timestamp and Ip here, the logs are from diff runs. ^^此处忽略时间戳和 Ip,日志来自差异运行。 But it happens the same everytime.但它每次都会发生。

Here is my compose section for the peer.这是我为同行撰写的部分。

  peer0:
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      # the following setting starts chaincode containers on the same
      # bridge network as the peers
      # https://docs.docker.com/compose/networking/
      - CORE_CHAINCODE_LOGGING_LEVEL=DEBUG
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fabric
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb0:5984
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
      - CORE_PEER_ID=peer0.org1.example.com
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
#      - CORE_PEER_ADDRESSAUTODETECT=true
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    volumes:
        - /var/run/:/host/var/run/
        - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp
        - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
    ports:
     - 7051:7051
     - 7053:7053
    expose:
     - 7051
     - 7053
    command: peer node start
    depends_on:
      - couchdb0
    networks:
      fabric:
        aliases:
         - "peer0.org1.example.com"
    deploy:
      placement:
        constraints:
          - node.hostname == ip-172-31-22-132

This is really weird, if I remove the deploy section (which is stack specific) everything works.这真的很奇怪,如果我删除部署部分(特定于堆栈),一切正常。

My n/w is an overlay type n/w with scope of swarm.我的 n/w 是一个覆盖类型 n/w,具有 swarm 范围。

@yacovm, thank you so much for the help! @yacovm,非常感谢您的帮助! The issue was that the chaincode container was not launching on the same network as my peer container and hence it was not able to connect to it.问题是链码容器没有在与我的对等容器相同的网络上启动,因此无法连接到它。 To fix it,要解决这个问题,

CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052 CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052

Was added to the env of my peer containers.已添加到我的对等容器的 env 中。 Now it works like a charm现在它就像一个魅力

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM