Centos7搭建Geth节点

环境准备

服务器

一般要求服务器:4核-8G-500G

[root@localhost opt]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)

Go Ethereum下载安装

下载地址:https://geth.ethereum.org/downloads/

选择需要下载的客户端:geth-linux-amd64-1.8.27-4bcc0a37.tar.gz

#下载
[root@localhost opt]# ll | grep geth-linux-amd64-1.8.27-4bcc0a37.tar.gz
-rw-r--r--. 1 root root 14594041 Apr 17 21:18 geth-linux-amd64-1.8.27-4bcc0a37.tar.gz
# 解压安装
[root@localhost opt]# tar zxvf geth-linux-amd64-1.8.27-4bcc0a37.tar.gz
[root@localhost opt]# cd geth-linux-amd64-1.8.27-4bcc0a37
[root@localhost opt]# cp geth /usr/bin/geth

时间同步(时间错误导致无法同步节点)

同步网络时间

[root@localhost opt]# ntpdate cn.pool.ntp.org
16 Jul 09:59:56 ntpdate[28004]: step time server 119.28.183.184 offset 0.975532 sec

定时同步网络时间

[root@localhost opt]# echo '0 0 * * * root ntpdate cn.pool.ntp.org prefer' >> /etc/crontab
[root@localhost opt]# service crond restart
Redirecting to /bin/systemctl restart crond.service

配置Geth

配置启动

# 创建目录
[root@localhost opt]# mkdir ethdir
# 生成配置文件
[root@localhost opt]# geth --syncmode 'fast' --rpc --rpcaddr '0.0.0.0' --rpcport 8545 --datadir /opt/ethdir/data --port '30303' --rpcapi 'db,eth,net,web3,personal' --rpccorsdomain '*' --networkid 4 --cache 1024 dumpconfig > /opt/ethdir/config.toml
# 后台启动geth节点
[root@localhost opt]# nohup geth --config /opt/ethdir/config.toml >> /opt/ethdir/geth.log  2>&1  &

选项说明

选项使用值说明
–syncmode“fast”Blockchain sync mode (“fast”, “full”, or “light”),同步模式,一般使用fast即可
–rpcEnable the HTTP-RPC server
–rpcaddr‘0.0.0.0’HTTP-RPC server listening interface (default: “localhost”)
–rpcport8545HTTP-RPC server listening port (default: 8545)
–datadir/opt/ethdir/dataData directory for the databases and keystore
–port‘30303’Network listening port (default: 30303)
–rpcapi‘db,eth,net,web3,personal’API’s offered over the HTTP-RPC interface
–rpccorsdomain‘*’Comma separated list of domains from which to accept cross origin requests (browser enforced)
–networkid4Network identifier (integer, 1=Frontier(主网), 2=Morden (disused), 3=Ropsten, 4=Rinkeby) (default: 1)
–cache1024Megabytes of memory allocated to internal caching (default: 1024)

参数参见

https://www.cnblogs.com/tinyxiong/p/7918706.html
https://geth.ethereum.org/interface/Command-Line-Options

基本指令

登录控制台

[root@localhost rinkeby]# geth attach geth.ipc
Welcome to the Geth JavaScript console!
 
instance: Geth/v1.8.27-stable-4bcc0a37/linux-amd64/go1.11.9
coinbase: 0x08d589b4d5921b128cda9aad4ce82570186b5491
at block: 4741795 (Tue, 16 Jul 2019 13:59:26 CST)
 datadir: /root/.ethereum/rinkeby
 modules: admin:1.0 clique: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
 
>

创建账户

> personal.newAccount('password')
"0xf15f87cf98c847af5b1de0bb106854b6e40f6276"
>

查看账户余额

> eth.getBalance('0xf15f87cf98c847af5b1de0bb106854b6e40f6276')
0
>

其他指令

参见:https://geth.ethereum.org/interface/Management-APIs

查看日志

查看同步日志

[root@localhost opt]# more geth.log
INFO [07-03|21:17:49.633] Maximum peer count                       ETH=25 LES=0 total=25
INFO [07-03|21:17:50.170] Starting peer-to-peer node               instance=Geth/v1.8.27-stable-4bcc0a3
7/linux-amd64/go1.11.9
INFO [07-03|21:17:50.170] Allocated cache and file handles         database=/root/.ethereum/rinkeby/get
h/chaindata cache=512 handles=32768
INFO [07-03|21:17:56.473] Initialised chain configuration          config="{ChainID: 4 Homestead: 1 DAO
: <nil> DAOSupport: true EIP150: 2 EIP155: 3 EIP158: 3 Byzantium: 1035301 Constantinople: 3660663  Cons
tantinopleFix: 4321234 Engine: clique}"
INFO [07-03|21:17:56.474] Initialising Ethereum protocol           versions="[63 62]" network=4
INFO [07-03|21:17:56.529] Loaded most recent local header          number=4668667 hash=d18fbe…ab7758 td
=8547789 age=1m2s
INFO [07-03|21:17:56.529] Loaded most recent local full block      number=4668667 hash=d18fbe…ab7758 td
=8547789 age=1m2s
INFO [07-03|21:17:56.529] Loaded most recent local fast block      number=4668667 hash=d18fbe…ab7758 td
=8547789 age=1m2s
INFO [07-03|21:17:56.529] Loaded local transaction journal         transactions=0 dropped=0
INFO [07-03|21:17:56.530] Regenerated local transaction journal    transactions=0 accounts=0
WARN [07-03|21:17:56.530] Blockchain not empty, fast sync disabled 
INFO [07-03|21:17:57.490] New local node record                    seq=74 id=35056e59ec20edb9 ip=127.0.
0.1 udp=30303 tcp=30303
INFO [07-03|21:17:57.491] Started P2P networking                   self=enode://d0e043a85000657cd8febdc
97678b946d5e20bd24bc0e7234962a17390a6abe2dd33eea67ff3df24634bef96807466c138256e7d65190ad9f360b7834f5163
5a@127.0.0.1:30303
INFO [07-03|21:17:57.494] IPC endpoint opened                      url=/root/.ethereum/rinkeby/geth.ipc
INFO [07-03|21:17:57.495] HTTP endpoint opened                     url=http://0.0.0.0:8545             
 cors=* vhosts=*
INFO [07-03|21:18:01.493] New local node record                    seq=75 id=35056e59ec20edb9 ip=<nil> 
    udp=30303 tcp=30303
INFO [07-03|21:21:57.492] Block synchronisation started 
WARN [07-03|21:22:04.382] Synchronisation failed, dropping peer    peer=d803dcc3febec864 err="no peers 
available or all tried for download"
INFO [07-03|21:27:47.508] Imported new chain segment               blocks=2 txs=17 mgas=2.315 elapsed=5
41.329ms mgasps=4.276 number=4668669 hash=17d9b1…1baa1c age=10m23s cache=229.03kB
INFO [07-03|21:27:49.054] Imported new chain segment               blocks=9 txs=184 mgas=21.486 elapsed
=1.544s    mgasps=13.910 number=4668678 hash=c9d65b…f0e2d2 age=8m10s  cache=1.55mB
INFO [07-03|21:27:59.959] Imported new chain segment               blocks=28 txs=496 mgas=52.850 elapse
d=10.901s   mgasps=4.848  number=4668706 hash=677f7f…86d5aa age=1m20s  cache=6.19mB
INFO [07-03|21:28:00.411] Imported new chain segment               blocks=4  txs=74  mgas=8.266  elapse
d=451.917ms mgasps=18.290 number=4668710 hash=d10922…2ff143 cache=6.69mB

当出现Block synchronisation started字样时,开始同步节点,一般第一次要同步1-2天(fast模式)。

同步结束

> eth.blockNumber
4741984
> 

当此命令返回的结果与链上的最新块一致时,同步完成。

rinkeby测试网浏览器
主网浏览器

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值