连接专用网络中不同机器上的两个对等点

Connecting two peers on different machines in a private network

我正在使用 geth 在我的系统中创建一个连接到我办公室网络的私有区块链。

我想在连接到同一网络的区块链网络中添加另一个点(不同的 PC)。

我该怎么做?

关于创建确实可以解决上述要求的应用程序的任何建议。

当 运行 客户端守护程序时,您可以添加 'connect' 参数以指定 IP:Port 启动时要尝试连接的计算机。

bitcoind --daemon -connect=127.0.0.1:9090

当硬编码到您的区块链代码库中的节点的 IP 尚未更新为您拥有节点的 IP 运行 时,通常必须这样做。因此 peers.dat 不知道去哪里寻找与区块链的连接。

您还可以在配置文件中使用 addnode 参数指定这些。例如

server=1
rpcport=9090
rpcuser=bitcoinrpc
rpcpassword=3QtnxrB7P5y4EpBdad1MkCeB2RHmArvcarw7udgXsAce

addnode=10.0.0.2:8333

需要进行的关键更改是使用 rpc 模式在这些机器上启动 geth 节点

例如,使用以下命令在机器 1 和机器 2 上启动 geth 节点:

  1. 机器 1:geth --datadir "C:\ethereum\geth\data" --networkid 1234 --rpc --rpcport "8545" --rpcaddr "127.198.216.197" --rpccorsdomain "*"
  2. 机器 2:geth --datadir "C:\ethereum\geth\data" --networkid 1234 --rpc --rpcport "8545" --rpcaddr "127.198.216.198" --rpccorsdomain "*"

如果您想手动添加机器 2 作为机器 1 的对等节点,或者使用 Bootnode 并使用 Bootnode 启动 Geth。如果要使用Boot节点可以参考link:https://github.com/ethereum/go-ethereum/wiki/Setting-up-private-network-or-local-cluster

然后您应该可以使用以下命令附加控制台:geth attach http://127.198.216.197:8545

一个警告:如果它们被您的办公室网络阻止,您需要打开相应的端口