使用Geth搭建多节点私有链
步骤
1.编辑初始化配置文件genesis.json
{"config": {"chainId": 6668,"homesteadBlock": 0,"eip150Block": 0,"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000","eip155Block": 0,"eip158Block": 0,"byzantiumBlock": 0,"constantinopleBlock": 0,"petersburgBlock": 0,"istanbulBlock": 0,"ethash": {}},"nonce": "0x0","timestamp": "0x5ddf8f3e","extraData": "0x0000000000000000000000000000000000000000000000000000000000000000","gasLimit": "0x47b760","difficulty": "20000","mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000","coinbase": "0x0000000000000000000000000000000000000000","alloc": { },"number": "0x0","gasUsed": "0x0","parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"}
2.启动节点1
geth --datadir chainA init genesis.json
geth --datadir chainA --networkid 123 console --nodiscover
3.另开一个终端,启动节点2
geth --datadir chainB init genesis.json
geth --datadir chainB --networkid 123 --port 30302 --http --http.port 8552 --http.addr 127.0.0.2 --ipcdisable console --nodiscover --authrpc.addr 127.0.0.2
4.节点连接
4.1 获取节点1的encode并复制 admin.nodeInfo.enode
4.2 节点2连接节点1 admin.addPeer("")
4.3 在节点2获取节点1信息 admin.peers
常见错误
1.套接字地址只允许使用一次,节点1开启已占用。加上--authrpc.addr 127.0.0.2
Fatal: Error starting protocol stack: listen tcp 127.0.0.1:8551: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
2.因为版本问题,–rpc已不使用
Incorrect Usage. flag provided but not defined: -rpc
- –rpc => --http
- –rpcapi => --http.api
- –rpcaddr => --http.addr
- –rpcport => --http.port
- –rpccorsdomain => --http.corsdomain