无法通过NodeJS查询/调用Hyperledger Fabric对等体(在Docker集群网络中)-GRPC / S截止日期错误

时间:2019-03-25 13:48:27

标签: docker hyperledger-fabric hyperledger grpc

过程 我已经通过CLI安装,查询,调用了fabcar chaincode。一切都成功了。

enrolAdmin.js和registerUser.js成功运行。

但是,当我运行 query.js 时,出现以下错误

错误

error: [Remote.js]: Error: Failed to connect before the deadline URL:grpc://192.168.56.171:7051
error: [Remote.js]: Error: Failed to connect before the deadline URL:grpc://192.168.56.171:8051
error: [Network]: _initializeInternalChannel: Unable to initialize channel. Attempted to contact 2 Peers. Last error was Error: Failed to connect before the deadline URL:grpc://192.168.56.171:8051
Failed to evaluate transaction: Error: Unable to initialize channel. Attempted to contact 2 Peers. Last error was Error: Failed to connect before the deadline URL:grpc://192.168.56.171:8051

仅供参考-在禁用和启用TLS的情况下,我进行了相同的测试。仍然失败

环境 我已经扩展了Hyperledger Fabric第一网络e2e,以便在docker swarm的帮助下在多个主机中工作。

连接配置文件( TLS),如下所示

{
    "name": "first-network",
    "version": "1.0.0",
    "client": {
        "organization": "Org1",
        "connection": {
            "timeout": {
                "peer": {
                    "endorser": "300"
                },
                "orderer": "300"
            }
        }
    },
    "channels": {
        "mychannel": {
            "orderers": [
                "orderer.example.com",
            ],
            "peers": {
                "peer0.org1.example.com": {},
                "peer1.org1.example.com": {},
                "peer0.org2.example.com": {},
                "peer1.org2.example.com": {}
            }
        }
    },
    "organizations": {
        "Org1": {
            "mspid": "Org1MSP",
            "peers": [
                "peer0.org1.example.com",
                "peer1.org1.example.com"
            ],
            "certificateAuthorities": [
                "ca.org1.example.com"
            ]
        },
        "Org2": {
            "mspid": "Org2MSP",
            "peers": [
                "peer0.org2.example.com",
                "peer1.org2.example.com"
            ],
            "certificateAuthorities": [
                "ca.org2.example.com"
            ]
        }
    },
    "orderers": {
        "orderer.example.com": {
            "url": "grpc://192.168.56.170:7050"
        }
    },
    "peers": {
        "peer0.org1.example.com": {
            "url": "grpc://192.168.56.171:7051"
        },
        "peer1.org1.example.com": {
            "url": "grpc://192.168.56.171:8051"
        },
        "peer0.org2.example.com": {
            "url": "grpc://192.168.56.172:7051"
        },
        "peer1.org2.example.com": {
            "url": "grpc://192.168.56.172:8051"
        }
    },
    "certificateAuthorities": {
        "ca.org1.example.com": {
            "url": "http://192.168.56.171:7054",
            "caName": "ca.org1.example.com"
        },
        "ca.org2.example.com": {
            "url": "http://192.168.56.172:7054",
            "caName": "ca.org2.example.com"
        }
    }
}

docker-compose文件结构的片段如下,

networks:
  hyperledger:
        external: 
            name: hyperledger
  peer0.org1.example.com:
    container_name: peer0.org1.example.com
    -----------------------
    -----------------------
    -----------------------
    ports:
      - 7051:7051
    networks:
      hyperledger:
        aliases:
         - peer0.org1.example.com 

预期结果-通过NodeJS连接到Hyperledger docker swarm容器

2 个答案:

答案 0 :(得分:1)

我建议使用域。 修改/ etc / hosts

192.168.100.100 peer0.org1.example.com
192.168.100.100 peer1.org1.example.com
192.168.100.100 orderer.example.com
192.168.100.100 orderer.example.com
192.168.100.100 orderer3.example.com
192.168.100.100 orderer4.example.com
192.168.100.100 orderer5.example.com

修改connection-org1.json

"peers": {
    "peer0.org1.example.com": {
        "url": "grpcs://peer0.org1.example.com:7051",


"peers": {
    "peer0.org1.example.com": {
        "url": "grpcs://peer0.org1.example.com:7051",

修改代码

await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: false } });

答案 1 :(得分:0)

我找到了解决该问题的方法。 确保telnet从网络外部可以工作到所需的容器。通过运行

telnet 192.168.128.171 7051

如果Telnet不起作用->问题一定是因为该端口未正确发布/公开。 首先检查以下内容,

确保将CORE_PEER_LISTENADDRESS设置为侦听docker-compose文件中的所需端口。如下, 对于peer0.org1.eaxmple.com-> 7051,

CORE_PEER_LISTENADDRESS=0.0.0.0:7051

如果Telnet有效->检查连接配置文件。 如果启用了TLS,请确保正确传递了tls证书/ PEM文件,并将连接设置为 GRPCS (不是GRPC)

连接配置文件

            "certificateAuthorities": [

                "ca.org1.example.com"

            ],

            "adminPrivateKey": {

                "path": "crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_sk"

            },

            "signedCert": {

                "path": "crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem"

            }
        "peer0.org1.example.com": {

            "url": "grpcs://192.168.128.171:7051",

            "grpcOptions": {

                "ssl-target-name-override": "peer0.org1.example.com",

                "request-timeout": 120001

            },

            "tlsCACerts": {

                "path": "crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem"

            }

        },

请看以下链接以获取更多参考 https://fabric-sdk-node.github.io/tutorial-network-config.html