Skip to content

核心思路 : 从原有的(或者从别人那里) 拷贝数据到自己的服务器

在 geth 的控制台调用 eth.syncing 发现 currentBlock 一直低于highestBlock

环境:

服务器 A: 已经同步好区块的服务器
服务器 B: 同步有问题的服务器
当前区块数据大小: 180G 左右
服务器 A: 已经同步好区块的服务器
服务器 B: 同步有问题的服务器
当前区块数据大小: 180G 左右

1.关闭 A服务器 上 的 geth

ps -axu | grep geth # 查看geth 的 pid 

kill  -INT ${pid} # 给 geth 发出 停止信号 #.... 等待关闭完成(大约 20 秒) 

tail -n 10 nohup.out # 查看是否输出 已经关闭了数据库

ps -axu | grep geth # 确保没有geth 正在运行
ps -axu | grep geth # 查看geth 的 pid 

kill  -INT ${pid} # 给 geth 发出 停止信号 #.... 等待关闭完成(大约 20 秒) 

tail -n 10 nohup.out # 查看是否输出 已经关闭了数据库

ps -axu | grep geth # 确保没有geth 正在运行

2.拷贝数据到新的服务器

scp A  root@B:/root/
scp A  root@B:/root/

3.在 B 服务器上 同步 A 服务器 的数据

  • 数据cp结束之后,把 A 服务的geth 重新启动起来

WARNING

启动数据文件夹指向复制过来的文件夹, 同步节点 指向 服务器 A. 不过记得修改 nodekey, 否则无法同步

./geth --data-dir =/tmp/eth/ # 生成 新的 nodekey 

#将原有的nodkey 改名 
mv ~/ethdata/data/geth/nodekey ~/ethdata/data/geth/nodekey2 

# 复制新生成的nodekey 到数据目录

 cp /tmp/eth/geth/nodekey  /data/coin/eth/geth/nodekey rm -rf /tmp/eth/ 
 
 #启动
 nohup /data/apps/eth/geth --rpc --port 8546 --rpcport 8545 --rpcapi admin,web3,db,eth,net,personal --rpcaddr=172.31.171.xxx --datadir /data/coin/eth --maxpeers 100 --cache 1024 &
./geth --data-dir =/tmp/eth/ # 生成 新的 nodekey 

#将原有的nodkey 改名 
mv ~/ethdata/data/geth/nodekey ~/ethdata/data/geth/nodekey2 

# 复制新生成的nodekey 到数据目录

 cp /tmp/eth/geth/nodekey  /data/coin/eth/geth/nodekey rm -rf /tmp/eth/ 
 
 #启动
 nohup /data/apps/eth/geth --rpc --port 8546 --rpcport 8545 --rpcapi admin,web3,db,eth,net,personal --rpcaddr=172.31.171.xxx --datadir /data/coin/eth --maxpeers 100 --cache 1024 &

4.geth 控制台, 将A 服务器的节点添加进去

/geth attach http://xxx.xxx.xxx.xxx # 连接到

# 添加服务器A geht 的节点
admin.addPeer("enode://xxxxx@0.0.0.0:30303?discport=0");
/geth attach http://xxx.xxx.xxx.xxx # 连接到

# 添加服务器A geht 的节点
admin.addPeer("enode://xxxxx@0.0.0.0:30303?discport=0");
  • 查看p2p 节点
head /path/nohup.out 
NFO [11-29|07:56:16.208] Started P2P networking  self="enode://xxxxx@0.0.0.0:30303?discport=0"
head /path/nohup.out 
NFO [11-29|07:56:16.208] Started P2P networking  self="enode://xxxxx@0.0.0.0:30303?discport=0"