Original address: http://www.cocoachina.com/cms/wap.php?action=article&id=22439
In order to run multiple instances of Ethereum nodes on the local network, the following must be ensured:
Each instance has a separate data directory (--datadir)
Each instance runs on a separate port. (both eth and rpc) (--port and --rpcprot)
In the case of a cluster, instances must all know about each other.
The only endpoint for ipc communication, or disable ipc.
Start the first node (specify the port, and disable ipc), run the command and the result is as follows:
root@i-ct5y7t0o:/home/ubuntu/private-geth# geth --datadir ./data0 --networkid 31459 --ipcdisable --port 619 --rpcport 8200 console INFO [06-28|14:52:52] Starting peer-to-peer node instance=Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1 INFO [06-28|14:52:52] Allocated cache and file handles database=/home/ubuntu/private-geth/data0/geth/chaindata cache=128 handles=1024 INFO [06-28|14:52:52] Initialised chain configuration config="{ChainID: 666 Homestead: 0 DAO: DAOSupport: false EIP150: EIP155: 0 EIP158: 0 Metropolis: Engine: unknown}" INFO [06-28|14:52:52] Disk storage enabled for ethash caches dir=/home/ubuntu/private-geth/data0/geth/ethash count=3 INFO [06-28|14:52:52] Disk storage enabled for ethash DAGs dir=/root/.ethash count=2 INFO [06-28|14:52:52] Initialising Ethereum protocol versions="[63 62]" network=31459 INFO [06-28|14:52:52] Loaded most recent local header number=546 hash=a511c3鈥40ac8 td=79201418 INFO [06-28|14:52:52] Loaded most recent local full block number=546 hash=a511c3鈥40ac8 td=79201418 INFO [06-28|14:52:52] Loaded most recent local fast block number=546 hash=a511c3鈥40ac8 td=79201418 WARN [06-28|14:52:52] Blockchain not empty, fast sync disabled INFO [06-28|14:52:52] Starting P2P networking INFO [06-28|14:52:54] UDP listener up self=enode://fc96d5fb078c82f33092c4944b31b3a8b9201ddec88b880ae245a131e1107b33f3d7833f5f6992d7c9ffdb557fbdd9ad2ab5b2ead2492f0bdb5690a0392c50f7@[::]:619 INFO [06-28|14:52:54] RLPx listener up self=enode://fc96d5fb078c82f33092c4944b31b3a8b9201ddec88b880ae245a131e1107b33f3d7833f5f6992d7c9ffdb557fbdd9ad2ab5b2ead2492f0bdb5690a0392c50f7@[::]:619 Welcome to the Geth JavaScript console! 6 instance: Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1 coinbase: 0x66c62f1afa08eae5343bd2b3129e0ae9aa141fc3 at block: 546 (Wed, 28 Jun 2017 14:08:50 CST) datadir: /home/ubuntu/private-geth/data0 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
The above command starts the node in the command line (console) way, so we can get the enode url of the node instance by continuing to enter the following command:
> admin.nodeInfo.enode "enode://fc96d5fb078c82f33092c4944b31b3a8b9201ddec88b880ae245a131e1107b33f3d7833f5f6992d7c9ffdb557fbdd9ad2ab5b2ead2492f0bdb5690a0392c50f7@[::]:619"
Get the local IP address
ubuntu@i-ct5y7t0o:~$ ip addr 1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 52:54:0f:63:73:66 brd ff:ff:ff:ff:ff:ff inet 192.168.0.3/24 brd 192.168.0.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::5054:fff:fe63:7366/64 scope link valid_lft forever preferred_lft forever
Open another terminal and initialize the second node:
root@i-ct5y7t0o:/home/ubuntu/private-geth# geth --datadir ./data1 init ./genesis.json WARN [06-28|14:55:45] No etherbase set and no accounts found as default INFO [06-28|14:55:45] Allocated cache and file handles database=/home/ubuntu/private-geth/data1/geth/chaindata cache=16 handles=16 INFO [06-28|14:55:45] Writing custom genesis block INFO [06-28|14:55:45] Successfully wrote genesis state database=chaindata hash=e492a5鈥0420d INFO [06-28|14:55:45] Allocated cache and file handles database=/home/ubuntu/private-geth/data1/geth/lightchaindata cache=16 handles=16 INFO [06-28|14:55:45] Writing custom genesis block INFO [06-28|14:55:45] Successfully wrote genesis state database=lightchaindata hash=e492a5鈥0420d
Start the node, plus console to indicate that after startup, enable the command line:
root@i-ct5y7t0o:/home/ubuntu/private-geth# geth --datadir ./data1 --networkid 31459 --ipcdisable --port 6191 --rpcport 8101 --bootnodes "enode://fc96d5fb078c82f33092c4944b31b3a8b9201ddec88b880ae245a131e1107b33f3d7833f5f6992d7c9ffdb557fbdd9ad2ab5b2ead2492f0bdb5690a0392c50f7@192.168.0.3:619" console WARN [06-28|15:01:27] No etherbase set and no accounts found as default INFO [06-28|15:01:27] Starting peer-to-peer node instance=Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1 INFO [06-28|15:01:27] Allocated cache and file handles database=/home/ubuntu/private-geth/data1/geth/chaindata cache=128 handles=1024 WARN [06-28|15:01:27] Upgrading chain database to use sequential keys INFO [06-28|15:01:27] Initialised chain configuration config="{ChainID: 666 Homestead: 0 DAO: DAOSupport: false EIP150: EIP155: 0 EIP158: 0 Metropolis: Engine: unknown}" INFO [06-28|15:01:27] Disk storage enabled for ethash caches dir=/home/ubuntu/private-geth/data1/geth/ethash count=3 INFO [06-28|15:01:27] Disk storage enabled for ethash DAGs dir=/root/.ethash count=2 WARN [06-28|15:01:27] Upgrading db log bloom bins INFO [06-28|15:01:27] Bloom-bin upgrade completed elapsed=198.75碌s INFO [06-28|15:01:27] Initialising Ethereum protocol versions="[63 62]" network=31459 INFO [06-28|15:01:27] Database conversion successful INFO [06-28|15:01:27] Loaded most recent local header number=0 hash=e492a5鈥0420d td=1024 INFO [06-28|15:01:27] Loaded most recent local full block number=0 hash=e492a5鈥0420d td=1024 INFO [06-28|15:01:27] Loaded most recent local fast block number=0 hash=e492a5鈥0420d td=1024 INFO [06-28|15:01:27] Starting P2P networking INFO [06-28|15:01:29] UDP listener up self=enode://769c6de9b913f40edac8a037bbc697242097c4fa8f1574240bd2aeb930c049fd0d85310b9ba04bf6027c9d1a36a13789210140c9f2e38525deff87e28c8f5a09@[::]:6191 INFO [06-28|15:01:29] RLPx listener up self=enode://769c6de9b913f40edac8a037bbc697242097c4fa8f1574240bd2aeb930c049fd0d85310b9ba04bf6027c9d1a36a13789210140c9f2e38525deff87e28c8f5a09@[::]:6191 Welcome to the Geth JavaScript console! 6 instance: Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
Then he will automatically synchronize the data of the blockchain
In the above command, –bootndoes is to set the current node to start, directly link the first node by setting the value of –bootndoes, and the value of –bootnoedes can be entered in the command line of the first section: admin.nodeInfo. The enode command prints it out.
You can also start directly without setting –bootnodes, enter the command line after startup, and add it as a peer through the command admin.addPeer(enodeUrlOfFirst Instance).
To confirm that the link was successful, the second node entered:
> admin.nodeInfo { enode: "enode://769c6de9b913f40edac8a037bbc697242097c4fa8f1574240bd2aeb930c049fd0d85310b9ba04bf6027c9d1a36a13789210140c9f2e38525deff87e28c8f5a09@[::]:6191", id: "769c6de9b913f40edac8a037bbc697242097c4fa8f1574240bd2aeb930c049fd0d85310b9ba04bf6027c9d1a36a13789210140c9f2e38525deff87e28c8f5a09", ip: "::", listenAddr: "[::]:6191", name: "Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1", ports: { discovery: 6191, listener: 6191 }, protocols: { eth: { difficulty: 79750339, genesis: "0xe492a51ac029fd78d9c27dd1ff018b233231d15aa795d90aab1bd7d1ebc0420d", head: "0xdeeb2bc33146dccc9b5a3f02c56735d4fa4cb562fb92b3966053ede8880db8bf", network: 31459 } } }
First node input:
> admin.nodeInfo.enode "enode://fc96d5fb078c82f33092c4944b31b3a8b9201ddec88b880ae245a131e1107b33f3d7833f5f6992d7c9ffdb557fbdd9ad2ab5b2ead2492f0bdb5690a0392c50f7@[::]:619" > admin.nodeInfo { enode: "enode://fc96d5fb078c82f33092c4944b31b3a8b9201ddec88b880ae245a131e1107b33f3d7833f5f6992d7c9ffdb557fbdd9ad2ab5b2ead2492f0bdb5690a0392c50f7@[::]:619", id: "fc96d5fb078c82f33092c4944b31b3a8b9201ddec88b880ae245a131e1107b33f3d7833f5f6992d7c9ffdb557fbdd9ad2ab5b2ead2492f0bdb5690a0392c50f7", ip: "::", listenAddr: "[::]:619", name: "Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1", ports: { discovery: 619, listener: 619 }, protocols: { eth: { difficulty: 79750339, genesis: "0xe492a51ac029fd78d9c27dd1ff018b233231d15aa795d90aab1bd7d1ebc0420d", head: "0xdeeb2bc33146dccc9b5a3f02c56735d4fa4cb562fb92b3966053ede8880db8bf", network: 31459 } } } > net.peerCount 1 > admin.peers [{ caps: ["eth/63"], id: "769c6de9b913f40edac8a037bbc697242097c4fa8f1574240bd2aeb930c049fd0d85310b9ba04bf6027c9d1a36a13789210140c9f2e38525deff87e28c8f5a09", name: "Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1", network: { localAddress: "192.168.0.3:619", remoteAddress: "192.168.0.3:38620" }, protocols: { eth: { difficulty: 1024, head: "0xe492a51ac029fd78d9c27dd1ff018b233231d15aa795d90aab1bd7d1ebc0420d", version: 63 } } }]
It can be seen from the obtained results that the first node has 1 peer link, and the node id of the link is:
“769c6de9b913f40edac8a037bbc697242097c4fa8f1574240bd2aeb930c049fd0d85310b9ba04bf6027c9d1a36a13789210140c9f2e38525deff87e28c8f5a09”
This id is exactly the id of the second node.
Continuing to expand in this way, it is very easy to establish a local node cluster. All these tasks can be done by writing script code, which can also include creating accounts, mining, etc..
Please refer to: gethcluster.sh script under https://github.com/ethersphere/eth-utils , and usage methods and examples in README.
After the link is successful, use the account we mined in the previous article to send "ether" (the currency unit of ether, and one called "Wei") to the second node.
First check the Wei number of the second node and the block number of the entire network, as well as the account id of the receiving currency:
personal.newAccount() Passphrase: Repeat passphrase: "0xd600f5622024bb8f53ca3f0506cf1a13c811e17b" > INFO [06-28|15:07:38] New wallet appeared url=keystore:///home/ubuntu/private鈥[32mstatus=Locked 5 > > eth.getBalance(eth.accounts[0])
On the first node command line, do the following:
personal.unlockAccount(eth.accounts[0]) Unlock account 0x66c62f1afa08eae5343bd2b3129e0ae9aa141fc3 Passphrase: true > ^C > eth.sendTransaction({from: "0x66c62f1afa08eae5343bd2b3129e0ae9aa141fc3", to: "0xd600f5622024bb8f53ca3f0506cf1a13c811e17b", value: web3.toWei(1, "ether")}) > miner.start()
Then at the command line of the second node enter:
eth.getBalance(eth.accounts[0]) to check the successful transfer
Open another terminal and initialize the third node:
root@i-ct5y7t0o:/home/ubuntu/private-geth# geth --datadir ./data2 init ./genesis.json WARN [06-28|14:55:45] No etherbase set and no accounts found as default INFO [06-28|14:55:45] Allocated cache and file handles database=/home/ubuntu/private-geth/data1/geth/chaindata cache=16 handles=16 INFO [06-28|14:55:45] Writing custom genesis block INFO [06-28|14:55:45] Successfully wrote genesis state database=chaindata hash=e492a5鈥0420d INFO [06-28|14:55:45] Allocated cache and file handles database=/home/ubuntu/private-geth/data1/geth/lightchaindata cache=16 handles=16 INFO [06-28|14:55:45] Writing custom genesis block INFO [06-28|14:55:45] Successfully wrote genesis state database=lightchaindata hash=e492a5鈥0420d
Start the node, plus console to indicate that after startup, enable the command line:
root@i-ct5y7t0o:/home/ubuntu/private-geth# geth --datadir ./data2 --networkid 31459 --ipcdisable --port 6192 --rpcport 8100 --bootnodes "enode://fc96d5fb078c82f33092c4944b31b3a8b9201ddec88b880ae245a131e1107b33f3d7833f5f6992d7c9ffdb557fbdd9ad2ab5b2ead2492f0bdb5690a0392c50f7@192.168.0.3:619" console WARN [06-28|15:01:27] No etherbase set and no accounts found as default INFO [06-28|15:01:27] Starting peer-to-peer node instance=Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1 INFO [06-28|15:01:27] Allocated cache and file handles database=/home/ubuntu/private-geth/data1/geth/chaindata cache=128 handles=1024 WARN [06-28|15:01:27] Upgrading chain database to use sequential keys INFO [06-28|15:01:27] Initialised chain configuration config="{ChainID: 666 Homestead: 0 DAO: DAOSupport: false EIP150: EIP155: 0 EIP158: 0 Metropolis: Engine: unknown}" INFO [06-28|15:01:27] Disk storage enabled for ethash caches dir=/home/ubuntu/private-geth/data1/geth/ethash count=3 INFO [06-28|15:01:27] Disk storage enabled for ethash DAGs dir=/root/.ethash count=2 WARN [06-28|15:01:27] Upgrading db log bloom bins INFO [06-28|15:01:27] Bloom-bin upgrade completed elapsed=198.75碌s INFO [06-28|15:01:27] Initialising Ethereum protocol versions="[63 62]" network=31459 INFO [06-28|15:01:27] Database conversion successful INFO [06-28|15:01:27] Loaded most recent local header number=0 hash=e492a5鈥0420d td=1024 INFO [06-28|15:01:27] Loaded most recent local full block number=0 hash=e492a5鈥0420d td=1024 INFO [06-28|15:01:27] Loaded most recent local fast block number=0 hash=e492a5鈥0420d td=1024 INFO [06-28|15:01:27] Starting P2P networking INFO [06-28|15:01:29] UDP listener up self=enode://769c6de9b913f40edac8a037bbc697242097c4fa8f1574240bd2aeb930c049fd0d85310b9ba04bf6027c9d1a36a13789210140c9f2e38525deff87e28c8f5a09@[::]:6191 INFO [06-28|15:01:29] RLPx listener up self=enode://769c6de9b913f40edac8a037bbc697242097c4fa8f1574240bd2aeb930c049fd0d85310b9ba04bf6027c9d1a36a13789210140c9f2e38525deff87e28c8f5a09@[::]:6191 Welcome to the Geth JavaScript console! instance: Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
Then he will automatically synchronize the data of the blockchain
This chain has three nodes