我正在测试运行织物应用程序教程。我在一个主机上部署了网络(比方说: HOST1)。然后,在另一个具有不同ip地址(HOST2)的主机上,我想运行应用程序(如教程中所示)。为此,我在运行./network.sh deployCC脚本时复制了已生成的连接配置文件,并将对等服务器的url从本地主机更改为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
}
}
}此外,我在gateway.connect()方法中更改了app.js文件中的发现选项,以避免在本地网络中查看fabric网络:
try {
const ccp = buildCCPOrg1();
const caClient = buildCAClient(FabricCAServices, ccp, 'ca.org1.example.com');
const wallet = await buildWallet(Wallets, walletPath);
await enrollAdmin(caClient, wallet, mspOrg1);
await registerAndEnrollUser(caClient, wallet, mspOrg1, org1UserId, 'org1.department1');
const gateway = new Gateway();
try {
await gateway.connect(ccp, {
wallet,
identity: org1UserId,
discovery: { enabled: true, asLocalhost: false }
});
//first exception here
const network = await gateway.getNetwork(channelName);
//second exception here, and app closes
const contract = network.getContract(chaincodeName);
console.log('\n--> Submit Transaction: InitLedger...');
await contract.submitTransaction('InitLedger');
console.log('*** Result: committed');
//rest of method from original app.js was cut
} finally {
gateway.disconnect();
}除了这些变化之外,一切都是默认的。应用程序可以连接到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可以看到,用户已成功注册,但无法建立到网络的连接。我想可能有什么隐藏着的东西,但我不知道该去哪里找。当然,与钱包和证书没有冲突。
如何将应用程序从另一个主机连接到这个网络?
//编辑
有时候你甚至不能相信自己。事实证明,tlcCACerts是不正确的。但是,在更正连接配置文件之后,出现了一些新的错误:
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似乎,就像HOST2上的应用程序没有看到HOST1上的对等程序和订购者.
发布于 2021-04-30 19:17:58
我终于找到了第二个问题的解决方案(连接到另一个主机上的网络)。您必须编辑/etc/host文件,并将orderer和对等主机名转换为部署网络的机器的IP地址。
在Linux上:
在Windows上:
https://stackoverflow.com/questions/67335105
复制相似问题