Hyperledger fabric 当部署在不同的主机上时,如何在结构节点SDK和结构网络之间建立连接?

Hyperledger fabric 当部署在不同的主机上时,如何在结构节点SDK和结构网络之间建立连接?,hyperledger-fabric,grpc,blockchain,hyperledger,hyperledger-fabric-sdk-js,Hyperledger Fabric,Grpc,Blockchain,Hyperledger,Hyperledger Fabric Sdk Js,我正在测试教程。我在一台主机上部署了网络(比如:HOST1)。 然后,在另一个具有不同ip地址的主机(HOST2)上运行应用程序(如教程中所示)。 为此,我在运行/network.sh deployCC脚本时复制了已生成的连接配置文件,并将对等方的url从localhost更改为HOST1的IP地址。因此,HOST2上的连接配置文件如下所示: { "name": "test-network-org1", "version": "

我正在测试教程。我在一台主机上部署了网络(比如:HOST1)。 然后,在另一个具有不同ip地址的主机(HOST2)上运行应用程序(如教程中所示)。 为此,我在运行/network.sh deployCC脚本时复制了已生成的连接配置文件,并将对等方的url从localhost更改为HOST1的IP地址。因此,HOST2上的连接配置文件如下所示:

{
"name": "test-network-org1",
"version": "1.0.0",
"client": {
    "organization": "Org1",
    "connection": {
        "timeout": {
            "peer": {
                "endorser": "300"
            }
        }
    }
},
"organizations": {
    "Org1": {
        "mspid": "Org1MSP",
        "peers": [
            "peer0.org1.example.com"
        ],
        "certificateAuthorities": [
            "ca.org1.example.com"
        ]
    }
},
"peers": {
    "peer0.org1.example.com": {
        "url": "grpcs://<HOST1IP>:7051",
        "tlsCACerts": {
            "pem": "-----BEGIN CERTIFICATE-----\nCERTBODY\n-----END CERTIFICATE-----\n"
        },
        "grpcOptions": {
            "ssl-target-name-override": "peer0.org1.example.com",
            "hostnameOverride": "peer0.org1.example.com"
        }
    }
},
"certificateAuthorities": {
    "ca.org1.example.com": {
        "url": "https://<HOST1IP>:7054",
        "caName": "ca-org1",
        "tlsCACerts": {
            "pem": ["-----BEGIN CERTIFICATE-----\nCERTBODY\n-----END CERTIFICATE-----\n"]
        },
        "httpOptions": {
            "verify": false
        }
    }
}
除了这些变化,一切都是默认的。 应用程序可以连接到CA并注册和注册管理员和appUser(如教程中所示),但在连接到网络时崩溃

日志和错误的副本:

Loaded the network configuration located at \fabric-samples\test-network\conn\connection-org1.json
Built a CA Client named ca-org1
Built a file system wallet at \fabric-samples\asset-transfer-basic\application-javascript\wallet
Successfully enrolled admin user and imported it into the wallet
Successfully registered and enrolled user appUser and imported it into the wallet
2021-04-30T11:49:34.232Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com, url:grpcs://<HOST1IP>:7051, connected:false, connectAttempted:true
2021-04-30T11:49:34.232Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org1.example.com url:grpcs://<HOST1IP>:7051 timeout:3000
2021-04-30T11:49:34.264Z - info: [NetworkConfig]: buildPeer - Unable to connect to the endorser peer0.org1.example.com due to Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com, url:grpcs://<HOST1IP>:7051, connected:false, connectAttempted:true
    at checkState (\fabric-samples\asset-transfer-basic\application-javascript\node_modules\@grpc\grpc-js\build\src\client.js:69:26)
    at Timeout._onTimeout (\fabric-samples\asset-transfer-basic\application-javascript\node_modules\@grpc\grpc-js\build\src\channel.js:292:17)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7) {
connectFailed: true
}
2021-04-30T11:49:37.389Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Discoverer- name: peer0.org1.example.com, url:grpcs://<HOST1IP>:7051, connected:false, connectAttempted:true
2021-04-30T11:49:37.391Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org1.example.com url:grpcs://<HOST1IP>:7051 timeout:3000
2021-04-30T11:49:37.393Z - error: [ServiceEndpoint]: ServiceEndpoint grpcs://mchm5pza:7051 reset connection failed :: Error: Failed to connect before the deadline on Discoverer- name: peer0.org1.example.com, url:grpcs://<HOST1IP>:7051, connected:false, connectAttempted:true
2021-04-30T11:49:37.396Z - error: [DiscoveryService]: send[mychannel] - no discovery results
******** FAILED to run the application: Error: DiscoveryService has failed to return results

似乎HOST2上的应用程序在HOST1上看不到对等方和订购方…

我终于找到了第二个问题的解决方案(与另一台主机上的网络连接)。 您必须编辑/etc/hosts文件,并将订购方和对等方主机名转换为部署网络的机器的IP地址


在Linux上:
  • 以管理员权限在文本编辑器中打开/etc/hosts文件
  • 添加必要的主机和IP翻译
  • 保存文件

  • 在Windows上:
  • 打开开始菜单
  • 键入记事本,然后按ctrl+shift+enter以在用户访问模式下打开记事本
  • 从记事本应用程序进入目录:c:\Windows\System32\drivers\etc
  • 筛选所有文件类型,然后打开主机文件
  • 添加必要的主机和IP翻译
  • 保存文件

  • 您可能希望查看此端到端教程,其中包括构建应用程序并将其连接到远程Hyperledger结构网络:

    以下是源代码:

    Loaded the network configuration located at \fabric-samples\test-network\conn\connection-org1.json
    Built a CA Client named ca-org1
    Built a file system wallet at \fabric-samples\asset-transfer-basic\application-javascript\wallet
    Successfully enrolled admin user and imported it into the wallet
    Successfully registered and enrolled user appUser and imported it into the wallet
    2021-04-30T11:49:34.232Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com, url:grpcs://<HOST1IP>:7051, connected:false, connectAttempted:true
    2021-04-30T11:49:34.232Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org1.example.com url:grpcs://<HOST1IP>:7051 timeout:3000
    2021-04-30T11:49:34.264Z - info: [NetworkConfig]: buildPeer - Unable to connect to the endorser peer0.org1.example.com due to Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com, url:grpcs://<HOST1IP>:7051, connected:false, connectAttempted:true
        at checkState (\fabric-samples\asset-transfer-basic\application-javascript\node_modules\@grpc\grpc-js\build\src\client.js:69:26)
        at Timeout._onTimeout (\fabric-samples\asset-transfer-basic\application-javascript\node_modules\@grpc\grpc-js\build\src\channel.js:292:17)
        at listOnTimeout (internal/timers.js:549:17)
        at processTimers (internal/timers.js:492:7) {
    connectFailed: true
    }
    2021-04-30T11:49:37.389Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Discoverer- name: peer0.org1.example.com, url:grpcs://<HOST1IP>:7051, connected:false, connectAttempted:true
    2021-04-30T11:49:37.391Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org1.example.com url:grpcs://<HOST1IP>:7051 timeout:3000
    2021-04-30T11:49:37.393Z - error: [ServiceEndpoint]: ServiceEndpoint grpcs://mchm5pza:7051 reset connection failed :: Error: Failed to connect before the deadline on Discoverer- name: peer0.org1.example.com, url:grpcs://<HOST1IP>:7051, connected:false, connectAttempted:true
    2021-04-30T11:49:37.396Z - error: [DiscoveryService]: send[mychannel] - no discovery results
    ******** FAILED to run the application: Error: DiscoveryService has failed to return results
    
    2021-04-30T15:10:02.760Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Committer- name: orderer.example.com:7050, url:grpcs://orderer.example.com:7050, connected:false, connectAttempted:true
    2021-04-30T15:10:02.760Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server orderer.example.com:7050 url:grpcs://orderer.example.com:7050 timeout:3000
    2021-04-30T15:10:02.760Z - error: [DiscoveryService]: _buildOrderer[mychannel] - Unable to connect to the discovered orderer orderer.example.com:7050 due to Error: Failed to connect before the deadline on Committer- name: orderer.example.com:7050, url:grpcs://orderer.example.com:7050, connected:false, connectAttempted:true
    2021-04-30T15:10:05.776Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com:7051, url:grpcs://peer0.org1.example.com:7051, connected:false, connectAttempted:true
    2021-04-30T15:10:05.778Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org1.example.com:7051 url:grpcs://peer0.org1.example.com:7051 timeout:3000
    2021-04-30T15:10:05.780Z - error: [DiscoveryService]: _buildPeer[mychannel] - Unable to connect to the discovered peer peer0.org1.example.com:7051 due to Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com:7051, url:grpcs://peer0.org1.example.com:7051, connected:false, connectAttempted:true
    2021-04-30T15:10:08.782Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org2.example.com:9051, url:grpcs://peer0.org2.example.com:9051, connected:false, connectAttempted:true
    2021-04-30T15:10:08.782Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org2.example.com:9051 url:grpcs://peer0.org2.example.com:9051 timeout:3000
    2021-04-30T15:10:08.782Z - error: [DiscoveryService]: _buildPeer[mychannel] - Unable to connect to the discovered peer peer0.org2.example.com:9051 due to Error: Failed to connect before the deadline on Endorser- name: peer0.org2.example.com:9051, url:grpcs://peer0.org2.example.com:9051, connected:false, connectAttempted:true