Blockchain 如何在geth中建立专用网络并连接对等点?

Blockchain 如何在geth中建立专用网络并连接对等点?,blockchain,ethereum,peer,local-network,private-network,Blockchain,Ethereum,Peer,Local Network,Private Network,我正在尝试设置一个专用网络并尝试连接对等点。目前我正在我的笔记本电脑和台式机上试用(它们都连接到不同的互联网) 我在第一个终端中运行以下命令(在两个系统中(data dir在两个系统中不同)): 然后我跑: geth --datadir "E:\User\priv\data" 现在,在第二个终端: geth attach ipc:\\.\pipe\geth.ipc 当我运行admin.nodeInfo.enode 然后在第一个人电脑上 admin.addPeer("enode://e0c49

我正在尝试设置一个专用网络并尝试连接对等点。目前我正在我的笔记本电脑和台式机上试用(它们都连接到不同的互联网)

我在第一个终端中运行以下命令(在两个系统中(
data dir
在两个系统中不同)):

然后我跑:

geth --datadir "E:\User\priv\data"
现在,在第二个终端:

geth attach ipc:\\.\pipe\geth.ipc
当我运行
admin.nodeInfo.enode

然后在第一个人电脑上

admin.addPeer("enode://e0c4960659b6ce4eda71c67b337055636f67660a711d157a81572b5eff1ed1b77931bef4bd079e2660baa661ac16d696b831e9394cb619378071a2593ecdf17a@[192.168.1.2]:30301");
在第二个人电脑上

admin.addPeer("enode://e0c4960659b6ce4eda71c67b337055636f67660a711d157a81572b5eff1ed1b77931bef4bd079e2660baa661ac16d696b831e9394cb619378071a2593ecdf17a@[13.75.117.156]:30302");
它们都返回
true

但是
admin.peerCount
返回
0

有人能帮我设置一个专用的geth网络吗

如上所述,您的
--port
--rpcport
变量应该不同。产生的
EnodeURLs
也应该不同


另外,当您第二次运行geth时,我会在
init

步骤1

geth --identity "YourNodeName" --rpc --rpcport "8092" --datadir "DirectoryPathToStoreData" --port "30330" --nodiscover --rpcapi "db,eth,net,web3" --networkid 2010 init PathOfGenesisFile
geth --identity "YourNodeName" --rpc --rpcport "8092" --datadir "DirectoryPathToStoreData" --port "30330" --nodiscover --rpcapi "db,eth,net,web3" --networkid 2010 console
上述命令用于初始化Genesis文件

注意:所有愿意连接到网络的对等方都应具有相同的Genesis文件

步骤2

geth --identity "YourNodeName" --rpc --rpcport "8092" --datadir "DirectoryPathToStoreData" --port "30330" --nodiscover --rpcapi "db,eth,net,web3" --networkid 2010 init PathOfGenesisFile
geth --identity "YourNodeName" --rpc --rpcport "8092" --datadir "DirectoryPathToStoreData" --port "30330" --nodiscover --rpcapi "db,eth,net,web3" --networkid 2010 console
上面的命令打开一个Geth JavaScript控制台。 在其他系统中也执行上述两个步骤

步骤3

geth --identity "YourNodeName" --rpc --rpcport "8092" --datadir "DirectoryPathToStoreData" --port "30330" --nodiscover --rpcapi "db,eth,net,web3" --networkid 2010 init PathOfGenesisFile
geth --identity "YourNodeName" --rpc --rpcport "8092" --datadir "DirectoryPathToStoreData" --port "30330" --nodiscover --rpcapi "db,eth,net,web3" --networkid 2010 console
在要将其他系统添加为对等节点的系统中,键入以下命令
admin.addPeer(“参数”)
其中,参数是通过在其他系统中键入
admin.nodeInfo()
获得的其他节点的enode值

Eg:admin.nodeInfo
{
  enode: "enode://965dc2b0f39e199d3a07871293015d8a4ad9349834fc27b7ee5e87bea89547e4fafda3ce7982ae07c14b8770c87a6c14e3fe2f91ef0d0ca717eb6ae56aa3e74b@[::]:30330?discport=0",
  //////////
}
其中
30330
是其他系统的网络id

Eg:admin.nodeInfo
{
  enode: "enode://965dc2b0f39e199d3a07871293015d8a4ad9349834fc27b7ee5e87bea89547e4fafda3ce7982ae07c14b8770c87a6c14e3fe2f91ef0d0ca717eb6ae56aa3e74b@[::]:30330?discport=0",
  //////////
}
复制到
30330
。您需要提供其他系统的ip地址以代替

[::]
如果该节点能够充当对等节点,但不意味着它已添加到我们的网络,则返回true,以了解
键入net.peerCount
。如果添加,则返回1

您可以按照步骤3添加更多对等点


您可以创建一个私有区块链,而无需创建Genesis文件。如果您选择这样做,请遵循。

否,它不起作用。当我运行net.peerCount时,它返回0。我已经设置了我的专用网络,但当我启动geth is时,它开始与我一无所知的其他IP交换发现流量。这个流量非常大,正在使我的网络饱和。您知道如何仅为属于我自己网络的节点设置发现吗?您可以在为您的网络启动genesis文件时添加--nodiscover protocal,但是如果我使用nodiscover,如何查找连接到我的专用网络的其他用户?您需要在运行时添加其他用户,或者将其eNode/PubKey包含在中geth folderwell中的static-nodes.json文件这是不可能的,我不知道下载客户端并连接到私有网络的每个用户的IP地址