Private Network Tutorial

This page describes how to set up a local cluster of nodes, advise how to make it private, and how to hook up your nodes on the eth-netstat network monitoring app. A fully controlled ethereum network is useful as a backend for network integration testing (core developers working on issues related to networking/blockchain synching/message propagation, etc or DAPP developers testing multi-block and multi-user scenarios).

此页面描述了如何设置本地节点集群,建议如何使其私有化以及如何在eth-netstat网络监视应用程序上连接节点。完全受控的以太坊网络可用作网络集成测试的后端(从事与网络/区块链同步/消息传播等问题有关的核心开发人员,或测试多块和多用户方案的DAPP开发人员)。

We assume you are able to build geth following the build instructions

Setting up multiple nodes

In order to run multiple ethereum nodes locally, you have to make sure:

为了在本地运行多个以太坊节点,您必须确保:

  • each instance has a separate data directory (--datadir) 每个实例都有一个单独的数据目录(–datadir)
  • each instance runs on a different port (both eth and rpc) (--port and --rpcport) 每个实例都在不同的端口(eth和rpc)上运行(–port和–rpcport)
  • in case of a cluster the instances must know about each other 在集群的情况下,实例必须彼此了解
  • the ipc endpoint is unique or the ipc interface is disabled (--ipcpath or --ipcdisable) ipc端点是唯一的或ipc接口已禁用(–ipcpath或–ipcdisable)

You start the first node (let’s make port explicit and disable ipc interface)

您启动第一个节点(让我们显式设置端口并禁用ipc接口)

geth --datadir="/tmp/eth/60/01" -verbosity 6 --ipcdisable --port 30301 --rpcport 8101 console 2>> /tmp/eth/60/01.log

We started the node with the console, so that we can grab the enode url for instance:

我们使用控制台启动了该节点,因此我们可以获取例如enode URL:

> admin.nodeInfo.enode
enode://8c544b4a07da02a9ee024def6f3ba24b2747272b64e16ec5dd6b17b55992f8980b77938155169d9d33807e501729ecb42f5c0a61018898c32799ced152e9f0d7@9[::]:30301

[::] will be parsed as localhost (127.0.0.1). If your nodes are on a local network check each individual host machine and find your ip with ifconfig (on Linux and MacOS):

$ ifconfig|grep netmask|awk '{print $2}'
127.0.0.1
192.168.1.97

If your peers are not on the local network, you need to know your external IP address (use a service) to construct the enode url.

Now you can launch a second node with:

geth --datadir="/tmp/eth/60/02" --verbosity 6 --ipcdisable --port 30302 --rpcport 8102 console 2>> /tmp/eth/60/02.log 

If you want to connect this instance to the previously started node you can add it as a peer from the console with admin.addPeer(enodeUrlOfFirstInstance).

You can test the connection by typing in geth console:

> net.listening
true
> net.peerCount 
1
> admin.peers
...

Local cluster

As an extention of the above, you can spawn a local cluster of nodes easily. It can also be scripted including account creation which is needed for mining. See gethcluster.sh script, and the README there for usage and examples.

作为上述扩展,您可以轻松生成本地节点集群。还可以编写脚本,包括进行挖掘所需的帐户创建。有关用法和示例,请参见gethcluster.sh脚本和README。

Private network

See [[the Private Network Page Private network]] for more information.

Setup bootnode

The first time a node connects to the network it uses one of the predefined bootnodes. Through these bootnodes a node can join the network and find other nodes. In the case of a private cluster these predefined bootnodes are not of much use. Therefore go-ethereum offers a bootnode implementation that can be configured and run in your private network.

节点第一次连接到网络时,它将使用预定义的引导节点之一。通过这些引导节点,一个节点可以加入网络并找到其他节点。在专用群集的情况下,这些预定义的引导节点用处不大。因此,go-ethereum提供了可以在您的专用网络中配置和运行的bootnode实现。

It can be run through the command.

> bootnode
Fatal: Use -nodekey or -nodekeyhex to specify a private key

As can be seen the bootnode asks for a key. Each ethereum node, including a bootnode is identified by an enode identifier. These identifiers are derived from a key. Therefore you will need to give the bootnode such key. Since we currently don’t have one we can instruct the bootnode to generate a key (and store it in a file) before it starts.

> bootnode -genkey bootnode.key
I0216 09:53:08.076155 p2p/discover/udp.go:227] Listening, enode://890b6b5367ef6072455fedbd7a24ebac239d442b18c5ab9d26f58a349dad35ee5783a0dd543e4f454fed22db9772efe28a3ed6f21e75674ef6203e47803da682@

(exit with CTRL-C)

The stored key can be seen with:

> cat bootnode.key
dc90f8f7324f1cc7ba52c4077721c939f98a628ed17e51266d01c9cd0294033a

To instruct geth nodes to use our own bootnode(s) use the --bootnodes flag. This is a comma separated list of bootnode enode identifiers.

geth --bootnodes "enode://890b6b5367ef6072455fedbd7a24ebac239d442b18c5ab9d26f58a349dad35ee5783a0dd543e4f454fed22db9772efe28a3ed6f21e75674ef6203e47803da682@[::]:30301"

(what [::] means is explained previously)

Since it is convenient to start the bootnode each time with the same enode we can give the bootnode program the just generated key on the next time it is started.

bootnode -nodekey bootnode.key
I0216 10:01:19.125600 p2p/discover/udp.go:227] Listening, enode://890b6b5367ef6072455fedbd7a24ebac239d442b18c5ab9d26f58a349dad35ee5783a0dd543e4f454fed22db9772efe28a3ed6f21e75674ef6203e47803da682@[::]:30301

or

bootnode -nodekeyhex dc90f8f7324f1cc7ba52c4077721c939f98a628ed17e51266d01c9cd0294033a
I0216 10:01:40.094089 p2p/discover/udp.go:227] Listening, enode://890b6b5367ef6072455fedbd7a24ebac239d442b18c5ab9d26f58a349dad35ee5783a0dd543e4f454fed22db9772efe28a3ed6f21e75674ef6203e47803da682@[::]:30301

Monitoring your nodes

This page describes how to use the The Ethereum (centralised) network status monitor. to monitor your nodes.

This page or this README describes how you set up your own monitoring service for a (private or public) local cluster.