如何将 hyperledger fabric 对等点(第 2、第 3、第 4)映射到用于 REST 通信的端口

How to map hyperledger fabric peers (2nd, 3rd , 4th) with ports for REST communication

我使用 docker-Toolbox 在 Windows 7 64 位 OS 上设置了 hyperledger fabric 0.6 环境,我正在使用 REST API 客户端来触发请求。以下是我的四个同行-ca.yamldocker撰写的文件:-

version: "2"
services: baseimage: image: hyperledger/fabric-baseimage:latest

membersrvc:
  image: hyperledger/fabric-membersrvc

  ports:
    - "7054:7054"

  command: membersrvc

  environment:

    - MEMBERSRVC_CA_LOGGING_SERVER=INFO
    - MEMBERSRVC_CA_LOGGING_CA=INFO
    - MEMBERSRVC_CA_LOGGING_ECA=INFO
    - MEMBERSRVC_CA_LOGGING_ECAP=INFO
    - MEMBERSRVC_CA_LOGGING_ECAA=INFO
    - MEMBERSRVC_CA_LOGGING_ACA=INFO
    - MEMBERSRVC_CA_LOGGING_ACAP=INFO
    - MEMBERSRVC_CA_LOGGING_TCA=INFO
    - MEMBERSRVC_CA_LOGGING_TCAP=INFO
    - MEMBERSRVC_CA_LOGGING_TCAA=INFO
    - MEMBERSRVC_CA_LOGGING_TLSCA=INFO

vp0:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "7050:7050"
    - "7051:7051"
    - "7053:7053"

  environment:
    - CORE_PEER_ID=vp0
    - CORE_SECURITY_ENROLLID=test_vp0
    - CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4

  command: sh -c "sleep 10; peer node start"
  links: - membersrvc

vp1:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "8050:7050"
    - "8051:7051"
    - "8053:7053"
  environment:
    - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
    - CORE_PEER_ID=vp1
    - CORE_SECURITY_ENROLLID=test_vp1
    - CORE_SECURITY_ENROLLSECRET=5wgHK9qqYaPy
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4
  links: - membersrvc - vp0
  command: sh -c "sleep 10; peer node start"

vp2:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "9050:7050"
    - "9051:7051"
    - "9053:7053"
  environment:
    - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
    - CORE_PEER_ID=vp2
    - CORE_SECURITY_ENROLLID=test_vp2
    - CORE_SECURITY_ENROLLSECRET=vQelbRvja7cJ
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4
  links: - membersrvc - vp0
  command: sh -c "sleep 10; peer node start"

vp3:
  image: hyperledger/fabric-peer
  volumes: - /var/run/docker.sock:/var/run/docker.sock
  ports:
    - "10050:7050"
    - "10051:7051"
    - "10053:7053"
  environment:
    - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
    - CORE_PEER_ID=vp3
    - CORE_SECURITY_ENROLLID=test_vp3
    - CORE_SECURITY_ENROLLSECRET=9LKqKH5peurL
    - CORE_PEER_DISCOVERY_PERIOD=60s
    - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
    - CORE_PBFT_GENERAL_MODE=batch
    - CORE_PBFT_GENERAL_N=4
  links: - membersrvc - vp0
  command: sh -c "sleep 10; peer node start"**

//------------ 使用 docker-compose up 命令,我的服务器已启动并且所有 4 个对等点都已成功创建。 在另一个 docker 终端中,我执行了以下命令,该命令也运行良好:

CORE_CHAINCODE_ID_NAME=mycc006 CORE_PEER_ADDRESS=192.168.99.100:7051 ./chaincode_example02

因为我只使用 docker 工具箱,192.168.99.100 是 CORE_PEER_ADDRESS.

可接受的 IP 地址

REST API 请求仅响应 - 192.168.99.100:7050/所有操作的链代码

在上面的docker-compose文件中可以看到,我已经将vp1、vp2、vp3映射到不同的端口,并转发到vp0。

但是当我尝试使用任何其他对等点时,例如 vp1 使用 192.168.99.100:8050/chaincode 请求失败,因为 vp1、vp2、vp3 没有响应,即使我已经专门映射了这些对等点的端口. Docker ps 命令显示 memersrvc 和所有 4 个对等容器 运行 但端口仅分配给 vp0。

如何将其他对等点 vp1、vp2、vp3 映射到端口以便通过 REST API 访问它们?任何帮助或指导将不胜感激。

谢谢。

你的 docker-compose 文件看起来不错,除了映射中的一些小问题,我猜这些问题与 Whosebug 上的渲染有关。 问题是 REST 端点根本不工作吗?例如 http://localhost:10050/chain 无法访问吗?如果是这样,您可能需要确保您使用的是正确的图像 hyperledger/fabric-peer:x86_64-0.6.1-preview 因为 docker-compose 文件也适用于 1.0-alpha 图像,但 REST API 丢失。 我在下面附加的稍微修改过的 docker-compose 文件开箱即用。如果这解决了您的问题,您必须查看 docker 图像并查看 latest 标签指向的位置。

version: "2"
services: # baseimage: image: hyperledger/fabric-baseimage:latest

  membersrvc:
    image: hyperledger/fabric-membersrvc

    ports:
      - "7054:7054"

    command: membersrvc

    environment:

      - MEMBERSRVC_CA_LOGGING_SERVER=INFO
      - MEMBERSRVC_CA_LOGGING_CA=INFO
      - MEMBERSRVC_CA_LOGGING_ECA=INFO
      - MEMBERSRVC_CA_LOGGING_ECAP=INFO
      - MEMBERSRVC_CA_LOGGING_ECAA=INFO
      - MEMBERSRVC_CA_LOGGING_ACA=INFO
      - MEMBERSRVC_CA_LOGGING_ACAP=INFO
      - MEMBERSRVC_CA_LOGGING_TCA=INFO
      - MEMBERSRVC_CA_LOGGING_TCAP=INFO
      - MEMBERSRVC_CA_LOGGING_TCAA=INFO
      - MEMBERSRVC_CA_LOGGING_TLSCA=INFO

  vp0:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes: 
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "7050:7050"
      - "7051:7051"
      - "7053:7053"

    environment:
      - CORE_PEER_ID=vp0
      - CORE_SECURITY_ENROLLID=test_vp0
      - CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4

    command: sh -c "sleep 10; peer node start"
    links: 
      - membersrvc

  vp1:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes: 
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "8050:7050"
      - "8051:7051"
      - "8053:7053"
    environment:
      - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
      - CORE_PEER_ID=vp1
      - CORE_SECURITY_ENROLLID=test_vp1
      - CORE_SECURITY_ENROLLSECRET=5wgHK9qqYaPy
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4
    links: 
      - membersrvc 
      - vp0
    command: sh -c "sleep 10; peer node start"

  vp2:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes: 
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "9050:7050"
      - "9051:7051"
      - "9053:7053"
    environment:
      - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
      - CORE_PEER_ID=vp2
      - CORE_SECURITY_ENROLLID=test_vp2
      - CORE_SECURITY_ENROLLSECRET=vQelbRvja7cJ
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4
    links: 
      - membersrvc 
      - vp0
    command: sh -c "sleep 10; peer node start"

  vp3:
    image: hyperledger/fabric-peer:x86_64-0.6.1-preview
    volumes: 
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "10050:7050"
      - "10051:7051"
      - "10053:7053"
    environment:
      - CORE_PEER_DISCOVERY_ROOTNODE=vp0:7051
      - CORE_PEER_ID=vp3
      - CORE_SECURITY_ENROLLID=test_vp3
      - CORE_SECURITY_ENROLLSECRET=9LKqKH5peurL
      - CORE_PEER_DISCOVERY_PERIOD=60s
      - CORE_PEER_DISCOVERY_TOUCHPERIOD=61s
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
      - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
      - CORE_SECURITY_ENABLED=true
      - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft
      - CORE_PBFT_GENERAL_MODE=batch
      - CORE_PBFT_GENERAL_N=4
    links: 
      - membersrvc 
      - vp0
    command: sh -c "sleep 10; peer node start"