1、首先搭建私链单节点
2、多节点
复制1份之前节点的创世块文件genesis.json,内容必须和第1个节点的相同
初始化创世块,datadir 数据目录不要和第1个节点重复
geth --datadir data1 init genesis.json
启动节点,这里注意networkid要和之前节点相同,但是port不能重复,如果开启远程rpcport端口的话也不能重复
geth --identity node2 --datadir data1 --networkid 1 --rpcport 8546 --port 30304 console
查看节点ID
> admin.nodeInfo.enode
"enode://b82a94949537230fdb89b718d38bd2e2522228a219cb96ce768a6c0ba120d3546423350777d25d1607ed286cffe927f72632ae387451291ac96c0a2a072f9c5a@[::]:30304"
用主节点来添加这个节点 注: 将[::]改成IP
> admin.addPeer("enode://b82a94949537230fdb89b718d38bd2e2522228a219cb96ce768a6c0ba120d3546423350777d25d1607ed286cffe927f72632ae387451291ac96c0a2a072f9c5a@127.0.0.1:30304")
查看节点列表
> admin.peers
[{
caps: ["eth/62", "eth/63"],
id: "b82a94949537230fdb89b718d38bd2e2522228a219cb96ce768a6c0ba120d3546423350777d25d1607ed286cffe927f72632ae387451291ac96c0a2a072f9c5a",
name: "Geth/node2/v1.8.12-stable/darwin-amd64/go1.10.3",
network: {
inbound: false,
localAddress: "127.0.0.1:52609",
remoteAddress: "127.0.0.1:30304",
static: true,
trusted: false
},
protocols: {
eth: {
difficulty: 30817382,
head: "0x21e8fa1f583ccd027ce28669d3cd21689444dd46d21c647d652a19bf1abff997",
version: 63
}
}
}]
2个节点连接上之后,会进行区块同步
> INFO [08-31|13:57:40.561] Block synchronisation started
INFO [08-31|13:57:40.637] Imported new chain segment blocks=74 txs=0 mgas=0.000 elapsed=66.851ms mgasps=0.000 number=223 hash=21e8fa…bff997 cache=23.40kB ignored=2
到这个已经2个节点已经搭建成功了.